index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  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}}</text>
  52. </view>
  53. <view style="margin-top: 10rpx;display: flex;align-items: center;">
  54. <text class="goods-info">起送 ¥ {{item.perCapita}}</text>
  55. <text v-if="!item.isfreeDeliverfee" class="goods-info" style="color: #E5AD21;margin-left: 18rpx;">免配送费</text>
  56. <view v-if="!item.isfreeDeliverfee && item.freeDeliverFee > 0" style="color: #999999;font-size: 21rpx;margin-left: 10rpx;text-decoration: line-through;">¥
  57. {{item.freeDeliverFee}}</view>
  58. <text v-if="item.isfreeDeliverfee" style="color: #999999;font-size: 21rpx;margin-left: 10rpx;">配送费¥
  59. {{item.distCosts}}</text>
  60. <text class="goods-info" style="margin-left: 38rpx;">10分钟</text>
  61. <text class="goods-info" style="margin-left: 10rpx;">{{item.distance}}</text>
  62. </view>
  63. <view style="margin-top: 22rpx;"><text class="goods-sales">已售卖{{item.salesVolume}}件</text></view>
  64. <view style="margin-top: 14rpx;">
  65. <text class="goods-labels" v-for="(item2,index2) in item.discountLabel" :key="index2">{{item2}}</text>
  66. </view>
  67. </view>
  68. </view>
  69. <view class='loadingicon flex-center' :hidden='!loading'>
  70. <text class='loading iconfont icon-jiazai' style="width: auto;"></text>加载更多
  71. </view>
  72. <view class="flex-center no-data-tip" v-if="loadTitle">{{loadTitle}}</view>
  73. </scroll-view>
  74. </view>
  75. </view>
  76. </template>
  77. <script>
  78. // +----------------------------------------------------------------------
  79. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  80. // +----------------------------------------------------------------------
  81. // | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
  82. // +----------------------------------------------------------------------
  83. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  84. // +----------------------------------------------------------------------
  85. // | Author: CRMEB Team <admin@crmeb.com>
  86. // +----------------------------------------------------------------------
  87. import {
  88. getSearchKeyword,
  89. } from '@/api/product.js';
  90. // #ifdef MP
  91. import navBar from '@/components/navBar';
  92. // #endif
  93. import {
  94. getMerchantSearchList,
  95. getHomeInfo
  96. } from '@/api/home.js';
  97. import {
  98. getProduct
  99. } from '@/api/takeout.js';
  100. import tags from '../../mixins/tags';
  101. let app = getApp();
  102. export default {
  103. components: {
  104. // #ifdef MP
  105. navBar
  106. // #endif
  107. },
  108. mixins:[tags],
  109. data() {
  110. return {
  111. optionData: [],
  112. optionIndex: 0,
  113. winHeight: 0,
  114. navTitle: '搜索外卖商家',
  115. hostProduct: [],
  116. searchValue: '',
  117. focus: false,
  118. bastList: [],
  119. hotSearchList: [],
  120. theme: app.globalData.theme,
  121. page: 1,
  122. // labelList: [{
  123. // id: 1,
  124. // label: "销量排行",
  125. // checked: true
  126. // }, {
  127. // id: 2,
  128. // label: "满减大促",
  129. // checked: false
  130. // }, {
  131. // id: 3,
  132. // label: "首单立减",
  133. // checked: false
  134. // }, {
  135. // id: 4,
  136. // label: "减配送费",
  137. // checked: false
  138. // }],
  139. urlDomain: this.$Cache.get("imgHost"),
  140. merchantList: [],
  141. noDataTip: '',
  142. loadTitle: '',
  143. loading: false,
  144. cateId: 0
  145. };
  146. },
  147. // 滚动监听
  148. onPageScroll(e) {
  149. // 传入scrollTop值并触发所有easy-loadimage组件下的滚动监听事件
  150. uni.$emit('scroll');
  151. },
  152. onShow: function() {
  153. this.getRoutineHotSearch();
  154. },
  155. onLoad(e) {
  156. let that = this
  157. uni.getSystemInfo({
  158. success: function(res) {
  159. that.winHeight = res.windowHeight
  160. },
  161. });
  162. if (e.searchVal) that.searchValue = e.searchVal;
  163. e.navTitle ? that.navTitle = e.navTitle : ''
  164. e.id ? that.cateId = e.id : ''
  165. const allData = {
  166. name : '全部',
  167. id : 0,
  168. icon : '/static/img/quanbu.png',
  169. };
  170. getProduct(that.cateId).then(res => {
  171. const data = res.data;
  172. if (data.length !== 0) {
  173. that.optionIndex =0;
  174. that.optionData.push(allData)
  175. data.forEach(function(item) {
  176. that.optionData.push(item);
  177. });
  178. }
  179. that.getMatchedData()
  180. })
  181. },
  182. methods: {
  183. // getTag(){
  184. // return this.labelList.filter((ite => ite.checked)).map(ite => ite.id).join(',')
  185. // },
  186. getMatchedData() {
  187. if (this.loading) return;
  188. this.loading = true
  189. getMerchantSearchList({
  190. latitude: uni.getStorageSync('user_latitude'),
  191. longitude: uni.getStorageSync('user_longitude'),
  192. productType: this.cateId,
  193. keywords: this.searchValue,
  194. typeIds: this.optionIndex==0?"":this.optionIndex,
  195. page: this.page,
  196. limit: 10,
  197. queryLabels: this.getTag()
  198. }).then(res => {
  199. let list = res.data.list || [];
  200. this.merchantList = this.$util.SplitArray(list, this.merchantList);
  201. if (this.merchantList.length == 0) {
  202. this.loadTitle = ''
  203. this.noDataTip = ' 暂无外卖商家 ';
  204. } else {
  205. this.noDataTip = ''
  206. this.loadTitle = list.length < 10 ? "我也是有底线的~" : '';
  207. }
  208. this.loading = false
  209. console.log('商品信息:', this.merchantList);
  210. this.page += 1;
  211. }).catch(err => {
  212. this.loading = false
  213. console.log(err)
  214. });
  215. },
  216. item2Click(item) {
  217. item.checked = !item.checked;
  218. this.merchantList = []
  219. this.page = 1
  220. this.getMatchedData()
  221. },
  222. onOptionClick(item) {
  223. if (this.optionIndex === item.id) return
  224. this.page = 1;
  225. this.merchantList = [];
  226. this.optionIndex = item.id;
  227. this.getMatchedData()
  228. },
  229. getRoutineHotSearch: function() {
  230. let that = this;
  231. getSearchKeyword().then(res => {
  232. that.$set(that, 'hotSearchList', res.data);
  233. });
  234. },
  235. setHotSearchValue: function(event) {
  236. this.$set(this, 'searchValue', event);
  237. this.page = 1;
  238. this.merchantList = [];
  239. this.$set(this, 'bastList', []);
  240. this.getMatchedData()
  241. // uni.navigateTo({
  242. // url: `/pages/goods/goods_list/index?searchValue=${this.searchValue}`
  243. // })
  244. },
  245. setValue: function(event) {
  246. this.$set(this, 'searchValue', event.detail.value);
  247. },
  248. searchBut: function(e) {
  249. let that = this;
  250. let val = '';
  251. that.focus = false;
  252. if (e.detail.value) {
  253. val = e.detail.value
  254. }
  255. if (that.searchValue.length > 0 || val) {
  256. this.page = 1;
  257. this.merchantList = [];
  258. this.getMatchedData()
  259. } else {
  260. return this.$util.Tips({
  261. title: '请输入要搜索的外卖商家',
  262. icon: 'none',
  263. duration: 1000,
  264. mask: true,
  265. });
  266. }
  267. },
  268. merchantTab(item) {
  269. // 修改跳转
  270. uni.navigateTo({
  271. url: `/pages/merchant/home/index?merId=${item.id}`
  272. // url: `/pages/goods_cate/index?id=${item.id}`
  273. })
  274. },
  275. onScrollBottom() {
  276. if (!this.loadTitle) {
  277. this.getMatchedData()
  278. }
  279. }
  280. }
  281. }
  282. </script>
  283. <style lang="scss" scoped>
  284. .container {
  285. overflow: hidden;
  286. position: relative;
  287. }
  288. .no-data-tip {
  289. color: #CCC;
  290. }
  291. page {
  292. background-color: #f5f5f5 !important;
  293. }
  294. .searchGood .search {
  295. padding-left: 30rpx;
  296. background-color: #fff !important;
  297. }
  298. .searchGood .search {
  299. /* #ifndef MP */
  300. padding-top: 20rpx;
  301. padding-bottom: 20rpx;
  302. /* #endif */
  303. /* #ifdef MP */
  304. position: fixed;
  305. width: 100%;
  306. z-index: 9999;
  307. top: 0;
  308. /* #endif */
  309. }
  310. .searchGood .search .input {
  311. width: 598rpx;
  312. background-color: #f7f7f7;
  313. border-radius: 33rpx;
  314. padding: 0 35rpx;
  315. box-sizing: border-box;
  316. height: 66rpx;
  317. }
  318. .searchGood .search .input input {
  319. width: 472rpx;
  320. font-size: 26rpx;
  321. }
  322. .searchGood .search .input .placeholder {
  323. color: #bbb;
  324. }
  325. .searchGood .search .input .iconfont {
  326. color: #000;
  327. font-size: 35rpx;
  328. }
  329. .searchGood .search .bnt {
  330. width: 120rpx;
  331. text-align: center;
  332. height: 66rpx;
  333. line-height: 66rpx;
  334. font-size: 30rpx;
  335. color: #282828;
  336. }
  337. .searchGood .title {
  338. font-weight: 500;
  339. font-family: PingFang SC, PingFang SC;
  340. font-size: 28rpx;
  341. color: #333;
  342. margin: 50rpx 30rpx 25rpx 30rpx;
  343. }
  344. .searchGood .list {
  345. padding-left: 10rpx;
  346. }
  347. .searchGood .list .item {
  348. font-size: 26rpx;
  349. color: #454545;
  350. padding: 0 21rpx;
  351. height: 60rpx;
  352. border-radius: 30rpx;
  353. line-height: 60rpx;
  354. border: 1rpx solid #aaa;
  355. margin: 0 0 20rpx 20rpx;
  356. }
  357. .searchGood .line {
  358. margin: 20rpx 30rpx 0 30rpx;
  359. }
  360. .searchBox {
  361. width: 100%;
  362. }
  363. .search-box {
  364. background-color: #fff;
  365. padding: 0 39rpx;
  366. margin-top: 10rpx;
  367. box-sizing: border-box;
  368. height: 96rpx;
  369. .flex-y-center {
  370. width: 100%;
  371. height: 69rpx;
  372. padding-left: 29rpx;
  373. border-radius: 35rpx;
  374. border: 2rpx solid #FF6702;
  375. }
  376. .bnt {
  377. background: #FF6702;
  378. border-radius: 35rpx;
  379. width: 115rpx;
  380. height: 100%;
  381. font-weight: 500;
  382. font-size: 35rpx;
  383. color: #FFFFFF;
  384. }
  385. }
  386. .icon-fanhui2 {
  387. // line-height: 66rpx;
  388. }
  389. .search-box input {
  390. width: 90%;
  391. font-size: 26rpx;
  392. }
  393. .search-box .placeholder {
  394. color: #bbb;
  395. }
  396. .search-box .iconfont {
  397. color: #000;
  398. font-size: 35rpx;
  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. .active-option {
  483. color: $bg-color-primary !important;
  484. }
  485. </style>