index.vue 6.1 KB

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