index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <view class="width-100 height-100 view-page">
  3. <u-swiper :list="bannerList" @click="click" keyName="cover"></u-swiper>
  4. <view class="p-10">
  5. <u-search :clearabled="true" placeholder="请输入搜索关键字" v-model="keyword" :shape="square" search="doRefresh"
  6. @custom="doRefresh"></u-search>
  7. </view>
  8. <u-list @scrolltolower="scrolltolower" height="calc(100% - 180px)" lowerThreshold="10">
  9. <u-list-item v-for="(item, index) in list" :key="index">
  10. <u-cell :title="item.name" @click="toDetail(item.id)">
  11. <u-avatar slot="icon" shape="square" size="35" :src="item.cover"
  12. customStyle="margin: -3px 5px -3px 0"></u-avatar>
  13. </u-cell>
  14. </u-list-item>
  15. <u-loadmore :status="page.status" :loading-text="page.loadingText" :loadmore-text="page.loadmoreText"
  16. :nomore-text="page.nomoreText" />
  17. </u-list>
  18. </view>
  19. </template>
  20. <script>
  21. import themeMixins from '@/pages/yuecai/mixins/themeMixins.js';
  22. export default {
  23. mixins: [themeMixins],
  24. data() {
  25. return {
  26. bannerList: [],
  27. page: {
  28. current: 1,
  29. size: 10,
  30. total: 0,
  31. // loadmore loading nomore
  32. status: 'loadmore',
  33. loadingText: '正在加载中',
  34. loadmoreText: '上拉加载更多',
  35. nomoreText: '没有更多了'
  36. },
  37. keyword: '',
  38. list: []
  39. }
  40. },
  41. onShow() {
  42. this.keyword = '';
  43. this.getBanners();
  44. this.doRefresh();
  45. },
  46. methods: {
  47. getBanners() {
  48. this.$u.api.getInformationList(0, 6, {}).then(res => {
  49. this.bannerList = res.data.records || []
  50. })
  51. },
  52. scrolltolower() {
  53. this.loadmore()
  54. },
  55. loadmore() {
  56. this.page.current++;
  57. this.getDishList();
  58. },
  59. doRefresh() {
  60. this.page.current = 1;
  61. this.page.status = 'loadmore'
  62. this.list = [];
  63. this.getDishList();
  64. },
  65. getDishList() {
  66. if (this.page.status == 'loading' || this.page.status == 'nomore') {
  67. // 防止重复下拉
  68. return;
  69. }
  70. this.page.status = 'loading';
  71. //
  72. this.$u.api.getDishList(this.page.current, this.page.size, {
  73. name: this.keyword || ''
  74. }).then(res => {
  75. if (res.data.records && res.data.records.length > 0) {
  76. this.list.push(...res.data.records)
  77. }
  78. this.page.total = res.data.total || 0;
  79. if (this.page.size * this.page.current >= res.data.total) {
  80. this.page.status = 'nomore'
  81. } else {
  82. this.page.status = 'loadmore'
  83. }
  84. })
  85. },
  86. toDetail(id) {
  87. uni.navigateTo({
  88. url: "/pages/yuecai/dish/detail/index?id=" + id,
  89. })
  90. }
  91. },
  92. }
  93. </script>
  94. <style scoped lang="scss">
  95. .view-page {
  96. overflow: hidden;
  97. }
  98. </style>