index.vue 12 KB

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