index.vue 11 KB

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