index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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.cateId ? that.cateId = e.cateId : ''
  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. this.merchantList.push(res.data.list[0])
  157. this.merchantList.push(res.data.list[0])
  158. this.merchantList.push(res.data.list[0])
  159. this.merchantList.push(res.data.list[0])
  160. this.merchantList.push(res.data.list[0])
  161. this.merchantList.push(res.data.list[0])
  162. this.merchantList.push(res.data.list[0])
  163. this.merchantList.push(res.data.list[0])
  164. console.log('商品信息:', this.merchantList);
  165. });
  166. },
  167. getRoutineHotSearch: function() {
  168. let that = this;
  169. getSearchKeyword().then(res => {
  170. that.$set(that, 'hotSearchList', res.data);
  171. });
  172. },
  173. setHotSearchValue: function(event) {
  174. this.$set(this, 'searchValue', event);
  175. this.page = 1;
  176. this.$set(this, 'bastList', []);
  177. this.getMatchedData()
  178. // uni.navigateTo({
  179. // url: `/pages/goods/goods_list/index?searchValue=${this.searchValue}`
  180. // })
  181. },
  182. setValue: function(event) {
  183. this.$set(this, 'searchValue', event.detail.value);
  184. },
  185. searchBut: function(e) {
  186. let that = this;
  187. let val = '';
  188. that.focus = false;
  189. if (e.detail.value) {
  190. val = e.detail.value
  191. }
  192. if (that.searchValue.length > 0 || val) {
  193. this.getMatchedData()
  194. // uni.navigateTo({
  195. // url: `/pages/goods/goods_list/index?searchValue=${val?val:that.searchValue}`
  196. // })
  197. } else {
  198. return this.$util.Tips({
  199. title: '请输入要搜索的商品',
  200. icon: 'none',
  201. duration: 1000,
  202. mask: true,
  203. });
  204. }
  205. }
  206. }
  207. }
  208. </script>
  209. <style lang="scss" scoped>
  210. .container {
  211. overflow: hidden;
  212. position: relative;
  213. }
  214. page {
  215. background-color: #f5f5f5 !important;
  216. }
  217. .searchGood .search {
  218. padding-left: 30rpx;
  219. background-color: #fff !important;
  220. }
  221. .searchGood .search {
  222. /* #ifndef MP */
  223. padding-top: 20rpx;
  224. padding-bottom: 20rpx;
  225. /* #endif */
  226. /* #ifdef MP */
  227. position: fixed;
  228. width: 100%;
  229. z-index: 9999;
  230. top: 0;
  231. /* #endif */
  232. }
  233. .searchGood .search .input {
  234. width: 598rpx;
  235. background-color: #f7f7f7;
  236. border-radius: 33rpx;
  237. padding: 0 35rpx;
  238. box-sizing: border-box;
  239. height: 66rpx;
  240. }
  241. .searchGood .search .input input {
  242. width: 472rpx;
  243. font-size: 26rpx;
  244. }
  245. .searchGood .search .input .placeholder {
  246. color: #bbb;
  247. }
  248. .searchGood .search .input .iconfont {
  249. color: #000;
  250. font-size: 35rpx;
  251. }
  252. .searchGood .search .bnt {
  253. width: 120rpx;
  254. text-align: center;
  255. height: 66rpx;
  256. line-height: 66rpx;
  257. font-size: 30rpx;
  258. color: #282828;
  259. }
  260. .searchGood .title {
  261. font-weight: 500;
  262. font-family: PingFang SC, PingFang SC;
  263. font-size: 28rpx;
  264. color: #333;
  265. margin: 50rpx 30rpx 25rpx 30rpx;
  266. }
  267. .searchGood .list {
  268. padding-left: 10rpx;
  269. }
  270. .searchGood .list .item {
  271. font-size: 26rpx;
  272. color: #454545;
  273. padding: 0 21rpx;
  274. height: 60rpx;
  275. border-radius: 30rpx;
  276. line-height: 60rpx;
  277. border: 1rpx solid #aaa;
  278. margin: 0 0 20rpx 20rpx;
  279. }
  280. .searchGood .line {
  281. margin: 20rpx 30rpx 0 30rpx;
  282. }
  283. .searchBox {
  284. width: 100%;
  285. }
  286. .search-box {
  287. background-color: #fff;
  288. padding: 0 39rpx;
  289. margin-top: 10rpx;
  290. box-sizing: border-box;
  291. height: 96rpx;
  292. .flex-y-center {
  293. width: 100%;
  294. height: 69rpx;
  295. padding-left: 29rpx;
  296. border-radius: 35rpx;
  297. border: 2rpx solid #FF6702;
  298. }
  299. .bnt {
  300. background: #FF6702;
  301. border-radius: 35rpx;
  302. width: 115rpx;
  303. height: 100%;
  304. font-weight: 500;
  305. font-size: 35rpx;
  306. color: #FFFFFF;
  307. }
  308. }
  309. .icon-fanhui2 {
  310. // line-height: 66rpx;
  311. }
  312. .search-box input {
  313. width: 90%;
  314. font-size: 26rpx;
  315. }
  316. .search-box .placeholder {
  317. color: #bbb;
  318. }
  319. .search-box .iconfont {
  320. color: #000;
  321. font-size: 35rpx;
  322. }
  323. .tab-list {
  324. display: flex;
  325. /* 启用弹性布局 */
  326. flex-direction: row;
  327. /* 横向排列 */
  328. justify-content: space-between;
  329. /* 均匀分布子项 */
  330. flex-wrap: wrap;
  331. /* 允许换行(适用于屏幕宽度不足时) */
  332. .tab-item2 {
  333. width: 23%;
  334. /* 5个元素平分宽度,留2%作为间隙 */
  335. text-align: center;
  336. background-color: #FFC127;
  337. border-radius: 8rpx;
  338. font-size: 23rpx;
  339. padding: 6rpx;
  340. font-weight: 400;
  341. }
  342. .tab-item2-false {
  343. width: 23%;
  344. /* 5个元素平分宽度,留2%作为间隙 */
  345. text-align: center;
  346. background-color: #fff;
  347. border-radius: 8rpx;
  348. font-size: 23rpx;
  349. padding: 6rpx;
  350. font-weight: 400;
  351. }
  352. }
  353. .content-goods2 {
  354. background: #FFFFFF;
  355. border-radius: 23rpx;
  356. margin-top: 10rpx;
  357. padding: 20rpx;
  358. display: flex;
  359. }
  360. .goods-title {
  361. color: #141414;
  362. font-size: 26rpx;
  363. font-weight: 600;
  364. }
  365. .goods-desc {
  366. color: #646464;
  367. font-size: 21rpx;
  368. margin-top: 10rpx;
  369. }
  370. .goods-price {
  371. color: #FF9805;
  372. font-size: 34rpx;
  373. font-weight: 600;
  374. }
  375. .goods-score {
  376. color: $bg-color-primary;
  377. font-size: 27rpx;
  378. }
  379. .goods-info {
  380. color: #999999;
  381. font-size: 21rpx;
  382. }
  383. .goods-info3 {
  384. color: #999999;
  385. font-size: 21rpx;
  386. margin-left: 10rpx;
  387. text-decoration: line-through;
  388. }
  389. .goods-sales {
  390. background-color: #FEEFE5;
  391. color: #FF6702;
  392. border-radius: 8rpx;
  393. font-size: 21rpx;
  394. padding: 4rpx 20rpx;
  395. }
  396. .goods-labels {
  397. background-color: #FFF6F6;
  398. color: #FF4B4B;
  399. border: 2rpx solid #FF4B4B;
  400. border-radius: 8rpx;
  401. font-size: 21rpx;
  402. padding: 4rpx 16rpx;
  403. margin-right: 20rpx;
  404. }
  405. </style>