index.vue 17 KB

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