index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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. let app = getApp();
  101. export default {
  102. components: {
  103. // #ifdef MP
  104. navBar
  105. // #endif
  106. },
  107. data() {
  108. return {
  109. optionData: [],
  110. optionIndex: 0,
  111. winHeight: 0,
  112. navTitle: '搜索外卖商家',
  113. hostProduct: [],
  114. searchValue: '',
  115. focus: false,
  116. bastList: [],
  117. hotSearchList: [],
  118. theme: app.globalData.theme,
  119. page: 1,
  120. labelList: [{
  121. id: 1,
  122. label: "销量排行",
  123. checked: true
  124. }, {
  125. id: 2,
  126. label: "满减大促",
  127. checked: false
  128. }, {
  129. id: 3,
  130. label: "首单立减",
  131. checked: false
  132. }, {
  133. id: 4,
  134. label: "减配送费",
  135. checked: false
  136. }],
  137. urlDomain: this.$Cache.get("imgHost"),
  138. merchantList: [],
  139. noDataTip: '',
  140. loadTitle: '',
  141. loading: false,
  142. cateId: 0
  143. };
  144. },
  145. // 滚动监听
  146. onPageScroll(e) {
  147. // 传入scrollTop值并触发所有easy-loadimage组件下的滚动监听事件
  148. uni.$emit('scroll');
  149. },
  150. onShow: function() {
  151. this.getRoutineHotSearch();
  152. },
  153. onLoad(e) {
  154. let that = this
  155. uni.getSystemInfo({
  156. success: function(res) {
  157. that.winHeight = res.windowHeight
  158. },
  159. });
  160. if (e.searchVal) that.searchValue = e.searchVal;
  161. e.navTitle ? that.navTitle = e.navTitle : ''
  162. e.id ? that.cateId = e.id : ''
  163. const allData = {
  164. name : '全部',
  165. id : 0,
  166. icon : '/static/img/quanbu.png',
  167. };
  168. getProduct(that.cateId).then(res => {
  169. const data = res.data;
  170. if (data.length !== 0) {
  171. that.optionIndex =0;
  172. that.optionData.push(allData)
  173. data.forEach(function(item) {
  174. that.optionData.push(item);
  175. });
  176. }
  177. that.getMatchedData()
  178. })
  179. },
  180. methods: {
  181. getMatchedData() {
  182. if (this.loading) return;
  183. this.loading = true
  184. getMerchantSearchList({
  185. latitude: uni.getStorageSync('user_latitude'),
  186. longitude: uni.getStorageSync('user_longitude'),
  187. productType: this.cateId,
  188. keywords: this.searchValue,
  189. typeIds: this.optionIndex==0?"":this.optionIndex,
  190. page: this.page,
  191. limit: 10
  192. }).then(res => {
  193. let list = res.data.list || [];
  194. this.merchantList = this.$util.SplitArray(list, this.merchantList);
  195. if (this.merchantList.length == 0) {
  196. this.loadTitle = ''
  197. this.noDataTip = ' 暂无外卖商家 ';
  198. } else {
  199. this.noDataTip = ''
  200. this.loadTitle = list.length < 10 ? "我也是有底线的~" : '';
  201. }
  202. this.loading = false
  203. console.log('商品信息:', this.merchantList);
  204. this.page += 1;
  205. }).catch(err => {
  206. this.loading = false
  207. console.log(err)
  208. });
  209. },
  210. item2Click(item) {
  211. item.checked = !item.checked;
  212. },
  213. onOptionClick(item) {
  214. if (this.optionIndex === item.id) return
  215. this.page = 1;
  216. this.merchantList = [];
  217. this.optionIndex = item.id;
  218. this.getMatchedData()
  219. },
  220. getRoutineHotSearch: function() {
  221. let that = this;
  222. getSearchKeyword().then(res => {
  223. that.$set(that, 'hotSearchList', res.data);
  224. });
  225. },
  226. setHotSearchValue: function(event) {
  227. this.$set(this, 'searchValue', event);
  228. this.page = 1;
  229. this.merchantList = [];
  230. this.$set(this, 'bastList', []);
  231. this.getMatchedData()
  232. // uni.navigateTo({
  233. // url: `/pages/goods/goods_list/index?searchValue=${this.searchValue}`
  234. // })
  235. },
  236. setValue: function(event) {
  237. this.$set(this, 'searchValue', event.detail.value);
  238. },
  239. searchBut: function(e) {
  240. let that = this;
  241. let val = '';
  242. that.focus = false;
  243. if (e.detail.value) {
  244. val = e.detail.value
  245. }
  246. if (that.searchValue.length > 0 || val) {
  247. this.page = 1;
  248. this.merchantList = [];
  249. this.getMatchedData()
  250. } else {
  251. return this.$util.Tips({
  252. title: '请输入要搜索的外卖商家',
  253. icon: 'none',
  254. duration: 1000,
  255. mask: true,
  256. });
  257. }
  258. },
  259. merchantTab(item) {
  260. // 修改跳转
  261. uni.navigateTo({
  262. url: `/pages/merchant/home/index?merId=${item.id}`
  263. // url: `/pages/goods_cate/index?id=${item.id}`
  264. })
  265. },
  266. onScrollBottom() {
  267. if (!this.loadTitle) {
  268. this.getMatchedData()
  269. }
  270. }
  271. }
  272. }
  273. </script>
  274. <style lang="scss" scoped>
  275. .container {
  276. overflow: hidden;
  277. position: relative;
  278. }
  279. .no-data-tip {
  280. color: #CCC;
  281. }
  282. page {
  283. background-color: #f5f5f5 !important;
  284. }
  285. .searchGood .search {
  286. padding-left: 30rpx;
  287. background-color: #fff !important;
  288. }
  289. .searchGood .search {
  290. /* #ifndef MP */
  291. padding-top: 20rpx;
  292. padding-bottom: 20rpx;
  293. /* #endif */
  294. /* #ifdef MP */
  295. position: fixed;
  296. width: 100%;
  297. z-index: 9999;
  298. top: 0;
  299. /* #endif */
  300. }
  301. .searchGood .search .input {
  302. width: 598rpx;
  303. background-color: #f7f7f7;
  304. border-radius: 33rpx;
  305. padding: 0 35rpx;
  306. box-sizing: border-box;
  307. height: 66rpx;
  308. }
  309. .searchGood .search .input input {
  310. width: 472rpx;
  311. font-size: 26rpx;
  312. }
  313. .searchGood .search .input .placeholder {
  314. color: #bbb;
  315. }
  316. .searchGood .search .input .iconfont {
  317. color: #000;
  318. font-size: 35rpx;
  319. }
  320. .searchGood .search .bnt {
  321. width: 120rpx;
  322. text-align: center;
  323. height: 66rpx;
  324. line-height: 66rpx;
  325. font-size: 30rpx;
  326. color: #282828;
  327. }
  328. .searchGood .title {
  329. font-weight: 500;
  330. font-family: PingFang SC, PingFang SC;
  331. font-size: 28rpx;
  332. color: #333;
  333. margin: 50rpx 30rpx 25rpx 30rpx;
  334. }
  335. .searchGood .list {
  336. padding-left: 10rpx;
  337. }
  338. .searchGood .list .item {
  339. font-size: 26rpx;
  340. color: #454545;
  341. padding: 0 21rpx;
  342. height: 60rpx;
  343. border-radius: 30rpx;
  344. line-height: 60rpx;
  345. border: 1rpx solid #aaa;
  346. margin: 0 0 20rpx 20rpx;
  347. }
  348. .searchGood .line {
  349. margin: 20rpx 30rpx 0 30rpx;
  350. }
  351. .searchBox {
  352. width: 100%;
  353. }
  354. .search-box {
  355. background-color: #fff;
  356. padding: 0 39rpx;
  357. margin-top: 10rpx;
  358. box-sizing: border-box;
  359. height: 96rpx;
  360. .flex-y-center {
  361. width: 100%;
  362. height: 69rpx;
  363. padding-left: 29rpx;
  364. border-radius: 35rpx;
  365. border: 2rpx solid #FF6702;
  366. }
  367. .bnt {
  368. background: #FF6702;
  369. border-radius: 35rpx;
  370. width: 115rpx;
  371. height: 100%;
  372. font-weight: 500;
  373. font-size: 35rpx;
  374. color: #FFFFFF;
  375. }
  376. }
  377. .icon-fanhui2 {
  378. // line-height: 66rpx;
  379. }
  380. .search-box input {
  381. width: 90%;
  382. font-size: 26rpx;
  383. }
  384. .search-box .placeholder {
  385. color: #bbb;
  386. }
  387. .search-box .iconfont {
  388. color: #000;
  389. font-size: 35rpx;
  390. }
  391. .tab-list {
  392. display: flex;
  393. /* 启用弹性布局 */
  394. flex-direction: row;
  395. /* 横向排列 */
  396. justify-content: space-between;
  397. /* 均匀分布子项 */
  398. flex-wrap: wrap;
  399. /* 允许换行(适用于屏幕宽度不足时) */
  400. .tab-item2 {
  401. width: 23%;
  402. /* 5个元素平分宽度,留2%作为间隙 */
  403. text-align: center;
  404. background-color: #FFC127;
  405. border-radius: 8rpx;
  406. font-size: 23rpx;
  407. padding: 6rpx;
  408. font-weight: 400;
  409. }
  410. .tab-item2-false {
  411. width: 23%;
  412. /* 5个元素平分宽度,留2%作为间隙 */
  413. text-align: center;
  414. background-color: #fff;
  415. border-radius: 8rpx;
  416. font-size: 23rpx;
  417. padding: 6rpx;
  418. font-weight: 400;
  419. }
  420. }
  421. .content-goods2 {
  422. background: #FFFFFF;
  423. border-radius: 23rpx;
  424. margin-top: 10rpx;
  425. padding: 20rpx;
  426. display: flex;
  427. }
  428. .goods-title {
  429. color: #141414;
  430. font-size: 26rpx;
  431. font-weight: 600;
  432. }
  433. .goods-desc {
  434. color: #646464;
  435. font-size: 21rpx;
  436. margin-top: 10rpx;
  437. }
  438. .goods-price {
  439. color: #FF9805;
  440. font-size: 34rpx;
  441. font-weight: 600;
  442. }
  443. .goods-score {
  444. color: $bg-color-primary;
  445. font-size: 27rpx;
  446. }
  447. .goods-info {
  448. color: #999999;
  449. font-size: 21rpx;
  450. }
  451. .goods-info3 {
  452. color: #999999;
  453. font-size: 21rpx;
  454. margin-left: 10rpx;
  455. text-decoration: line-through;
  456. }
  457. .goods-sales {
  458. background-color: #FEEFE5;
  459. color: #FF6702;
  460. border-radius: 8rpx;
  461. font-size: 21rpx;
  462. padding: 4rpx 20rpx;
  463. }
  464. .goods-labels {
  465. background-color: #FFF6F6;
  466. color: #FF4B4B;
  467. border: 2rpx solid #FF4B4B;
  468. border-radius: 8rpx;
  469. font-size: 21rpx;
  470. padding: 4rpx 16rpx;
  471. margin-right: 20rpx;
  472. }
  473. .active-option {
  474. color: $bg-color-primary !important;
  475. }
  476. </style>