index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  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)">
  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(item) {
  314. let opitem=JSON.stringify(item)
  315. let cid=item.cid
  316. uni.setStorageSync('merId', JSON.parse(JSON.stringify(item.id)))
  317. // 修改跳转
  318. uni.navigateTo({
  319. // url: '/pages/merchant/home/index'
  320. url: `/pages/goods_cate/index?item=${opitem}`
  321. })
  322. }
  323. },
  324. }
  325. </script>
  326. <style>
  327. page {
  328. height: auto;
  329. display: flex;
  330. flex-direction: column;
  331. height: 100%;
  332. /* #ifdef H5 */
  333. background-color: #fff;
  334. /* #endif */
  335. }
  336. </style>
  337. <style lang="scss" scoped>
  338. .navigationbar {
  339. display: flex;
  340. background-color: #FF6702;
  341. color: #fff;
  342. align-items: center;
  343. position: fixed;
  344. z-index: 100;
  345. width: 100%;
  346. }
  347. .navigationbar image {
  348. width: 35rpx;
  349. height: 35rpx;
  350. vertical-align: middle;
  351. }
  352. .bar-left {
  353. flex: 1;
  354. margin-left: 40rpx;
  355. }
  356. .bar-position {
  357. margin-left: 16rpx;
  358. font-size: 22rpx;
  359. overflow: hidden;
  360. /*超出部分隐藏*/
  361. white-space: nowrap;
  362. /*禁止换行*/
  363. text-overflow: ellipsis;
  364. /*省略号*/
  365. }
  366. .bar-center {
  367. flex: 1;
  368. font-size: 36rpx;
  369. }
  370. .swiper-item {
  371. flex-direction: column;
  372. justify-content: center;
  373. align-items: center;
  374. background-color: #999;
  375. color: #fff;
  376. text-align: center;
  377. width: 712rpx;
  378. height: 230rpx;
  379. border-radius: 10rpx;
  380. margin: 0 auto;
  381. }
  382. .banner-img {
  383. width: 712rpx;
  384. height: 230rpx;
  385. border-radius: 10rpx;
  386. }
  387. .content {
  388. margin: 0 20rpx;
  389. }
  390. .content-message {
  391. background-color: #fff;
  392. margin-top: 10rpx;
  393. padding: 10rpx;
  394. }
  395. .content-message image {
  396. width: 38rpx;
  397. height: 38rpx;
  398. vertical-align: middle;
  399. }
  400. .content-message text {
  401. font-size: 23rpx;
  402. color: #646464;
  403. margin-left: 16rpx;
  404. }
  405. .content-tab {
  406. background: linear-gradient(225deg, #ECF3FE 0%, #FEFEFE 100%);
  407. border-radius: 23rpx;
  408. padding: 20rpx;
  409. }
  410. .tab-list {
  411. display: flex;
  412. /* 启用弹性布局 */
  413. flex-direction: row;
  414. /* 横向排列 */
  415. justify-content: space-between;
  416. /* 均匀分布子项 */
  417. flex-wrap: wrap;
  418. /* 允许换行(适用于屏幕宽度不足时) */
  419. }
  420. .tab-item {
  421. width: 19%;
  422. /* 5个元素平分宽度,留1%作为间隙 */
  423. margin-bottom: 20rpx;
  424. /* 底部间距 */
  425. text-align: center;
  426. /* 内容居中 */
  427. color: #141414;
  428. font-size: 24rpx;
  429. }
  430. .tab-image {
  431. width: 100%;
  432. /* 宽度占满父容器 */
  433. height: 80rpx;
  434. /* 固定图片高度 */
  435. border-radius: 10rpx;
  436. /* 圆角效果 */
  437. background-color: #f5f5f5;
  438. /* 占位背景色 */
  439. }
  440. .tab-text {
  441. display: block;
  442. font-size: 27rpx;
  443. font-weight: 500;
  444. color: #141414;
  445. margin-top: 10rpx;
  446. }
  447. .tab-text2 {
  448. display: block;
  449. font-size: 23rpx;
  450. font-weight: 400;
  451. color: #141414;
  452. margin-top: 10rpx;
  453. }
  454. .content-goods {
  455. background: #FFFFFF;
  456. border-radius: 23rpx;
  457. padding: 20rpx;
  458. margin-top: 10rpx;
  459. }
  460. .tab-item2 {
  461. width: 23%;
  462. /* 5个元素平分宽度,留2%作为间隙 */
  463. text-align: center;
  464. background-color: #FFC127;
  465. border-radius: 8rpx;
  466. font-size: 23rpx;
  467. padding: 6rpx;
  468. font-weight: 400;
  469. }
  470. .tab-item2-false {
  471. width: 23%;
  472. /* 5个元素平分宽度,留2%作为间隙 */
  473. text-align: center;
  474. background-color: #fff;
  475. border-radius: 8rpx;
  476. font-size: 23rpx;
  477. padding: 6rpx;
  478. font-weight: 400;
  479. }
  480. .content-goods2 {
  481. background: #FFFFFF;
  482. border-radius: 23rpx;
  483. margin-top: 10rpx;
  484. padding: 20rpx;
  485. display: flex;
  486. }
  487. .goods-more {
  488. font-size: 21rpx;
  489. color: #999999;
  490. float: right;
  491. line-height: 44rpx;
  492. }
  493. .goods-list {
  494. flex: 0 0 356rpx;
  495. margin-right: 18rpx;
  496. }
  497. .goods-title {
  498. color: #141414;
  499. font-size: 26rpx;
  500. font-weight: 600;
  501. }
  502. .goods-desc {
  503. color: #646464;
  504. font-size: 21rpx;
  505. margin-top: 10rpx;
  506. }
  507. .goods-price {
  508. color: #FF9805;
  509. font-size: 34rpx;
  510. font-weight: 600;
  511. }
  512. .goods-score {
  513. color: #FD6716;
  514. font-size: 26rpx;
  515. }
  516. .goods-info {
  517. color: #999999;
  518. font-size: 21rpx;
  519. }
  520. .goods-info3 {
  521. color: #999999;
  522. font-size: 21rpx;
  523. margin-left: 10rpx;
  524. text-decoration: line-through;
  525. }
  526. .goods-sales {
  527. background-color: #FEEFE5;
  528. color: #FF6702;
  529. border-radius: 8rpx;
  530. font-size: 21rpx;
  531. padding: 4rpx 20rpx;
  532. }
  533. .goods-labels {
  534. background-color: #FFF6F6;
  535. color: #FF4B4B;
  536. border: 2rpx solid #FF4B4B;
  537. border-radius: 8rpx;
  538. font-size: 21rpx;
  539. padding: 4rpx 16rpx;
  540. margin-right: 20rpx;
  541. }
  542. .container {
  543. display: flex;
  544. align-items: center;
  545. padding: 12rpx;
  546. background: #ffffff;
  547. margin: 10rpx 0;
  548. }
  549. .left-image {
  550. width: 38rpx;
  551. height: 38rpx;
  552. margin-left: 20rpx;
  553. margin-right: 16rpx;
  554. }
  555. .right-text-container {
  556. flex: 1;
  557. height: 20px;
  558. /* 单行文字高度 */
  559. overflow: hidden;
  560. position: relative;
  561. }
  562. .text-list {
  563. position: absolute;
  564. width: 100%;
  565. transition: transform 0.5s ease;
  566. /* 动画过渡 */
  567. }
  568. .text-item {
  569. height: 40rpx;
  570. line-height: 40rpx;
  571. font-size: 23rpx;
  572. color: #646464;
  573. white-space: nowrap;
  574. overflow: hidden;
  575. text-overflow: ellipsis;
  576. }
  577. .newsTitle {
  578. font-size: 23rpx;
  579. color: #646464;
  580. margin-top: 2rpx;
  581. }
  582. </style>