index.vue 5.5 KB

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