index.vue 12 KB

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