index.vue 16 KB

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