index.vue 14 KB

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