index.vue 2.7 KB

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