index.vue 11 KB

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