index.vue 5.3 KB

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