index.vue 15 KB

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