index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <view class="width-100 height-100 view-page">
  3. <u-swiper :list="bannerList" @click="clickInfo" 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. clickInfo(index) {
  48. if (index < 0) {
  49. return;
  50. }
  51. uni.navigateTo({
  52. url: "/pages/yuecai/information/detail/index?id=" + this.bannerList[index].id,
  53. })
  54. },
  55. getBanners() {
  56. this.$u.api.getInformationList(0, 6, {}).then(res => {
  57. this.bannerList = res.data.records || []
  58. })
  59. },
  60. scrolltolower() {
  61. this.loadmore()
  62. },
  63. loadmore() {
  64. this.page.current++;
  65. this.getDishList();
  66. },
  67. doRefresh() {
  68. this.page.current = 1;
  69. this.page.status = 'loadmore'
  70. this.list = [];
  71. this.getDishList();
  72. },
  73. getDishList() {
  74. if (this.page.status == 'loading' || this.page.status == 'nomore') {
  75. // 防止重复下拉
  76. return;
  77. }
  78. this.page.status = 'loading';
  79. //
  80. this.$u.api.getDishList(this.page.current, this.page.size, {
  81. name: this.keyword || ''
  82. }).then(res => {
  83. if (res.data.records && res.data.records.length > 0) {
  84. this.list.push(...res.data.records)
  85. }
  86. this.page.total = res.data.total || 0;
  87. if (this.page.size * this.page.current >= res.data.total) {
  88. this.page.status = 'nomore'
  89. } else {
  90. this.page.status = 'loadmore'
  91. }
  92. })
  93. },
  94. toDetail(id) {
  95. uni.navigateTo({
  96. url: "/pages/yuecai/dish/detail/index?id=" + id,
  97. })
  98. }
  99. },
  100. }
  101. </script>
  102. <style scoped lang="scss">
  103. .view-page {
  104. overflow: hidden;
  105. }
  106. </style>