index.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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. <view class="search-view">
  16. <view class="area-selector">
  17. <u-list height="100%">
  18. <view class="area-name" :class="{'area-name-active': currentArea==item.code}"
  19. v-for="(item,index) in areaOptions[cuisineType]" :key="index" @click="areaChange(item.code)">
  20. {{item.name}}
  21. </view>
  22. </u-list>
  23. </view>
  24. <view class="search-result">
  25. <u-list @scrolltolower="scrolltolower" height="100%" lowerThreshold="10">
  26. <view class="info-list">
  27. <view class="info-item" v-for="(item, index) in list" :key="index" @click="toDetail(item.id)">
  28. <view class="info-pic">
  29. <u-image width="175rpx" height="175rpx" mode="aspectFill" :src="item.cover"></u-image>
  30. </view>
  31. <view class="info-title">
  32. {{item.name}}
  33. </view>
  34. </view>
  35. </view>
  36. <u-loadmore :status="page.status" :loading-text="page.loadingText" :loadmore-text="page.loadmoreText"
  37. :nomore-text="page.nomoreText" />
  38. </u-list>
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import themeMixins from '@/pages/yuecai/mixins/themeMixins.js';
  45. export default {
  46. mixins: [themeMixins],
  47. data() {
  48. return {
  49. page: {
  50. current: 1,
  51. size: 15,
  52. total: 0,
  53. // loadmore loading nomore
  54. status: 'loadmore',
  55. loadingText: '正在加载中',
  56. loadmoreText: '上拉加载更多',
  57. nomoreText: '没有更多了'
  58. },
  59. keyword: '',
  60. list: [],
  61. tabList: [{
  62. name: '名店',
  63. }, {
  64. name: '名菜'
  65. }, {
  66. name: '名点',
  67. }],
  68. currentArea: '',
  69. cuisineType: '',
  70. areaOptions: {
  71. 'guagnfu': [{
  72. code: "4401",
  73. name: "广州市"
  74. },
  75. {
  76. code: "4403",
  77. name: "深圳市"
  78. },
  79. {
  80. code: "4404",
  81. name: "珠海市"
  82. },
  83. {
  84. code: "4406",
  85. name: "佛山市"
  86. },
  87. {
  88. code: "4407",
  89. name: "江门市"
  90. },
  91. {
  92. code: "4408",
  93. name: "湛江市"
  94. },
  95. {
  96. code: "4409",
  97. name: "茂名市"
  98. },
  99. {
  100. code: "4412",
  101. name: "肇庆市"
  102. },
  103. {
  104. code: "4417",
  105. name: "阳江市"
  106. },
  107. {
  108. code: "4418",
  109. name: "清远市"
  110. },
  111. {
  112. code: "4419",
  113. name: "东莞市"
  114. },
  115. {
  116. code: "4420",
  117. name: "中山市"
  118. },
  119. {
  120. code: "4453",
  121. name: "云浮市"
  122. }
  123. ],
  124. 'chaozhou': [{
  125. code: "4405",
  126. name: "汕头市"
  127. }, {
  128. code: "4415",
  129. name: "汕尾市"
  130. }, {
  131. code: "4451",
  132. name: "潮州市"
  133. }, {
  134. code: "4452",
  135. name: "揭阳市"
  136. }],
  137. 'kejia': [{
  138. code: "4402",
  139. name: "韶关市"
  140. }, {
  141. code: "4413",
  142. name: "惠州市"
  143. }, {
  144. code: "4414",
  145. name: "梅州市"
  146. }, {
  147. code: "4416",
  148. name: "河源市"
  149. }]
  150. },
  151. currentTab: 0
  152. }
  153. },
  154. onLoad(options) {
  155. this.cuisineType = options.cuisineType || ''
  156. //
  157. this.currentTab = 0;
  158. wx.setNavigationBarTitle({
  159. title: '名店'
  160. })
  161. //
  162. // switch (options.type) {
  163. // case 'restaurant':
  164. // this.currentTab = 0;
  165. // wx.setNavigationBarTitle({
  166. // title: '名店'
  167. // })
  168. // break;
  169. // case 'dish':
  170. // this.currentTab = 1;
  171. // wx.setNavigationBarTitle({
  172. // title: '名菜'
  173. // })
  174. // break;
  175. // case 'snacks':
  176. // this.currentTab = 2;
  177. // wx.setNavigationBarTitle({
  178. // title: '名点'
  179. // })
  180. // break;
  181. // default:
  182. // this.currentTab = 0;
  183. // wx.setNavigationBarTitle({
  184. // title: '名店'
  185. // })
  186. // break;
  187. // }
  188. this.keyword = '';
  189. this.doRefresh();
  190. },
  191. methods: {
  192. areaChange(areaCode) {
  193. if (!areaCode) {
  194. return;
  195. }
  196. //
  197. if (this.currentArea == areaCode) {
  198. this.currentArea = '';
  199. } else {
  200. this.currentArea = areaCode;
  201. }
  202. this.doRefresh();
  203. },
  204. tabChange(e) {
  205. this.currentTab = e.index;
  206. switch (this.currentTab) {
  207. case 0:
  208. uni.setNavigationBarTitle({
  209. title: '名店'
  210. })
  211. break;
  212. case 1:
  213. uni.setNavigationBarTitle({
  214. title: '名菜'
  215. })
  216. break;
  217. case 2:
  218. uni.setNavigationBarTitle({
  219. title: '名点'
  220. })
  221. break;
  222. default:
  223. return;
  224. break;
  225. }
  226. this.doRefresh();
  227. },
  228. scrolltolower() {
  229. this.loadmore()
  230. },
  231. loadmore() {
  232. this.page.current++;
  233. this.getList();
  234. },
  235. doRefresh() {
  236. this.page.current = 1;
  237. this.page.status = 'loadmore'
  238. this.list = [];
  239. this.getList();
  240. },
  241. getList() {
  242. if (this.page.status == 'loading' || this.page.status == 'nomore') {
  243. // 防止重复下拉
  244. return;
  245. }
  246. this.page.status = 'loading';
  247. //
  248. let listFunc;
  249. switch (this.currentTab) {
  250. case 0:
  251. listFunc = this.$u.api.getRestaurantList;
  252. break;
  253. case 1:
  254. listFunc = this.$u.api.getDishList;
  255. break;
  256. case 2:
  257. listFunc = this.$u.api.getSnacksList;
  258. break;
  259. default:
  260. return;
  261. break;
  262. }
  263. //
  264. listFunc(this.page.current, this.page.size, {
  265. name: this.keyword || '',
  266. cuisineCode: this.cuisineType || '',
  267. regionId: this.currentArea || ''
  268. }).then(res => {
  269. if (res.data.records && res.data.records.length > 0) {
  270. this.list.push(...res.data.records)
  271. }
  272. this.page.total = res.data.total || 0;
  273. if (this.page.size * this.page.current >= res.data.total) {
  274. this.page.status = 'nomore'
  275. } else {
  276. this.page.status = 'loadmore'
  277. }
  278. })
  279. },
  280. toDetail(id) {
  281. switch (this.currentTab) {
  282. case 0:
  283. uni.navigateTo({
  284. url: "/pages/yuecai/restaurant/detail/index?id=" + id,
  285. })
  286. break;
  287. case 1:
  288. uni.navigateTo({
  289. url: "/pages/yuecai/dish/detail/index?id=" + id,
  290. })
  291. break;
  292. case 2:
  293. uni.navigateTo({
  294. url: "/pages/yuecai/snacks/detail/index?id=" + id,
  295. })
  296. break;
  297. default:
  298. return;
  299. break;
  300. }
  301. }
  302. },
  303. }
  304. </script>
  305. <style scoped lang="scss">
  306. .view-page {
  307. overflow: hidden;
  308. }
  309. .info-list {
  310. display: flex;
  311. flex-wrap: wrap;
  312. background-color: #f4f4f4;
  313. .info-item {
  314. padding: 20rpx;
  315. width: 33%;
  316. box-sizing: border-box;
  317. .info-pic {
  318. margin: auto;
  319. width: 175rpx;
  320. height: 175rpx;
  321. background: bisque;
  322. }
  323. .info-title {
  324. word-break: break-all;
  325. text-align: center;
  326. color: #65371b;
  327. font-size: 24rpx;
  328. font-weight: 300;
  329. line-height: 47rpx;
  330. word-spacing: 2rpx;
  331. overflow: hidden;
  332. text-overflow: -o-ellipsis-lastline;
  333. overflow: hidden;
  334. text-overflow: ellipsis;
  335. display: -webkit-box;
  336. -webkit-line-clamp: 1;
  337. line-clamp: 3;
  338. -webkit-box-orient: vertical;
  339. }
  340. }
  341. }
  342. .search-view {
  343. height: calc(100% - 91px);
  344. display: flex;
  345. }
  346. .area-selector {
  347. height: 100%;
  348. width: 70px;
  349. .area-name {
  350. text-align: center;
  351. line-height: 35px;
  352. border-top: 1rpx solid #f0f0f0;
  353. }
  354. .area-name-active {
  355. color: white;
  356. background-color: #65371b;
  357. font-weight: bold;
  358. }
  359. }
  360. .search-result {
  361. width: calc(100% - 70px);
  362. height: 100%;
  363. background-color: #f4f4f4;
  364. }
  365. </style>