123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674 |
- <template>
- <view style="overflow-y: scroll;">
- <!-- 状态栏高度 -->
- <view :style="{ height: `${statusBarHeight}px` }"></view>
- <!-- 导航栏 -->
- <view class="navigationbar" :style="{ height: `${navigationBarHeight}px` }">
- <view class="bar-left flex-y-center">
- <image src="/static/img/ic-position.png" @tap="chooseLocation()">
- </image>
- <text class="bar-position">{{userAddress}}</text>
- </view>
- <view class="bar-center">校园外卖</view>
- <view style="flex: 1;">
- <image @click="goSearch" src="/static/img/ic-search.png"></image>
- </view>
- </view>
- <!-- 主体内容 -->
- <view class="content" :style="{ marginTop: `${navigationBarHeight + 5 }px` }">
- <!-- banner轮播图 -->
- <view style="margin-top: 10rpx;">
- <swiper :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval" :duration="duration" circular="true">
- <block v-for="(item,index) in bannerList" :key='item.id'>
- <swiper-item catchtouchmove='catchTouchMove'>
- <view class="swiper-item">
- <image class="banner-img" :src="item.pic" mode="widthFix" />
- </view>
- </swiper-item>
- </block>
- </swiper>
- </view>
- <!-- 新闻 -->
- <view class="container">
- <!-- 左侧固定图片 -->
- <image class="left-image" src="/static/img/ic-message.png"></image>
- <!-- 右侧文字轮播区域 -->
- <view class="right-text-container">
- <swiper :indicator-dots="false" :autoplay="autoplay" interval="2500" :duration="500" vertical="true" circular="true">
- <block v-for="(item,index) in messageList" :key='index'>
- <swiper-item catchtouchmove='catchTouchMove'>
- <view class='text acea-row row-between-wrapper'>
- <view class='newsTitle'>
- {{item.title}}
- </view>
- <!-- <view class='newsTitle' v-if="messageList.length = 0">
- 暂无
- </view> -->
- </view>
- </swiper-item>
- </block>
- </swiper>
- <!-- <view class="text-list" :style="{ transform: `translateY(${offset}px)` }">
- <view class="text-item" v-for="(item, index) in messageList" :key="index">
- {{ item.title }}
- </view>
- <view class="text-item" v-if="messageList.length > 0">
- {{ messageList[0].title }}
- </view>
- </view> -->
- </view>
- </view>
- <!-- 九宫格 -->
- <view class="content-tab">
- <view class="tab-list">
- <view class="tab-item flex-col flex-between-center" v-for="(item, index) in cateList" :key="index" @tap="onCateListClick(item)">
- <image class="tab-image" :style="{width: !item.isHighLight ? '80rpx' : ''}" :src="item.icon" mode="widthFix"></image>
- <text :class="item.isHighLight || item.color ? 'tab-text' : 'tab-text2' " :style="{color: item.color || ''}">{{item.name}}</text>
- </view>
- </view>
- </view>
- <!-- 活动精选 -->
- <view class="content-goods">
- <view>
- <image src="/static/img/img-hdjx.png" style="width: 298rpx;height: 44rpx;"></image>
- <text class="goods-more">更多 》</text>
- </view>
- <view style="display: flex;">
- <view class="goods-list" v-for="item in proList" :key="item.id">
- <view style="display: flex;" @click="goGoodList(item)">
- <view style="margin-right: 20rpx;">
- <image :src="item.image" style="width: 134rpx;height: 134rpx;border-radius: 12rpx;">
- </image>
- </view>
- <view>
- <view class="goods-title">{{item.name}}</view>
- <view class="goods-desc">{{item.intro}}</view>
- <view style="margin-top: 10rpx;">
- <image src="/static/img/ic-ykj.png" style="height: 38rpx;width: 86rpx;"></image>
- <text class="goods-price">¥</text>
- <text class="goods-price" style="font-size: 30rpx;">{{item.price}}</text>
- </view>
- </view>
- </view>
- </view>
- </view>
- </view>
- <!-- 销量排行 -->
- <view class="tab-list" style="margin-top: 10rpx;">
- <view :class=" item.checked ? 'tab-item2' : 'tab-item2-false' " v-for="item in labelList" :key="item.id" @click="item2Click(item)">{{item.label}}</view>
- </view>
- <view class="content-goods2" v-for="item in merchantList" :key="item.id" @click="merchantTab(item)">
- <view>
- <image :src="item.avatar" style="width: 230rpx;height: 230rpx;"></image>
- </view>
- <view style="margin-left: 20rpx;flex: 1;">
- <view class="">
- <text class="goods-title">{{item.name}}</text>
- </view>
- <view style="margin-top: 10rpx;">
- <text class="goods-score">{{item.score}}</text>
- <text class="goods-info" style="margin-left: 10rpx;">月销 {{item.salesVolume}}</text>
- <text class="goods-info" style="margin-left: 25rpx;">人均 ¥ {{item.perCapita}}</text>
- </view>
- <view style="margin-top: 10rpx;display: flex;align-items: center;">
- <text class="goods-info">起送 ¥ {{item.perCapita}}</text>
- <text v-if="!item.isfreeDeliverfee" class="goods-info" style="color: #E5AD21;margin-left: 18rpx;">免配送费</text>
- <view v-if="!item.isfreeDeliverfee && item.freeDeliverFee > 0" style="color: #999999;font-size: 21rpx;margin-left: 10rpx;text-decoration: line-through;">¥
- {{item.freeDeliverFee}}</view>
- <text v-if="item.isfreeDeliverfee" style="color: #999999;font-size: 21rpx;margin-left: 10rpx;">配送费¥
- {{item.distCosts}}</text>
- <text class="goods-info" style="margin-left: 38rpx;">10分钟</text>
- <text class="goods-info" style="margin-left: 10rpx;">{{item.distance}}</text>
- </view>
- <view style="margin-top: 22rpx;"><text class="goods-sales">已售卖{{item.salesVolume}}件</text></view>
- <view style="margin-top: 14rpx;">
- <text class="goods-labels" v-for="(item2,index2) in item.discountLabel" :key="index2">{{item2}}</text>
- </view>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- import QQMapWX from '@/utils/qqmap-wx-jssdk.min.js';
- import {
- getMerchantList,
- getHomeInfo
- } from '@/api/home.js';
- var statusBarHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
- let app = getApp();
- export default {
- data() {
- return {
- statusBarHeight: app.globalData.statusBarHeight,
- navigationBarHeight: 0,
- userAddress: "定位",
- indicatorDots: true,
- autoplay: true,
- interval: 2000, //切换的间隔时间
- duration: 500, //滑动动画时长
- bannerList: [],
- messageList: [],
- cateList: [],
- proList: [],
- labelList: [{
- id: 1,
- label: "销量排行",
- checked: true
- }, {
- id: 2,
- label: "满减大促",
- checked: false
- }, {
- id: 3,
- label: "首单立减",
- checked: false
- }, {
- id: 4,
- label: "减配送费",
- checked: false
- }],
- merchantList: [],
- currentIndex: 0,
- offset: 0,
- }
- },
- //下拉刷新
- onPullDownRefresh() {
- },
- onLoad(options) {
- let that = this;
- //首页数据加载
- // this.getIndexConfig();
- // #ifdef MP-WEIXIN
- // 获取微信胶囊的位置信息 width,height,top,right,left,bottom
- const custom = wx.getMenuButtonBoundingClientRect()
- // 导航栏高度(标题栏高度) = 胶囊高度 + (顶部距离 - 状态栏高度) * 2
- this.navigationBarHeight = custom.height + (custom.top - this.statusBarHeight) * 2
- // console.log("导航栏高度:"+this.globalData.navigationBarHeight)
- // #endif
- this.initLocation();
- },
- methods: {
- initLocation() {
- let that = this;
- this.$util.$L.getLocation().then(res => {
- const qqmapsdk = new QQMapWX({
- key: '7FJBZ-ACWCN-EFWFQ-SBXR5-QXC7K-LPF2U'
- //key: '7FJBZ-ACWCN-EFWFQ-SBXR5-QXC7K-LPF2U'
- });
- qqmapsdk.reverseGeocoder({
- location: {
- latitude: uni.getStorageSync('user_latitude'),
- longitude: uni.getStorageSync('user_longitude'),
- },
- success: (res2) => {
- const address = res2.result.address; // 完整地址(如北京市海淀区中关村)
- const province = res2.result.ad_info.province; // 省份
- const city = res2.result.ad_info.city; // 城市
- const recommend = res2.result.address_reference.landmark_l2.title;; // 推荐使用的地址描述,描述精确性较高
- console.log('地址信息1:', res2);
- that.userAddress = recommend;
- getMerchantList({
- latitude: uni.getStorageSync('user_latitude'),
- longitude: uni.getStorageSync('user_longitude'),
- }).then(res => {
- that.merchantList = res.data.list;
- console.log('商品信息:', that.merchantList);
- });
- that.getHomeData();
- },
- fail: (err) => {
- console.error('逆地理编码失败:', err);
- }
- });
- })
-
-
- // const qqmapsdk = new QQMapWX({
- // key: 'SMJBZ-WCHK4-ZPZUA-DSIXI-XDDVQ-XWFX7'
- // //key: '7FJBZ-ACWCN-EFWFQ-SBXR5-QXC7K-LPF2U'
- // });
- // qqmapsdk.reverseGeocoder({
- // location: {
- // latitude: uni.getStorageSync('user_latitude'),
- // longitude: uni.getStorageSync('user_longitude'),
- // },
- // success: (res2) => {
- // const address = res2.result.address; // 完整地址(如北京市海淀区中关村)
- // const province = res2.result.ad_info.province; // 省份
- // const city = res2.result.ad_info.city; // 城市
- // const recommend = res2.result.address_reference.landmark_l2.title;; // 推荐使用的地址描述,描述精确性较高
- // console.log('地址信息1:', res2);
- // that.userAddress = recommend;
- // getMerchantList({
- // latitude: uni.getStorageSync('user_latitude'),
- // longitude: uni.getStorageSync('user_longitude'),
- // }).then(res => {
- // that.merchantList = res.data.list;
- // console.log('商品信息:', that.merchantList);
- // });
- // that.getHomeData();
- // },
- // fail: (err) => {
- // console.error('逆地理编码失败:', err);
- // }
- // });
- },
- getHomeData() {
- getHomeInfo().then(res => {
- this.bannerList = res.data.banner;
- this.proList = res.data.proList;
- console.log(this.proList)
- this.messageList = res.data.headline;
- this.cateList = res.data.cateList;
- this.cateList.push({
- id: 999,
- name: '今日吃啥',
- icon: '/static/img/ic-random.png',
- color: '#FF9805'
- })
- // this.messageList = [{"id":2,"title":"绿草地活动大促,消费满三十减十五"},{"id":3,"title":"绿草地活动大促,消费满三十减十五33333"}];
- console.log("this.messageList--", this.messageList)
- this.startScroll();
- })
- },
- item2Click(item) {
- item.checked = !item.checked;
- },
- startScroll() {
- setInterval(() => {
- this.currentIndex = (this.currentIndex + 1) % this.messageList.length;
- this.offset = -this.currentIndex * 20; // 20px 是单行高度
- }, 2000); // 2秒切换一次
- },
- goSearch() {
- this.$util.navigateTo('/pages/goods/goods_search/index');
- },
- //配送时间转换
- convertMinutes(minutes) {
- const mins = Number(minutes);
- if (isNaN(mins)) return '无效输入';
- if (mins > 60) {
- const hours = Math.floor(mins / 60);
- const remaining = mins % 60;
- let result = [];
- if (hours > 0) result.push(`${hours}小时`);
- if (remaining > 0) result.push(`${remaining}分钟`);
- return result.join('') || '0分钟';
- } else {
- return `${mins}分钟`;
- }
- },
- merchantTab(item) {
- let opitem = JSON.stringify(item)
- let cid = item.cid
- uni.setStorageSync('merId', JSON.parse(JSON.stringify(item.id)))
- // 修改跳转
- uni.navigateTo({
- url: '/pages/merchant/home/index'
- // url: `/pages/goods_cate/index?id=${item.id}`
- })
- },
- onCateListClick(item) {
- if (item.link) {
- uni.navigateTo({
- url: item.link + `?id=${item.id}`
- })
- }
- },
- goGoodList(item) {
- uni.navigateTo({
- url: `/pages/goods/goods_details/index?id=${item.productId}&mt=0&iSshop=1`
- })
- },
- //选择定位
- chooseLocation: function() {
- this.$util.$L.getLocation().then(res => {
- uni.chooseLocation({
- latitude: uni.getStorageSync('user_latitude'),
- longitude: uni.getStorageSync('user_longitude'),
- success: (res) => {
- this.userAddress = res.name;
- getMerchantList({
- latitude: res.latitude,
- longitude: res.longitude
- }).then(data => {
- this.merchantList = data.data.list;
- console.log('商品信息:', this.merchantList);
- });
- // this.$set(this.userAddress, 'detail', res.name);
- }
- })
- })
- },
- },
- }
- </script>
- <style>
- page {
- height: auto;
- display: flex;
- flex-direction: column;
- height: 100%;
- /* #ifdef H5 */
- background-color: #fff;
- /* #endif */
- }
- </style>
- <style lang="scss" scoped>
- .navigationbar {
- display: flex;
- background-color: #FF6702;
- color: #fff;
- align-items: center;
- position: fixed;
- z-index: 100;
- width: 100%;
- }
- .navigationbar image {
- width: 35rpx;
- height: 35rpx;
- vertical-align: middle;
- }
- .bar-left {
- flex: 1;
- margin-left: 40rpx;
- }
- .bar-position {
- margin-left: 16rpx;
- font-size: 22rpx;
- overflow: hidden;
- /*超出部分隐藏*/
- white-space: nowrap;
- /*禁止换行*/
- text-overflow: ellipsis;
- /*省略号*/
- }
- .bar-center {
- flex: 1;
- font-size: 36rpx;
- }
- .swiper-item {
- flex-direction: column;
- justify-content: center;
- align-items: center;
- background-color: #999;
- color: #fff;
- text-align: center;
- width: 712rpx;
- height: 230rpx;
- border-radius: 10rpx;
- margin: 0 auto;
- }
- .banner-img {
- width: 712rpx;
- height: 230rpx;
- border-radius: 10rpx;
- }
- .content {
- margin: 0 20rpx;
- }
- .content-message {
- background-color: #fff;
- margin-top: 10rpx;
- padding: 10rpx;
- }
- .content-message image {
- width: 38rpx;
- height: 38rpx;
- vertical-align: middle;
- }
- .content-message text {
- font-size: 23rpx;
- color: #646464;
- margin-left: 16rpx;
- }
- .content-tab {
- background: linear-gradient(225deg, #ECF3FE 0%, #FEFEFE 100%);
- border-radius: 23rpx;
- padding: 20rpx;
- }
- .tab-list {
- display: flex;
- /* 启用弹性布局 */
- flex-direction: row;
- /* 横向排列 */
- justify-content: space-between;
- /* 均匀分布子项 */
- flex-wrap: wrap;
- /* 允许换行(适用于屏幕宽度不足时) */
- }
- .tab-item {
- width: 18%;
- /* 5个元素平分宽度,留1%作为间隙 */
- margin-bottom: 20rpx;
- /* 底部间距 */
- text-align: center;
- /* 内容居中 */
- color: #141414;
- font-size: 24rpx;
- }
- .tab-image {
- width: 100%;
- /* 宽度占满父容器 */
- height: 80rpx;
- /* 固定图片高度 */
- border-radius: 10rpx;
- /* 圆角效果 */
- background-color: #f5f5f5;
- /* 占位背景色 */
- }
- .tab-text {
- display: block;
- font-size: 27rpx;
- font-weight: 600;
- color: #141414;
- margin-top: 10rpx;
- }
- .tab-text2 {
- display: block;
- font-size: 23rpx;
- font-weight: 400;
- color: #141414;
- margin-top: 10rpx;
- }
- .content-goods {
- background: #FFFFFF;
- border-radius: 23rpx;
- padding: 20rpx;
- margin-top: 10rpx;
- }
- .tab-item2 {
- width: 23%;
- /* 5个元素平分宽度,留2%作为间隙 */
- text-align: center;
- background-color: #FFC127;
- border-radius: 8rpx;
- font-size: 23rpx;
- padding: 6rpx;
- font-weight: 400;
- }
- .tab-item2-false {
- width: 23%;
- /* 5个元素平分宽度,留2%作为间隙 */
- text-align: center;
- background-color: #fff;
- border-radius: 8rpx;
- font-size: 23rpx;
- padding: 6rpx;
- font-weight: 400;
- }
- .content-goods2 {
- background: #FFFFFF;
- border-radius: 23rpx;
- margin-top: 10rpx;
- padding: 20rpx;
- display: flex;
- }
- .goods-more {
- font-size: 21rpx;
- color: #999999;
- float: right;
- line-height: 44rpx;
- }
- .goods-list {
- flex: 0 0 356rpx;
- margin-right: 18rpx;
- }
- .goods-title {
- color: #141414;
- font-size: 26rpx;
- font-weight: 600;
- }
- .goods-desc {
- color: #646464;
- font-size: 21rpx;
- margin-top: 10rpx;
- }
- .goods-price {
- color: #FF9805;
- font-size: 34rpx;
- font-weight: 600;
- }
- .goods-score {
- color: #FD6716;
- font-size: 26rpx;
- }
- .goods-info {
- color: #999999;
- font-size: 21rpx;
- }
- .goods-info3 {
- color: #999999;
- font-size: 21rpx;
- margin-left: 10rpx;
- text-decoration: line-through;
- }
- .goods-sales {
- background-color: #FEEFE5;
- color: #FF6702;
- border-radius: 8rpx;
- font-size: 21rpx;
- padding: 4rpx 20rpx;
- }
- .goods-labels {
- background-color: #FFF6F6;
- color: #FF4B4B;
- border: 2rpx solid #FF4B4B;
- border-radius: 8rpx;
- font-size: 21rpx;
- padding: 4rpx 16rpx;
- margin-right: 20rpx;
- }
- .container {
- display: flex;
- align-items: center;
- padding: 12rpx;
- background: #ffffff;
- margin: 10rpx 0;
- }
- .left-image {
- width: 38rpx;
- height: 38rpx;
- margin-left: 20rpx;
- margin-right: 16rpx;
- }
- .right-text-container {
- flex: 1;
- height: 20px;
- /* 单行文字高度 */
- overflow: hidden;
- position: relative;
- }
- .text-list {
- position: absolute;
- width: 100%;
- transition: transform 0.5s ease;
- /* 动画过渡 */
- }
- .text-item {
- height: 40rpx;
- line-height: 40rpx;
- font-size: 23rpx;
- color: #646464;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- }
- .newsTitle {
- font-size: 23rpx;
- color: #646464;
- margin-top: 2rpx;
- }
- </style>
|