index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  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 @click="getDetils(item)" 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. // 跳转商品详情
  247. getDetils(item){
  248. console.log(item)
  249. uni.navigateTo({
  250. url:`/pages/goods/goods_details/index?id=${item.productId}&mt=0&iSshop=1`
  251. })
  252. },
  253. getAddressInfo(latitude, longitude) {
  254. let that = this;
  255. const qqmapsdk = new QQMapWX({
  256. key: '7FJBZ-ACWCN-EFWFQ-SBXR5-QXC7K-LPF2U'
  257. });
  258. qqmapsdk.reverseGeocoder({
  259. location: {
  260. latitude: latitude,
  261. longitude: longitude
  262. },
  263. success: (res2) => {
  264. const address = res2.result.address; // 完整地址(如北京市海淀区中关村)
  265. const province = res2.result.ad_info.province; // 省份
  266. const city = res2.result.ad_info.city; // 城市
  267. const recommend = res2.result.formatted_addresses.recommend; // 推荐使用的地址描述,描述精确性较高
  268. console.log('地址信息1:', res2);
  269. that.userAddress = recommend.length <= 8 ? recommend : recommend.slice(0, 8);
  270. getMerchantList({
  271. latitude: latitude,
  272. longitude: longitude
  273. }).then(res => {
  274. that.merchantList = res.data.list;
  275. console.log('商品信息:', that.merchantList);
  276. });
  277. },
  278. fail: (err) => {
  279. console.error('逆地理编码失败:', err);
  280. }
  281. });
  282. },
  283. getHomeData() {
  284. getHomeInfo().then(res => {
  285. this.bannerList = res.data.banner;
  286. this.proList = res.data.proList;
  287. this.messageList = res.data.headline;
  288. // this.messageList = [{"id":2,"title":"绿草地活动大促,消费满三十减十五"},{"id":3,"title":"绿草地活动大促,消费满三十减十五33333"}];
  289. console.log("this.messageList--", this.messageList)
  290. this.startScroll();
  291. })
  292. },
  293. item2Click(item) {
  294. item.checked = !item.checked;
  295. },
  296. startScroll() {
  297. setInterval(() => {
  298. this.currentIndex = (this.currentIndex + 1) % this.messageList.length;
  299. this.offset = -this.currentIndex * 20; // 20px 是单行高度
  300. }, 2000); // 2秒切换一次
  301. },
  302. goSearch() {
  303. this.$util.navigateTo('/pages/goods/goods_search/index');
  304. },
  305. //配送时间转换
  306. convertMinutes(minutes) {
  307. const mins = Number(minutes);
  308. if (isNaN(mins)) return '无效输入';
  309. if (mins > 60) {
  310. const hours = Math.floor(mins / 60);
  311. const remaining = mins % 60;
  312. let result = [];
  313. if (hours > 0) result.push(`${hours}小时`);
  314. if (remaining > 0) result.push(`${remaining}分钟`);
  315. return result.join('') || '0分钟';
  316. } else {
  317. return `${mins}分钟`;
  318. }
  319. },
  320. merchantTab(item) {
  321. let opitem=JSON.stringify(item)
  322. let cid=item.cid
  323. uni.setStorageSync('merId', JSON.parse(JSON.stringify(item.id)))
  324. // 修改跳转
  325. uni.navigateTo({
  326. // url: '/pages/merchant/home/index'
  327. url: `/pages/goods_cate/index?id=${item.id}`
  328. })
  329. }
  330. },
  331. }
  332. </script>
  333. <style>
  334. page {
  335. height: auto;
  336. display: flex;
  337. flex-direction: column;
  338. height: 100%;
  339. /* #ifdef H5 */
  340. background-color: #fff;
  341. /* #endif */
  342. }
  343. </style>
  344. <style lang="scss" scoped>
  345. .navigationbar {
  346. display: flex;
  347. background-color: #FF6702;
  348. color: #fff;
  349. align-items: center;
  350. position: fixed;
  351. z-index: 100;
  352. width: 100%;
  353. }
  354. .navigationbar image {
  355. width: 35rpx;
  356. height: 35rpx;
  357. vertical-align: middle;
  358. }
  359. .bar-left {
  360. flex: 1;
  361. margin-left: 40rpx;
  362. }
  363. .bar-position {
  364. margin-left: 16rpx;
  365. font-size: 22rpx;
  366. overflow: hidden;
  367. /*超出部分隐藏*/
  368. white-space: nowrap;
  369. /*禁止换行*/
  370. text-overflow: ellipsis;
  371. /*省略号*/
  372. }
  373. .bar-center {
  374. flex: 1;
  375. font-size: 36rpx;
  376. }
  377. .swiper-item {
  378. flex-direction: column;
  379. justify-content: center;
  380. align-items: center;
  381. background-color: #999;
  382. color: #fff;
  383. text-align: center;
  384. width: 712rpx;
  385. height: 230rpx;
  386. border-radius: 10rpx;
  387. margin: 0 auto;
  388. }
  389. .banner-img {
  390. width: 712rpx;
  391. height: 230rpx;
  392. border-radius: 10rpx;
  393. }
  394. .content {
  395. margin: 0 20rpx;
  396. }
  397. .content-message {
  398. background-color: #fff;
  399. margin-top: 10rpx;
  400. padding: 10rpx;
  401. }
  402. .content-message image {
  403. width: 38rpx;
  404. height: 38rpx;
  405. vertical-align: middle;
  406. }
  407. .content-message text {
  408. font-size: 23rpx;
  409. color: #646464;
  410. margin-left: 16rpx;
  411. }
  412. .content-tab {
  413. background: linear-gradient(225deg, #ECF3FE 0%, #FEFEFE 100%);
  414. border-radius: 23rpx;
  415. padding: 20rpx;
  416. }
  417. .tab-list {
  418. display: flex;
  419. /* 启用弹性布局 */
  420. flex-direction: row;
  421. /* 横向排列 */
  422. justify-content: space-between;
  423. /* 均匀分布子项 */
  424. flex-wrap: wrap;
  425. /* 允许换行(适用于屏幕宽度不足时) */
  426. }
  427. .tab-item {
  428. width: 19%;
  429. /* 5个元素平分宽度,留1%作为间隙 */
  430. margin-bottom: 20rpx;
  431. /* 底部间距 */
  432. text-align: center;
  433. /* 内容居中 */
  434. color: #141414;
  435. font-size: 24rpx;
  436. }
  437. .tab-image {
  438. width: 100%;
  439. /* 宽度占满父容器 */
  440. height: 80rpx;
  441. /* 固定图片高度 */
  442. border-radius: 10rpx;
  443. /* 圆角效果 */
  444. background-color: #f5f5f5;
  445. /* 占位背景色 */
  446. }
  447. .tab-text {
  448. display: block;
  449. font-size: 27rpx;
  450. font-weight: 500;
  451. color: #141414;
  452. margin-top: 10rpx;
  453. }
  454. .tab-text2 {
  455. display: block;
  456. font-size: 23rpx;
  457. font-weight: 400;
  458. color: #141414;
  459. margin-top: 10rpx;
  460. }
  461. .content-goods {
  462. background: #FFFFFF;
  463. border-radius: 23rpx;
  464. padding: 20rpx;
  465. margin-top: 10rpx;
  466. }
  467. .tab-item2 {
  468. width: 23%;
  469. /* 5个元素平分宽度,留2%作为间隙 */
  470. text-align: center;
  471. background-color: #FFC127;
  472. border-radius: 8rpx;
  473. font-size: 23rpx;
  474. padding: 6rpx;
  475. font-weight: 400;
  476. }
  477. .tab-item2-false {
  478. width: 23%;
  479. /* 5个元素平分宽度,留2%作为间隙 */
  480. text-align: center;
  481. background-color: #fff;
  482. border-radius: 8rpx;
  483. font-size: 23rpx;
  484. padding: 6rpx;
  485. font-weight: 400;
  486. }
  487. .content-goods2 {
  488. background: #FFFFFF;
  489. border-radius: 23rpx;
  490. margin-top: 10rpx;
  491. padding: 20rpx;
  492. display: flex;
  493. }
  494. .goods-more {
  495. font-size: 21rpx;
  496. color: #999999;
  497. float: right;
  498. line-height: 44rpx;
  499. }
  500. .goods-list {
  501. flex: 0 0 356rpx;
  502. margin-right: 18rpx;
  503. }
  504. .goods-title {
  505. color: #141414;
  506. font-size: 26rpx;
  507. font-weight: 600;
  508. }
  509. .goods-desc {
  510. color: #646464;
  511. font-size: 21rpx;
  512. margin-top: 10rpx;
  513. }
  514. .goods-price {
  515. color: #FF9805;
  516. font-size: 34rpx;
  517. font-weight: 600;
  518. }
  519. .goods-score {
  520. color: #FD6716;
  521. font-size: 26rpx;
  522. }
  523. .goods-info {
  524. color: #999999;
  525. font-size: 21rpx;
  526. }
  527. .goods-info3 {
  528. color: #999999;
  529. font-size: 21rpx;
  530. margin-left: 10rpx;
  531. text-decoration: line-through;
  532. }
  533. .goods-sales {
  534. background-color: #FEEFE5;
  535. color: #FF6702;
  536. border-radius: 8rpx;
  537. font-size: 21rpx;
  538. padding: 4rpx 20rpx;
  539. }
  540. .goods-labels {
  541. background-color: #FFF6F6;
  542. color: #FF4B4B;
  543. border: 2rpx solid #FF4B4B;
  544. border-radius: 8rpx;
  545. font-size: 21rpx;
  546. padding: 4rpx 16rpx;
  547. margin-right: 20rpx;
  548. }
  549. .container {
  550. display: flex;
  551. align-items: center;
  552. padding: 12rpx;
  553. background: #ffffff;
  554. margin: 10rpx 0;
  555. }
  556. .left-image {
  557. width: 38rpx;
  558. height: 38rpx;
  559. margin-left: 20rpx;
  560. margin-right: 16rpx;
  561. }
  562. .right-text-container {
  563. flex: 1;
  564. height: 20px;
  565. /* 单行文字高度 */
  566. overflow: hidden;
  567. position: relative;
  568. }
  569. .text-list {
  570. position: absolute;
  571. width: 100%;
  572. transition: transform 0.5s ease;
  573. /* 动画过渡 */
  574. }
  575. .text-item {
  576. height: 40rpx;
  577. line-height: 40rpx;
  578. font-size: 23rpx;
  579. color: #646464;
  580. white-space: nowrap;
  581. overflow: hidden;
  582. text-overflow: ellipsis;
  583. }
  584. .newsTitle {
  585. font-size: 23rpx;
  586. color: #646464;
  587. margin-top: 2rpx;
  588. }
  589. </style>