index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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="175rpx" height="175rpx" 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. name: '名菜',
  48. }, {
  49. name: '名点',
  50. }],
  51. currentTab: 0
  52. }
  53. },
  54. onLoad(options) {
  55. this.collectionType = options.type || 'information'
  56. switch (options.type) {
  57. case 'information':
  58. this.currentTab = 0;
  59. break;
  60. case 'professional_style':
  61. this.currentTab = 1;
  62. break;
  63. case 'restaurant':
  64. this.currentTab = 2;
  65. break;
  66. case 'dish':
  67. this.currentTab = 3;
  68. break;
  69. case 'snacks':
  70. this.currentTab = 4;
  71. break;
  72. default:
  73. this.currentTab = 0;
  74. break;
  75. }
  76. },
  77. onShow() {
  78. this.keyword = '';
  79. this.doRefresh();
  80. },
  81. methods: {
  82. tabChange(e) {
  83. this.currentTab = e.index;
  84. switch (e.index) {
  85. case 0:
  86. this.collectionType = 'restaurant';
  87. break;
  88. case 1:
  89. this.collectionType = 'dish';
  90. break;
  91. case 2:
  92. this.collectionType = 'snacks';
  93. break;
  94. default:
  95. this.collectionType = 'restaurant';
  96. break;
  97. }
  98. this.doRefresh();
  99. },
  100. scrolltolower() {
  101. this.loadmore()
  102. },
  103. loadmore() {
  104. this.page.current++;
  105. this.getList();
  106. },
  107. doRefresh() {
  108. this.page.current = 1;
  109. this.page.status = 'loadmore'
  110. this.list = [];
  111. this.getList();
  112. },
  113. getList() {
  114. if (this.page.status == 'loading' || this.page.status == 'nomore') {
  115. // 防止重复下拉
  116. return;
  117. }
  118. this.page.status = 'loading';
  119. //
  120. this.$u.api.getCollectionList(this.page.current, this.page.size, {
  121. collectType: this.collectionType || ''
  122. }).then(res => {
  123. if (res.data.records && res.data.records.length > 0) {
  124. this.list.push(...res.data.records)
  125. }
  126. this.page.total = res.data.total || 0;
  127. if (this.page.size * this.page.current >= res.data.total) {
  128. this.page.status = 'nomore'
  129. } else {
  130. this.page.status = 'loadmore'
  131. }
  132. }).catch(e => {
  133. this.page.status = 'loadmore'
  134. })
  135. },
  136. toDetail(id) {
  137. if (this.collectionType == 'dish') {
  138. uni.navigateTo({
  139. url: "/pages/yuecai/dish/detail/index?id=" + id,
  140. })
  141. } else if (this.collectionType == 'snacks') {
  142. uni.navigateTo({
  143. url: "/pages/yuecai/snacks/detail/index?id=" + id,
  144. })
  145. } else if (this.collectionType == 'restaurant') {
  146. uni.navigateTo({
  147. url: "/pages/yuecai/restaurant/detail/index?id=" + id,
  148. })
  149. }
  150. },
  151. deleteCollection(id, index) {
  152. if (this.loading) {
  153. return;
  154. }
  155. this.loading = true;
  156. this.$u.api.deleteCollection(id).then(res => {
  157. this.list.splice(index, 1);
  158. this.loading = false;
  159. }).catch(e => {
  160. this.loading = false;
  161. })
  162. }
  163. },
  164. }
  165. </script>
  166. <style scoped lang="scss">
  167. .view-page {
  168. overflow: hidden;
  169. }
  170. .info-list {
  171. display: flex;
  172. flex-wrap: wrap;
  173. .info-item {
  174. padding: 20rpx;
  175. width: 33%;
  176. box-sizing: border-box;
  177. .info-pic {
  178. margin: auto;
  179. width: 175rpx;
  180. height: 175rpx;
  181. background: bisque;
  182. }
  183. .info-title {
  184. word-break: break-all;
  185. text-align: center;
  186. color: #65371b;
  187. font-size: 24rpx;
  188. font-weight: 300;
  189. line-height: 47rpx;
  190. word-spacing: 2rpx;
  191. overflow: hidden;
  192. text-overflow: -o-ellipsis-lastline;
  193. overflow: hidden;
  194. text-overflow: ellipsis;
  195. display: -webkit-box;
  196. -webkit-line-clamp: 1;
  197. line-clamp: 3;
  198. -webkit-box-orient: vertical;
  199. }
  200. }
  201. }
  202. </style>