index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. <template>
  2. <view class="container flex-col" :style="{height: winHeight + 'px'}">
  3. <!-- #ifdef MP -->
  4. <!-- 状态栏高度 -->
  5. <view :style="{ height: `${statusBarHeight}px` }"></view>
  6. <!-- 导航栏 -->
  7. <view class="navigationbar flex-center" :style="{ height: `${navigationBarHeight}px` }">
  8. <view class="back-button" @tap="handBack()"></view>
  9. <navigator :url="`/pages/merchant_search/index?id=${takeoutId}`" class="input tui-skeleton-rect searchIpt flex-center"
  10. hover-class="none"><text class="iconfont icon-xiazai5"></text>
  11. 点击搜索外卖商家</navigator>
  12. </view>
  13. <!-- #endif -->
  14. <view class="box-merchant flex-col">
  15. <view class="top-merchant">
  16. <view class="flex-y-center">
  17. <image style="width: 96rpx; height: 96rpx;border-radius: 6rpx;" :src="recommendObj.avatar"></image>
  18. <view style="margin-left: 20rpx; flex: 1;">
  19. <view class="mer-name flex-between-center">
  20. <view>{{recommendObj.name}}</view>
  21. <view class='iconfont icon-jiantou' style="font-size: 30rpx;" @tap="merchantTab(recommendObj)"></view>
  22. </view>
  23. <view class="flex-between-center" style="padding-right: 53rpx;">
  24. <text class="mer-tj">今日推荐</text>
  25. <text class="goods-score">{{recommendObj.score}}</text>
  26. <text class="goods-info">月销量{{getFormattedSales(recommendObj.salesVolume)}}</text>
  27. <text v-if="recommendObj.isFreeDeliverFee" class="goods-info" style="color: #E5AD21;margin-left: 18rpx;">免配送费</text>
  28. <view v-if="recommendObj.isFreeDeliverFee && recommendObj.freeDeliverFee > 0" style="color: #999999;font-size: 21rpx;margin-left: 10rpx;text-decoration: line-through;">¥
  29. {{recommendObj.freeDeliverFee}}</view>
  30. <text v-if="!recommendObj.isFreeDeliverFee" style="color: #999999;font-size: 21rpx;margin-left: 10rpx;">配送费¥
  31. {{recommendObj.distCosts}}</text>
  32. <text class="goods-info" style="margin-left: 10rpx;">{{recommendObj.distance}}</text>
  33. </view>
  34. </view>
  35. </view>
  36. <view class="flex-y-center" style="margin: 15rpx 0;">
  37. <view class="cert-box" v-for="(item, index) in recommendObj.discountLabel" :key="index">{{item}}</view>
  38. </view>
  39. <scroll-view :scroll-x="true" scroll-with-animation style="white-space: nowrap;">
  40. <view class="top-box-item" v-for="(item, index) in recommendObj.proList" :key="index">
  41. <image style="width: 100%; height: 131rpx;border-radius: 10rpx;" :src="item.image"></image>
  42. <view class="name">{{item.name}}</view>
  43. <view style="padding-right: 23rpx">
  44. <text style="color: #FF6702;">¥</text><text class="bg-color">{{item.price}}</text>
  45. <!-- <text class="goods-info" style="text-decoration: line-through;">¥6</text> -->
  46. </view>
  47. </view>
  48. </scroll-view>
  49. </view>
  50. <scroll-view :scroll-x="true" scroll-with-animation style="white-space: nowrap;margin: 20rpx 0rpx;">
  51. <view :class="optionIndex == item.id ? 'active-option' : ''" style="color: #141414;display: inline-block;margin-right: 30rpx;width: 96rpx;"
  52. v-for="(item, index) in optionData" :key="index" @tap="onOptionClick(item)">
  53. <view class="flex-col flex-center">
  54. <image style="width: 100%;height: 96rpx;" :src="item.icon"></image>
  55. <view style="font-size: 21rpx;margin-top: 10rpx;">{{item.name}}</view>
  56. </view>
  57. </view>
  58. </scroll-view>
  59. <!-- 销量排行 -->
  60. <view class="tab-list" style="margin-top: 10rpx;">
  61. <view :class=" item.checked ? 'tab-item2' : 'tab-item2-false' " v-for="item in labelList" :key="item.id" @click="item2Click(item)">{{item.label}}</view>
  62. </view>
  63. <view class="flex-center flex-col" v-if="noDataTip">
  64. <image :src="urlDomain+'crmebimage/presets/noSearch.png'"></image>
  65. <text class="no-data-tip">{{noDataTip}}</text>
  66. </view>
  67. <scroll-view scroll-y scroll-with-animation style="flex: 1;overflow: hidden;" @scrolltolower="onScrollBottom">
  68. <view class="content-goods2" v-for="item in merchantList" :key="item.id" @click="merchantTab(item)">
  69. <view>
  70. <image :src="item.avatar" style="width: 230rpx;height: 230rpx;"></image>
  71. </view>
  72. <view style="margin-left: 20rpx;flex: 1;">
  73. <view class="">
  74. <text class="goods-title">{{item.name}}</text>
  75. </view>
  76. <view style="margin-top: 10rpx;">
  77. <text class="goods-score">{{item.score}}</text>
  78. <text class="goods-info" style="margin-left: 10rpx;">月销 {{getFormattedSales(item.salesVolume)}}</text>
  79. <text class="goods-info" style="margin-left: 25rpx;">人均 ¥ {{item.perCapita==null?0:item.perCapita}}</text>
  80. </view>
  81. <view style="margin-top: 10rpx;display: flex;align-items: center;">
  82. <text class="goods-info">起送 ¥ {{item.perCapita==null?0:item.perCapita}}</text>
  83. <text v-if="item.isFreeDeliverFee" class="goods-info" style="color: #E5AD21;margin-left: 18rpx;">免配送费</text>
  84. <view v-if="item.isFreeDeliverFee && item.freeDeliverFee > 0" style="color: #999999;font-size: 21rpx;margin-left: 10rpx;text-decoration: line-through;">¥
  85. {{item.freeDeliverFee}}</view>
  86. <text v-if="!item.isFreeDeliverFee" class="goods-info" style="color: #999999;margin-left: 40rpx;">配送费¥{{item.distCosts}}</text>
  87. <text class="goods-info" style="margin-left: 38rpx;">{{item.deliverTime}}分钟</text>
  88. <text class="goods-info" style="margin-left: 10rpx;">{{item.distance}}</text>
  89. </view>
  90. <view style="margin-top: 22rpx;"><text class="goods-sales">已售卖{{getFormattedSales(item.salesAllNum)}}单</text></view>
  91. <view style="margin-top: 14rpx;">
  92. <swiper :indicator-dots="false" :autoplay="true" :circular="true" :display-multiple-items="3" style="height: 43rpx;">
  93. <swiper-item v-for="(item2,index2) in item.discountLabel" :key="index2">
  94. <text class="goods-labels">{{item2}}</text>
  95. </swiper-item>
  96. </swiper>
  97. </view>
  98. </view>
  99. </view>
  100. <view class='loadingicon flex-center' :hidden='!loading'>
  101. <text class='loading iconfont icon-jiazai' style="width: auto;"></text>加载更多
  102. </view>
  103. <view class="flex-center no-data-tip" v-if="loadTitle">{{loadTitle}}</view>
  104. </scroll-view>
  105. </view>
  106. </view>
  107. </template>
  108. <script>
  109. // +----------------------------------------------------------------------
  110. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  111. // +----------------------------------------------------------------------
  112. // | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
  113. // +----------------------------------------------------------------------
  114. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  115. // +----------------------------------------------------------------------
  116. // | Author: CRMEB Team <admin@crmeb.com>
  117. // +----------------------------------------------------------------------
  118. import navBar from '@/components/navBar';
  119. import {
  120. getMerchantList,
  121. getHomeInfo,
  122. getMerchantSearchList
  123. } from '@/api/home.js';
  124. import {
  125. getTakeoutList,
  126. getProduct
  127. } from '@/api/takeout.js';
  128. import tags from '../../mixins/tags';
  129. let app = getApp();
  130. var statusBarHeight = uni.getSystemInfoSync().statusBarHeight + 'rpx';
  131. export default {
  132. components: {
  133. navBar
  134. },
  135. mixins:[tags],
  136. data() {
  137. return {
  138. statusBarHeight: app.globalData.statusBarHeight,
  139. navigationBarHeight: 0,
  140. takeoutId: null,
  141. winHeight: 0,
  142. recommendObj: {},
  143. optionData: [],
  144. optionIndex: 0,
  145. noDataTip: '',
  146. urlDomain: this.$Cache.get("imgHost"),
  147. // labelList: [{
  148. // id: 1,
  149. // label: "销量排行",
  150. // checked: true
  151. // }, {
  152. // id: 2,
  153. // label: "满减大促",
  154. // checked: false
  155. // }, {
  156. // id: 3,
  157. // label: "首单立减",
  158. // checked: false
  159. // }, {
  160. // id: 4,
  161. // label: "减配送费",
  162. // checked: false
  163. // }],
  164. merchantList: [],
  165. loadTitle:'',
  166. loading: false,
  167. page: 1,
  168. }
  169. },
  170. onLoad(options) {
  171. let that = this;
  172. const custom = wx.getMenuButtonBoundingClientRect()
  173. // 导航栏高度(标题栏高度) = 胶囊高度 + (顶部距离 - 状态栏高度) * 2
  174. that.navigationBarHeight = custom.height + (custom.top - that.statusBarHeight) * 2
  175. that.takeoutId = options.id;
  176. uni.getSystemInfo({
  177. success: function(res) {
  178. that.winHeight = res.windowHeight
  179. },
  180. });
  181. const allData = {
  182. name : '全部',
  183. id : 0,
  184. icon : '/static/img/quanbu.png',
  185. };
  186. getProduct(that.takeoutId).then(res => {
  187. const data = res.data;
  188. // data[0].id = 0;
  189. // data[0].name = '全部';
  190. // data[0].icon = '/static/img/quanbu.png';
  191. // that.optionIndex = data[0].id;
  192. // that.optionData = data || []
  193. if (data.length !== 0) {
  194. that.optionIndex =0;
  195. that.optionData.push(allData)
  196. data.forEach(function(item) {
  197. that.optionData.push(item);
  198. });
  199. }
  200. that.page = 1;
  201. that.getMatchedData()
  202. console.log(that.optionData, '12312321321312321321312312')
  203. })
  204. getTakeoutList({
  205. latitude: uni.getStorageSync('user_latitude'),
  206. longitude: uni.getStorageSync('user_longitude'),
  207. cateId: that.takeoutId
  208. }).then(recommendRes => {
  209. that.recommendObj = recommendRes.data
  210. console.log(that.recommendObj, '00000000000000000000000000')
  211. })
  212. },
  213. methods: {
  214. getFormattedSales(value) {
  215. // 转换成字符串,然后截取前三位,并添加“+”
  216. return value.length>3?`${String(value).slice(0, 3)}+`:value;
  217. },
  218. onScrollBottom() {
  219. if (!this.loadTitle) {
  220. this.getMatchedData()
  221. }
  222. },
  223. // getTag(){
  224. // return this.labelList.filter((ite => ite.checked)).map(ite => ite.id).join(',')
  225. // },
  226. getMatchedData() {
  227. if (this.loading) return;
  228. this.loading = true
  229. getMerchantSearchList({
  230. latitude: uni.getStorageSync('user_latitude'),
  231. longitude: uni.getStorageSync('user_longitude'),
  232. productType: this.takeoutId,
  233. typeIds: this.optionIndex==0?"":this.optionIndex,
  234. page: this.page,
  235. limit: 10,
  236. queryLabels: this.getTag()
  237. }).then(res => {
  238. let list = res.data.list || [];
  239. this.merchantList = this.$util.SplitArray(list, this.merchantList);
  240. if (this.merchantList.length == 0) {
  241. this.loadTitle = ''
  242. this.noDataTip = ' 暂无外卖商家 ';
  243. } else {
  244. this.noDataTip = ''
  245. this.loadTitle = list.length < 10 ? "我也是有底线的~" : '';
  246. }
  247. this.loading = false
  248. console.log('商品信息:', this.merchantList);
  249. this.page += 1;
  250. }).catch(err => {
  251. this.loading = false
  252. console.log(err)
  253. });
  254. },
  255. handBack() {
  256. uni.navigateBack({
  257. delta: 1
  258. })
  259. },
  260. goMerchant() {
  261. this.$util.navigateTo('/pages/merchant_search/index');
  262. },
  263. item2Click(item) {
  264. item.checked = !item.checked;
  265. this.merchantList = []
  266. this.page = 1
  267. this.getMatchedData()
  268. },
  269. // getMatchedData() {
  270. // getMerchantList({
  271. // latitude: uni.getStorageSync('user_latitude'),
  272. // longitude: uni.getStorageSync('user_longitude'),
  273. // cateId: this.takeoutId
  274. // }).then(res => {
  275. // this.merchantList = res.data.list;
  276. // this.noDataTip = this.merchantList.length ? '' : ' 暂无外卖商家 ';
  277. // console.log('商品信息:', this.merchantList);
  278. // });
  279. // },
  280. onOptionClick(item) {
  281. if (this.optionIndex === item.id) return
  282. this.page = 1;
  283. this.merchantList = [];
  284. this.optionIndex = item.id;
  285. //this.optionIndex = item.id;
  286. this.getMatchedData()
  287. },
  288. merchantTab(item) {
  289. // 修改跳转
  290. uni.navigateTo({
  291. url: `/pages/merchant/home/index?merId=${item.id}`
  292. // url: `/pages/goods_cate/index?id=${item.id}`
  293. })
  294. },
  295. }
  296. }
  297. </script>
  298. <style lang="scss" scoped>
  299. .searchIpt {
  300. width: 350rpx !important;
  301. height: 75%;
  302. background-color: #fff;
  303. border-radius: 35rpx;
  304. padding-left: 20rpx;
  305. justify-content: flex-start;
  306. }
  307. .no-data-tip {
  308. color: #CCC;
  309. }
  310. .container {
  311. overflow: hidden;
  312. position: relative;
  313. }
  314. .search-box {
  315. background-color: #fff;
  316. padding: 0 39rpx;
  317. margin-top: 10rpx;
  318. box-sizing: border-box;
  319. height: 96rpx;
  320. .flex-y-center {
  321. width: 100%;
  322. height: 69rpx;
  323. padding-left: 29rpx;
  324. border-radius: 35rpx;
  325. border: 2rpx solid #FF6702;
  326. }
  327. }
  328. .icon-fanhui2 {
  329. // line-height: 66rpx;
  330. }
  331. .search-box input {
  332. width: 90%;
  333. font-size: 26rpx;
  334. }
  335. .search-box .placeholder {
  336. color: #bbb;
  337. }
  338. .search-box .iconfont {
  339. color: #000;
  340. font-size: 35rpx;
  341. }
  342. .box-merchant {
  343. background-color: #F5F5F5;
  344. border-radius: 30rpx 30rpx 0 0;
  345. padding: 20rpx 20rpx 0 20rpx;
  346. // margin-top: 30rpx;
  347. overflow: hidden;
  348. flex: 1;
  349. }
  350. .top-merchant {
  351. background-color: #fff;
  352. position: relative;
  353. padding: 20rpx;
  354. border-radius: 20rpx;
  355. .mer-name {
  356. font-weight: 600;
  357. font-size: 27rpx;
  358. color: #141414;
  359. margin-bottom: 10rpx;
  360. overflow: hidden;
  361. text-overflow: ellipsis;
  362. white-space: nowrap;
  363. }
  364. .mer-tj {
  365. background: #FAFAFA;
  366. border-radius: 19rpx;
  367. font-weight: 400;
  368. font-size: 17rpx;
  369. color: #646464;
  370. padding: 6rpx 10rpx;
  371. }
  372. .cert-box {
  373. font-size: 21rpx;
  374. color: #FF6702;
  375. background: #FEEFE5;
  376. border-radius: 8rpx;
  377. padding: 4rpx 20rpx;
  378. margin-right: 10rpx;
  379. }
  380. .top-box-item {
  381. width: 173rpx;
  382. margin-right: 20rpx;
  383. display: inline-block;
  384. .name {
  385. font-weight: 400;
  386. font-size: 21rpx;
  387. color: #141414;
  388. width: 100%;
  389. overflow: hidden;
  390. text-overflow: ellipsis;
  391. white-space: nowrap;
  392. }
  393. }
  394. }
  395. .bg-color {
  396. color: $bg-color-primary;
  397. font-weight: 600;
  398. font-size: 31rpx;
  399. }
  400. .active-option {
  401. color: $bg-color-primary !important;
  402. }
  403. .tab-list {
  404. display: flex;
  405. /* 启用弹性布局 */
  406. flex-direction: row;
  407. /* 横向排列 */
  408. justify-content: space-between;
  409. /* 均匀分布子项 */
  410. flex-wrap: wrap;
  411. /* 允许换行(适用于屏幕宽度不足时) */
  412. .tab-item2 {
  413. width: 23%;
  414. /* 5个元素平分宽度,留2%作为间隙 */
  415. text-align: center;
  416. background-color: #FFC127;
  417. border-radius: 8rpx;
  418. font-size: 23rpx;
  419. padding: 6rpx;
  420. font-weight: 400;
  421. }
  422. .tab-item2-false {
  423. width: 23%;
  424. /* 5个元素平分宽度,留2%作为间隙 */
  425. text-align: center;
  426. background-color: #fff;
  427. border-radius: 8rpx;
  428. font-size: 23rpx;
  429. padding: 6rpx;
  430. font-weight: 400;
  431. }
  432. }
  433. .content-goods2 {
  434. background: #FFFFFF;
  435. border-radius: 23rpx;
  436. margin-top: 10rpx;
  437. padding: 20rpx;
  438. display: flex;
  439. }
  440. .goods-title {
  441. color: #141414;
  442. font-size: 26rpx;
  443. font-weight: 600;
  444. }
  445. .goods-desc {
  446. color: #646464;
  447. font-size: 21rpx;
  448. margin-top: 10rpx;
  449. }
  450. .goods-price {
  451. color: #FF9805;
  452. font-size: 34rpx;
  453. font-weight: 600;
  454. }
  455. .goods-score {
  456. color: $bg-color-primary;
  457. font-size: 27rpx;
  458. }
  459. .goods-info {
  460. color: #999999;
  461. font-size: 21rpx;
  462. }
  463. .goods-info3 {
  464. color: #999999;
  465. font-size: 21rpx;
  466. margin-left: 10rpx;
  467. text-decoration: line-through;
  468. }
  469. .goods-sales {
  470. background-color: #FEEFE5;
  471. color: #FF6702;
  472. border-radius: 8rpx;
  473. font-size: 21rpx;
  474. padding: 4rpx 20rpx;
  475. }
  476. .goods-labels {
  477. background-color: #FFF6F6;
  478. color: #FF4B4B;
  479. border: 2rpx solid #FF4B4B;
  480. border-radius: 8rpx;
  481. font-size: 21rpx;
  482. padding: 4rpx 16rpx;
  483. margin-right: 20rpx;
  484. margin-left: 10rpx;
  485. }
  486. .back-button {
  487. width: 25rpx;
  488. height: 25rpx;
  489. border-right: 4rpx solid #fff;
  490. border-bottom: 4rpx solid #fff;
  491. transform: rotate(135deg);
  492. margin-left: 10rpx;
  493. display: inline-block;
  494. }
  495. .navigationbar {
  496. position: relative;
  497. background-color: $bg-color-primary;
  498. .back-button {
  499. position: absolute;
  500. left: 40rpx;
  501. }
  502. }
  503. </style>