index.vue 17 KB

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