index.vue 15 KB

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