index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. loading: false,
  27. current: 1,
  28. size: 10,
  29. total: 0,
  30. // loadmore loading nomore
  31. status: 'loadmore',
  32. loadingText: '正在加载中',
  33. loadmoreText: '上拉加载更多',
  34. nomoreText: '没有更多了'
  35. },
  36. keyword: '',
  37. list: []
  38. }
  39. },
  40. onLoad(options) {
  41. this.collectionType = options.type || '';
  42. },
  43. onShow() {
  44. this.keyword = '';
  45. this.doRefresh();
  46. },
  47. methods: {
  48. scrolltolower() {
  49. this.loadmore()
  50. },
  51. loadmore() {
  52. this.page.current++;
  53. this.getCollectionList();
  54. },
  55. doRefresh() {
  56. this.page.current = 1;
  57. this.page.status = 'loadmore'
  58. this.list = [];
  59. this.getCollectionList();
  60. },
  61. getCollectionList() {
  62. if (this.page.status == 'loading' || this.page.status == 'nomore') {
  63. // 防止重复下拉
  64. return;
  65. }
  66. this.page.status = 'loading';
  67. //
  68. this.$u.api.getCollectionList(this.page.current, this.page.size, {
  69. collectType: this.collectionType || ''
  70. }).then(res => {
  71. if (res.data.records && res.data.records.length > 0) {
  72. this.list.push(...res.data.records)
  73. }
  74. this.page.total = res.data.total || 0;
  75. if (this.page.size * this.page.current >= res.data.total) {
  76. this.page.status = 'nomore'
  77. } else {
  78. this.page.status = 'loadmore'
  79. }
  80. }).catch(e=> {
  81. this.page.status = 'loadmore'
  82. })
  83. },
  84. toDetail(id) {
  85. if (this.collectionType == 'dish') {
  86. uni.navigateTo({
  87. url: "/pages/yuecai/dish/detail/index?id=" + id,
  88. })
  89. } else if (this.collectionType == 'location') {
  90. uni.navigateTo({
  91. url: "/pages/yuecai/location/detail/index?id=" + id,
  92. })
  93. } else if (this.collectionType == 'restaurant') {
  94. uni.navigateTo({
  95. url: "/pages/yuecai/restaurant/detail/index?id=" + id,
  96. })
  97. }
  98. },
  99. deleteCollection(id, index) {
  100. if (this.loading) {
  101. return;
  102. }
  103. this.loading = true;
  104. this.$u.api.deleteCollection(id).then(res => {
  105. this.list.splice(index, 1);
  106. this.loading = false;
  107. }).catch(e => {
  108. this.loading = false;
  109. })
  110. }
  111. },
  112. }
  113. </script>
  114. <style scoped lang="scss">
  115. .view-page {
  116. overflow: hidden;
  117. }
  118. </style>