index.vue 9.5 KB

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