index.vue 15 KB

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