index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <view class="width-100 height-100 view-page">
  3. <u-tabs ref="tabs" :list="tabList" :scrollable="false" :current="currentTab" @change="tabChange" lineColor="#65371b"
  4. :activeStyle="{color:'#65371b'}" inactiveStyle="{color:'#65371b'}"></u-tabs>
  5. <u-list @scrolltolower="scrolltolower" height="calc(100% - 91px)" lowerThreshold="10">
  6. <view class="info-list">
  7. <view class="info-item" v-for="(item, index) in list" :key="index" @click="toDetail(item.collectId)">
  8. <view class="info-pic">
  9. <u-image width="96px" height="96px" mode="aspectFill" :src="item.cover"></u-image>
  10. </view>
  11. <view class="info-title">
  12. {{item.name}}
  13. </view>
  14. </view>
  15. </view>
  16. <u-loadmore :status="page.status" :loading-text="page.loadingText" :loadmore-text="page.loadmoreText"
  17. :nomore-text="page.nomoreText" />
  18. </u-list>
  19. </view>
  20. </template>
  21. <script>
  22. import themeMixins from '@/pages/yuecai/mixins/themeMixins.js';
  23. export default {
  24. mixins: [themeMixins],
  25. data() {
  26. return {
  27. page: {
  28. loading: false,
  29. current: 1,
  30. size: 10,
  31. total: 0,
  32. // loadmore loading nomore
  33. status: 'loadmore',
  34. loadingText: '正在加载中',
  35. loadmoreText: '上拉加载更多',
  36. nomoreText: '没有更多了'
  37. },
  38. keyword: '',
  39. list: [],
  40. tabList: [{
  41. name: '名店'
  42. }, {
  43. name: '名菜',
  44. }, {
  45. name: '名点',
  46. }],
  47. currentTab: 0
  48. }
  49. },
  50. onLoad(options) {
  51. this.collectionType = options.type || 'restaurant'
  52. switch (options.type) {
  53. case 'restaurant':
  54. this.currentTab = 0;
  55. break;
  56. case 'dish':
  57. this.currentTab = 1;
  58. break;
  59. case 'snacks':
  60. this.currentTab = 2;
  61. break;
  62. default:
  63. this.currentTab = 0;
  64. break;
  65. }
  66. },
  67. onShow() {
  68. this.keyword = '';
  69. this.doRefresh();
  70. },
  71. methods: {
  72. tabChange(e) {
  73. this.currentTab = e.index;
  74. switch (e.index) {
  75. case 0:
  76. this.collectionType = 'restaurant';
  77. break;
  78. case 1:
  79. this.collectionType = 'dish';
  80. break;
  81. case 2:
  82. this.collectionType = 'snacks';
  83. break;
  84. default:
  85. this.collectionType = 'restaurant';
  86. break;
  87. }
  88. this.doRefresh();
  89. },
  90. scrolltolower() {
  91. this.loadmore()
  92. },
  93. loadmore() {
  94. this.page.current++;
  95. this.getList();
  96. },
  97. doRefresh() {
  98. this.page.current = 1;
  99. this.page.status = 'loadmore'
  100. this.list = [];
  101. this.getList();
  102. },
  103. getList() {
  104. if (this.page.status == 'loading' || this.page.status == 'nomore') {
  105. // 防止重复下拉
  106. return;
  107. }
  108. this.page.status = 'loading';
  109. //
  110. this.$u.api.getCollectionList(this.page.current, this.page.size, {
  111. collectType: this.collectionType || ''
  112. }).then(res => {
  113. if (res.data.records && res.data.records.length > 0) {
  114. this.list.push(...res.data.records)
  115. }
  116. this.page.total = res.data.total || 0;
  117. if (this.page.size * this.page.current >= res.data.total) {
  118. this.page.status = 'nomore'
  119. } else {
  120. this.page.status = 'loadmore'
  121. }
  122. }).catch(e => {
  123. this.page.status = 'loadmore'
  124. })
  125. },
  126. toDetail(id) {
  127. if (this.collectionType == 'dish') {
  128. uni.navigateTo({
  129. url: "/pages/yuecai/dish/detail/index?id=" + id,
  130. })
  131. } else if (this.collectionType == 'snacks') {
  132. uni.navigateTo({
  133. url: "/pages/yuecai/snacks/detail/index?id=" + id,
  134. })
  135. } else if (this.collectionType == 'restaurant') {
  136. uni.navigateTo({
  137. url: "/pages/yuecai/restaurant/detail/index?id=" + id,
  138. })
  139. }
  140. },
  141. deleteCollection(id, index) {
  142. if (this.loading) {
  143. return;
  144. }
  145. this.loading = true;
  146. this.$u.api.deleteCollection(id).then(res => {
  147. this.list.splice(index, 1);
  148. this.loading = false;
  149. }).catch(e => {
  150. this.loading = false;
  151. })
  152. }
  153. },
  154. }
  155. </script>
  156. <style scoped lang="scss">
  157. .view-page {
  158. overflow: hidden;
  159. }
  160. .info-list {
  161. display: flex;
  162. flex-wrap: wrap;
  163. .info-item {
  164. padding: 20rpx;
  165. width: 33%;
  166. box-sizing: border-box;
  167. .info-pic {
  168. margin: auto;
  169. width: 175rpx;
  170. height: 175rpx;
  171. background: bisque;
  172. }
  173. .info-title {
  174. word-break: break-all;
  175. text-align: center;
  176. color: #65371b;
  177. font-size: 24rpx;
  178. font-weight: 300;
  179. line-height: 47rpx;
  180. word-spacing: 2rpx;
  181. overflow: hidden;
  182. text-overflow: -o-ellipsis-lastline;
  183. overflow: hidden;
  184. text-overflow: ellipsis;
  185. display: -webkit-box;
  186. -webkit-line-clamp: 1;
  187. line-clamp: 3;
  188. -webkit-box-orient: vertical;
  189. }
  190. }
  191. }
  192. </style>