index.vue 16 KB

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