index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. <template>
  2. <view style="overflow-y: scroll;">
  3. <!-- 状态栏高度 -->
  4. <view :style="{ height: `${statusBarHeight}px` }"></view>
  5. <!-- 导航栏 -->
  6. <view class="navigationbar" :style="{ height: `${navigationBarHeight}px` }">
  7. <view class="bar-left flex-y-center">
  8. <image src="/static/img/ic-position.png" @tap="chooseLocation()">
  9. </image>
  10. <text class="bar-position">{{userAddress}}</text>
  11. </view>
  12. <view class="bar-center">校园外卖</view>
  13. <view style="flex: 1;">
  14. <image @click="goSearch" src="/static/img/ic-search.png"></image>
  15. </view>
  16. </view>
  17. <!-- 主体内容 -->
  18. <view class="content" :style="{ marginTop: `${navigationBarHeight + 5 }px` }">
  19. <!-- banner轮播图 -->
  20. <view style="margin-top: 10rpx;">
  21. <swiper :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval" :duration="duration" circular="true">
  22. <block v-for="(item,index) in bannerList" :key='item.id'>
  23. <swiper-item catchtouchmove='catchTouchMove'>
  24. <view class="swiper-item">
  25. <image class="banner-img" :src="item.pic" mode="widthFix" />
  26. </view>
  27. </swiper-item>
  28. </block>
  29. </swiper>
  30. </view>
  31. <!-- 新闻 -->
  32. <view class="container">
  33. <!-- 左侧固定图片 -->
  34. <image class="left-image" src="/static/img/ic-message.png"></image>
  35. <!-- 右侧文字轮播区域 -->
  36. <view class="right-text-container">
  37. <swiper :indicator-dots="false" :autoplay="autoplay" interval="2500" :duration="500" vertical="true" circular="true">
  38. <block v-for="(item,index) in messageList" :key='index'>
  39. <swiper-item catchtouchmove='catchTouchMove'>
  40. <view class='text acea-row row-between-wrapper'>
  41. <view class='newsTitle'>
  42. {{item.title}}
  43. </view>
  44. <!-- <view class='newsTitle' v-if="messageList.length = 0">
  45. 暂无
  46. </view> -->
  47. </view>
  48. </swiper-item>
  49. </block>
  50. </swiper>
  51. <!-- <view class="text-list" :style="{ transform: `translateY(${offset}px)` }">
  52. <view class="text-item" v-for="(item, index) in messageList" :key="index">
  53. {{ item.title }}
  54. </view>
  55. <view class="text-item" v-if="messageList.length > 0">
  56. {{ messageList[0].title }}
  57. </view>
  58. </view> -->
  59. </view>
  60. </view>
  61. <!-- 九宫格 -->
  62. <view class="content-tab">
  63. <view class="tab-list">
  64. <view class="tab-item flex-col flex-between-center" v-for="(item, index) in cateList" :key="index" @tap="onCateListClick(item)">
  65. <image class="tab-image" :style="{width: !item.isHighLight ? '80rpx' : ''}" :src="item.icon" mode="widthFix"></image>
  66. <text :class="item.isHighLight || item.color ? 'tab-text' : 'tab-text2' " :style="{color: item.color || ''}">{{item.name}}</text>
  67. </view>
  68. </view>
  69. </view>
  70. <!-- 活动精选 -->
  71. <view class="content-goods">
  72. <view>
  73. <image src="/static/img/img-hdjx.png" style="width: 298rpx;height: 44rpx;"></image>
  74. <text class="goods-more" @tap="goSearch">更多 》</text>
  75. </view>
  76. <view style="display: flex;">
  77. <view class="goods-list" v-for="item in proList" :key="item.id">
  78. <view style="display: flex;" @click="goGoodList(item)">
  79. <view style="margin-right: 20rpx;">
  80. <image :src="item.image" style="width: 134rpx;height: 134rpx;border-radius: 12rpx;">
  81. </image>
  82. </view>
  83. <view>
  84. <view class="goods-title">{{item.name}}</view>
  85. <view class="goods-desc">{{item.intro}}</view>
  86. <view class="flex-y-center" style="margin-top: 10rpx;">
  87. <image src="/static/img/ic-ykj.png" style="height: 38rpx;width: 86rpx;"></image>
  88. <text class="goods-price">¥</text>
  89. <text class="goods-price" style="font-size: 30rpx;">{{item.price}}</text>
  90. </view>
  91. </view>
  92. </view>
  93. </view>
  94. </view>
  95. </view>
  96. <!-- 销量排行 -->
  97. <view class="tab-list" style="margin-top: 10rpx;">
  98. <view :class=" item.checked ? 'tab-item2' : 'tab-item2-false' " v-for="item in labelList" :key="item.id" @click="item2Click(item)">{{item.label}}</view>
  99. </view>
  100. <view class="content-goods2" v-for="item in merchantList" :key="item.id" @click="merchantTab(item)">
  101. <view>
  102. <image :src="item.avatar" style="width: 230rpx;height: 230rpx;"></image>
  103. </view>
  104. <view style="margin-left: 20rpx;flex: 1;">
  105. <view class="">
  106. <text class="goods-title">{{item.name}}</text>
  107. </view>
  108. <view style="margin-top: 10rpx;">
  109. <text class="goods-score">{{item.score}}</text>
  110. <text class="goods-info" style="margin-left: 10rpx;">月销 {{item.salesVolume}}</text>
  111. <text class="goods-info" style="margin-left: 25rpx;">人均 ¥ {{item.perCapita}}</text>
  112. </view>
  113. <view style="margin-top: 10rpx;display: flex;align-items: center;">
  114. <text class="goods-info">起送 ¥ {{item.perCapita}}</text>
  115. <text v-if="!item.isfreeDeliverfee" class="goods-info" style="color: #E5AD21;margin-left: 18rpx;">免配送费</text>
  116. <view v-if="!item.isfreeDeliverfee && item.freeDeliverFee > 0" style="color: #999999;font-size: 21rpx;margin-left: 10rpx;text-decoration: line-through;">¥
  117. {{item.freeDeliverFee}}</view>
  118. <text v-if="item.isfreeDeliverfee" style="color: #999999;font-size: 21rpx;margin-left: 10rpx;">配送费¥
  119. {{item.distCosts}}</text>
  120. <text class="goods-info" style="margin-left: 38rpx;">10分钟</text>
  121. <text class="goods-info" style="margin-left: 10rpx;">{{item.distance}}</text>
  122. </view>
  123. <view style="margin-top: 22rpx;"><text class="goods-sales">已售卖{{item.salesVolume}}件</text></view>
  124. <view style="margin-top: 14rpx;">
  125. <text class="goods-labels" v-for="(item2,index2) in item.discountLabel" :key="index2">{{item2}}</text>
  126. </view>
  127. </view>
  128. </view>
  129. </view>
  130. </view>
  131. </template>
  132. <script>
  133. import QQMapWX from '@/utils/qqmap-wx-jssdk.min.js';
  134. import {
  135. getMerchantList,
  136. getHomeInfo
  137. } from '@/api/home.js';
  138. var statusBarHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
  139. let app = getApp();
  140. export default {
  141. data() {
  142. return {
  143. statusBarHeight: app.globalData.statusBarHeight,
  144. navigationBarHeight: 0,
  145. userAddress: "定位",
  146. indicatorDots: true,
  147. autoplay: true,
  148. interval: 2000, //切换的间隔时间
  149. duration: 500, //滑动动画时长
  150. bannerList: [],
  151. messageList: [],
  152. cateList: [],
  153. proList: [],
  154. labelList: [{
  155. id: 1,
  156. label: "销量排行",
  157. checked: true
  158. }, {
  159. id: 2,
  160. label: "满减大促",
  161. checked: false
  162. }, {
  163. id: 3,
  164. label: "首单立减",
  165. checked: false
  166. }, {
  167. id: 4,
  168. label: "减配送费",
  169. checked: false
  170. }],
  171. merchantList: [],
  172. currentIndex: 0,
  173. offset: 0,
  174. }
  175. },
  176. //下拉刷新
  177. onPullDownRefresh() {
  178. },
  179. onLoad(options) {
  180. let that = this;
  181. //首页数据加载
  182. // this.getIndexConfig();
  183. // #ifdef MP-WEIXIN
  184. // 获取微信胶囊的位置信息 width,height,top,right,left,bottom
  185. const custom = wx.getMenuButtonBoundingClientRect()
  186. // 导航栏高度(标题栏高度) = 胶囊高度 + (顶部距离 - 状态栏高度) * 2
  187. that.navigationBarHeight = custom.height + (custom.top - that.statusBarHeight) * 2
  188. // console.log("导航栏高度:"+this.globalData.navigationBarHeight)
  189. // #endif
  190. that.initLocation();
  191. },
  192. methods: {
  193. initLocation() {
  194. let that = this;
  195. this.$util.$L.getLocation().then(res => {
  196. const qqmapsdk = new QQMapWX({
  197. key: '7FJBZ-ACWCN-EFWFQ-SBXR5-QXC7K-LPF2U'
  198. //key: '7FJBZ-ACWCN-EFWFQ-SBXR5-QXC7K-LPF2U'
  199. });
  200. qqmapsdk.reverseGeocoder({
  201. location: {
  202. latitude: uni.getStorageSync('user_latitude'),
  203. longitude: uni.getStorageSync('user_longitude'),
  204. },
  205. success: (res2) => {
  206. const address = res2.result.address; // 完整地址(如北京市海淀区中关村)
  207. const province = res2.result.ad_info.province; // 省份
  208. const city = res2.result.ad_info.city; // 城市
  209. const recommend = res2.result.address_reference.landmark_l2.title;; // 推荐使用的地址描述,描述精确性较高
  210. console.log('地址信息1:', res2);
  211. that.userAddress = recommend;
  212. that.getHomeData();
  213. },
  214. fail: (err) => {
  215. console.error('逆地理编码失败:', err);
  216. }
  217. });
  218. })
  219. },
  220. getHomeData() {
  221. getHomeInfo({
  222. latitude: uni.getStorageSync('user_latitude'),
  223. longitude: uni.getStorageSync('user_longitude'),
  224. }).then(res => {
  225. this.bannerList = res.data.banner;
  226. this.proList = res.data.proList;
  227. console.log(this.proList)
  228. this.messageList = res.data.headline;
  229. this.cateList = res.data.cateList;
  230. this.cateList.push({
  231. id: 999,
  232. name: '今日吃啥',
  233. icon: '/static/img/ic-random.png',
  234. color: '#FF9805'
  235. });
  236. getMerchantList({
  237. latitude: uni.getStorageSync('user_latitude'),
  238. longitude: uni.getStorageSync('user_longitude'),
  239. cateId: this.cateList[0].id
  240. }).then(res => {
  241. this.merchantList = res.data.list;
  242. console.log('商品信息:', this.merchantList);
  243. });
  244. // this.messageList = [{"id":2,"title":"绿草地活动大促,消费满三十减十五"},{"id":3,"title":"绿草地活动大促,消费满三十减十五33333"}];
  245. console.log("this.messageList--", this.messageList)
  246. // this.startScroll();
  247. })
  248. },
  249. item2Click(item) {
  250. item.checked = !item.checked;
  251. },
  252. startScroll() {
  253. setInterval(() => {
  254. this.currentIndex = (this.currentIndex + 1) % this.messageList.length;
  255. this.offset = -this.currentIndex * 20; // 20px 是单行高度
  256. }, 2000); // 2秒切换一次
  257. },
  258. goSearch() {
  259. this.$util.navigateTo('/pages/goods/goods_search/index');
  260. },
  261. //配送时间转换
  262. convertMinutes(minutes) {
  263. const mins = Number(minutes);
  264. if (isNaN(mins)) return '无效输入';
  265. if (mins > 60) {
  266. const hours = Math.floor(mins / 60);
  267. const remaining = mins % 60;
  268. let result = [];
  269. if (hours > 0) result.push(`${hours}小时`);
  270. if (remaining > 0) result.push(`${remaining}分钟`);
  271. return result.join('') || '0分钟';
  272. } else {
  273. return `${mins}分钟`;
  274. }
  275. },
  276. merchantTab(item) {
  277. let opitem = JSON.stringify(item)
  278. let cid = item.cid
  279. uni.setStorageSync('merId', JSON.parse(JSON.stringify(item.id)))
  280. // 修改跳转
  281. uni.navigateTo({
  282. url: '/pages/merchant/home/index'
  283. // url: `/pages/goods_cate/index?id=${item.id}`
  284. })
  285. },
  286. onCateListClick(item) {
  287. if (item.link) {
  288. uni.navigateTo({
  289. url: item.link + `?id=${item.id}&navTitle=${item.name}`
  290. })
  291. }
  292. },
  293. goGoodList(item) {
  294. uni.navigateTo({
  295. url: `/pages/goods/goods_details/index?id=${item.productId}&mt=0&iSshop=1`
  296. })
  297. },
  298. //选择定位
  299. chooseLocation: function() {
  300. this.$util.$L.getLocation().then(res => {
  301. uni.chooseLocation({
  302. latitude: uni.getStorageSync('user_latitude'),
  303. longitude: uni.getStorageSync('user_longitude'),
  304. success: (res) => {
  305. this.userAddress = res.name;
  306. getMerchantList({
  307. latitude: res.latitude,
  308. longitude: res.longitude
  309. }).then(data => {
  310. this.merchantList = data.data.list;
  311. console.log('商品信息:', this.merchantList);
  312. });
  313. // this.$set(this.userAddress, 'detail', res.name);
  314. }
  315. })
  316. })
  317. },
  318. },
  319. }
  320. </script>
  321. <style>
  322. page {
  323. height: auto;
  324. display: flex;
  325. flex-direction: column;
  326. height: 100%;
  327. /* #ifdef H5 */
  328. background-color: #fff;
  329. /* #endif */
  330. }
  331. </style>
  332. <style lang="scss" scoped>
  333. .navigationbar {
  334. display: flex;
  335. background-color: #FF6702;
  336. color: #fff;
  337. align-items: center;
  338. position: fixed;
  339. z-index: 100;
  340. width: 100%;
  341. }
  342. .navigationbar image {
  343. width: 35rpx;
  344. height: 35rpx;
  345. vertical-align: middle;
  346. }
  347. .bar-left {
  348. flex: 1;
  349. margin-left: 40rpx;
  350. }
  351. .bar-position {
  352. margin-left: 16rpx;
  353. font-size: 22rpx;
  354. overflow: hidden;
  355. /*超出部分隐藏*/
  356. white-space: nowrap;
  357. /*禁止换行*/
  358. text-overflow: ellipsis;
  359. /*省略号*/
  360. }
  361. .bar-center {
  362. flex: 1;
  363. font-size: 36rpx;
  364. }
  365. .swiper-item {
  366. flex-direction: column;
  367. justify-content: center;
  368. align-items: center;
  369. background-color: #999;
  370. color: #fff;
  371. text-align: center;
  372. width: 712rpx;
  373. height: 230rpx;
  374. border-radius: 10rpx;
  375. margin: 0 auto;
  376. }
  377. .banner-img {
  378. width: 712rpx;
  379. height: 230rpx;
  380. border-radius: 10rpx;
  381. }
  382. .content {
  383. margin: 0 20rpx;
  384. }
  385. .content-message {
  386. background-color: #fff;
  387. margin-top: 10rpx;
  388. padding: 10rpx;
  389. }
  390. .content-message image {
  391. width: 38rpx;
  392. height: 38rpx;
  393. vertical-align: middle;
  394. }
  395. .content-message text {
  396. font-size: 23rpx;
  397. color: #646464;
  398. margin-left: 16rpx;
  399. }
  400. .content-tab {
  401. background: linear-gradient(225deg, #ECF3FE 0%, #FEFEFE 100%);
  402. border-radius: 23rpx;
  403. padding: 20rpx;
  404. }
  405. .tab-list {
  406. display: flex;
  407. /* 启用弹性布局 */
  408. flex-direction: row;
  409. /* 横向排列 */
  410. justify-content: space-between;
  411. /* 均匀分布子项 */
  412. flex-wrap: wrap;
  413. /* 允许换行(适用于屏幕宽度不足时) */
  414. }
  415. .tab-item {
  416. width: 18%;
  417. /* 5个元素平分宽度,留1%作为间隙 */
  418. margin-bottom: 20rpx;
  419. /* 底部间距 */
  420. text-align: center;
  421. /* 内容居中 */
  422. color: #141414;
  423. font-size: 24rpx;
  424. }
  425. .tab-image {
  426. width: 100%;
  427. /* 宽度占满父容器 */
  428. height: 80rpx;
  429. /* 固定图片高度 */
  430. border-radius: 10rpx;
  431. /* 圆角效果 */
  432. background-color: #f5f5f5;
  433. /* 占位背景色 */
  434. }
  435. .tab-text {
  436. display: block;
  437. font-size: 27rpx;
  438. font-weight: 600;
  439. color: #141414;
  440. margin-top: 10rpx;
  441. }
  442. .tab-text2 {
  443. display: block;
  444. font-size: 23rpx;
  445. font-weight: 400;
  446. color: #141414;
  447. margin-top: 10rpx;
  448. }
  449. .content-goods {
  450. background: #FFFFFF;
  451. border-radius: 23rpx;
  452. padding: 20rpx;
  453. margin-top: 10rpx;
  454. }
  455. .tab-item2 {
  456. width: 23%;
  457. /* 5个元素平分宽度,留2%作为间隙 */
  458. text-align: center;
  459. background-color: #FFC127;
  460. border-radius: 8rpx;
  461. font-size: 23rpx;
  462. padding: 6rpx;
  463. font-weight: 400;
  464. }
  465. .tab-item2-false {
  466. width: 23%;
  467. /* 5个元素平分宽度,留2%作为间隙 */
  468. text-align: center;
  469. background-color: #fff;
  470. border-radius: 8rpx;
  471. font-size: 23rpx;
  472. padding: 6rpx;
  473. font-weight: 400;
  474. }
  475. .content-goods2 {
  476. background: #FFFFFF;
  477. border-radius: 23rpx;
  478. margin-top: 10rpx;
  479. padding: 20rpx;
  480. display: flex;
  481. }
  482. .goods-more {
  483. font-size: 21rpx;
  484. color: #999999;
  485. float: right;
  486. line-height: 44rpx;
  487. }
  488. .goods-list {
  489. flex: 1;
  490. margin-right: 18rpx;
  491. }
  492. .goods-title {
  493. color: #141414;
  494. font-size: 26rpx;
  495. font-weight: 600;
  496. }
  497. .goods-desc {
  498. color: #646464;
  499. font-size: 21rpx;
  500. margin-top: 10rpx;
  501. }
  502. .goods-price {
  503. color: #FF9805;
  504. font-size: 34rpx;
  505. font-weight: 600;
  506. }
  507. .goods-score {
  508. color: #FD6716;
  509. font-size: 26rpx;
  510. }
  511. .goods-info {
  512. color: #999999;
  513. font-size: 21rpx;
  514. }
  515. .goods-info3 {
  516. color: #999999;
  517. font-size: 21rpx;
  518. margin-left: 10rpx;
  519. text-decoration: line-through;
  520. }
  521. .goods-sales {
  522. background-color: #FEEFE5;
  523. color: #FF6702;
  524. border-radius: 8rpx;
  525. font-size: 21rpx;
  526. padding: 4rpx 20rpx;
  527. }
  528. .goods-labels {
  529. background-color: #FFF6F6;
  530. color: #FF4B4B;
  531. border: 2rpx solid #FF4B4B;
  532. border-radius: 8rpx;
  533. font-size: 21rpx;
  534. padding: 4rpx 16rpx;
  535. margin-right: 20rpx;
  536. }
  537. .container {
  538. display: flex;
  539. align-items: center;
  540. padding: 12rpx;
  541. background: #ffffff;
  542. margin: 10rpx 0;
  543. }
  544. .left-image {
  545. width: 38rpx;
  546. height: 38rpx;
  547. margin-left: 20rpx;
  548. margin-right: 16rpx;
  549. }
  550. .right-text-container {
  551. flex: 1;
  552. height: 20px;
  553. /* 单行文字高度 */
  554. overflow: hidden;
  555. position: relative;
  556. }
  557. .text-list {
  558. position: absolute;
  559. width: 100%;
  560. transition: transform 0.5s ease;
  561. /* 动画过渡 */
  562. }
  563. .text-item {
  564. height: 40rpx;
  565. line-height: 40rpx;
  566. font-size: 23rpx;
  567. color: #646464;
  568. white-space: nowrap;
  569. overflow: hidden;
  570. text-overflow: ellipsis;
  571. }
  572. .newsTitle {
  573. font-size: 23rpx;
  574. color: #646464;
  575. margin-top: 2rpx;
  576. }
  577. </style>