index.vue 14 KB

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