Files
xdd-uniapp-new/pages/home/index.vue
T

796 lines
20 KiB
Vue

<template>
<view class="tabbar-page">
<view
:style="{
'padding-top': statusBarHeight + 'px',
'padding-right': rightDistance + 'px'
}"
:class="scrollTop > 40 ? 'blur' : ''"
class="fix-header"
>
<view class="location" @click="reLocateHandle()">
{{ isLocating ? '定位中' : (cityName || '定位失败') }}
<image
:src="webUrl + '/home/icon-location.png'"
class="icon"
/>
</view>
<view class="search-wrap" @click="goGoodSearch">
<image
:src="webUrl + '/home/icon-search2.png'"
class="icon"
/>
</view>
</view>
<view class="slider-banner">
<swiper
v-if="banner.length > 0"
indicatorDots="true"
indicator-color="rgba(255, 255, 255, .3)"
indicator-active-color="#ffffff"
autoplay
circular
style="height: 510rpx;"
>
<block
v-for="(item, bannerIndex) in banner"
:key="bannerIndex"
>
<swiper-item>
<view @click="goRoll(item)" class="swiper-item">
<image :src="item.pic"/>
</view>
</swiper-item>
</block>
</swiper>
</view>
<view class="home-body">
<!-- 导航v9 -->
<view class="menus-wrap">
<view class="menus-bg" />
<view class="menus-list">
<view
v-for="(item, index) in menus"
:key="index"
class="item flex flex-col ai-center"
@click="$global.commonJump(item.uniapp_url)"
>
<image
:src="item.pic"
mode="scaleToFill"
class="img"
/>
<view class="one-t tc menu-name">
{{ item.name }}
</view>
</view>
</view>
</view>
<!-- 千县名品和地标好物 -->
<view
v-if="landmarkGoodsImage.image || countyFamousImage.image"
class="land-famous-wrap"
>
<view v-if="countyFamousImage.image" class="pic-wrap">
<image
:src="countyFamousImage.image"
mode="heightFix"
class="img"
@click="landAndFamousItemClickHandle(countyFamousImage)"
/>
</view>
<view v-if="landmarkGoodsImage.image" class="pic-wrap">
<image
:src="landmarkGoodsImage.image"
mode="heightFix"
class="img"
@click="landAndFamousItemClickHandle(landmarkGoodsImage)"
/>
</view>
</view>
<!-- 导航v9end -->
<!-- v9 专题 -->
<view class="subject-box">
<view class="section-full flex jc-between">
<swiper
class="swiper"
circular
autoplay
:interval="3000"
>
<swiper-item
v-for="(stay, stayIndex) in contentHomestay"
:key="stayIndex"
>
<image
:src="stay.indexImage"
mode="scaleToFill"
@click="goHomeStay(stay)"
/>
</swiper-item>
</swiper>
<image
v-if="contentFestival.indexImage"
:src="contentFestival.indexImage"
mode="scaleToFill"
@click="goFestival"
/>
</view>
</view>
<!-- 2022/6/20 add 尖货推荐 -->
<view class="bast-box">
<view>
<image
:src="webUrl + '/home/bast-list-title.png'"
class="bast-title"
mode="scaleToFill"
/>
</view>
<view class="bast-list">
<view class="bast-list-left">
<view
v-for="(item, index) in bastLeftList"
:key="index"
class="item flex"
>
<view
v-if="item.type === 'hotel'"
class="hotel-list-wrap"
>
<image
:src="webUrl + '/home/hotel-list-bg.png'"
mode="widthFix"
class="bg"
/>
<view class="list">
<view
v-for="(hotelItem, hotelIndex) in item.list"
:key="hotelIndex"
class="hotel-item"
@click="hotelItemClickHandle(hotelItem)"
>
<image :src="webUrl + '/home/home-number' + (hotelIndex + 1) + '.png'" class="mark" />
<image :src="webUrl + '/home/icon-hotel-btn.png'" class="btn" />
<image :src="hotelItem.logo" class="logo" />
<view class="info">
<view class="name one-t">{{ hotelItem.name }}</view>
<view class="desc more-t">{{ hotelItem.content }}</view>
</view>
</view>
</view>
</view>
<xdd-product-item
v-else
:item="item"
@view="goGoodsCon(item)"
/>
</view>
</view>
<view class="bast-list-right">
<view
v-for="(item, index) in bastRightList"
:key="index"
class="item flex"
>
<view
v-if="item.type === 'swiper'"
class="swiper-wrap"
>
<swiper
class="swiper"
circular
autoplay
:interval="3000"
>
<swiper-item
v-for="(swiperItem, swiperIndex) in item.list"
:key="swiperIndex"
>
<image
:src="swiperItem.indexImage"
mode="scaleToFill"
class="swiper-img"
@click="productSwiperItemClickHandle(swiperItem)"
/>
</swiper-item>
</swiper>
</view>
<xdd-product-item
v-else
:item="item"
@view="goGoodsCon(item)"
/>
</view>
</view>
</view>
</view>
</view>
<!-- v9 老用户弹窗 -->
<u-popup
:show="isOldUser && oldUserPopup.image"
mode="center"
bgColor="transparent"
>
<view class="popup-old-user flex flex-col ai-center">
<image
:src="oldUserPopup.image"
class="main"
mode="scaleToFill"
@click="tapOld()"
/>
<view
class="icon-box flex jc-center ai-center"
@click="changeOldPopup(false)"
>
<image
:src="webUrl+'/20230608112219219303.png'"
mode="scaleToFill"
/>
</view>
</view>
</u-popup>
<!-- 尖货推荐结束 -->
<u-back-top :scroll-top="scrollTop">
<image
:src="webUrl+'/icon/setTop.png'"
mode="scaleToFill"
style="width: 40px;height: 40px;"
@click="setTopHandle"
/>
</u-back-top>
<xdd-tabbar :curr-index="0" />
</view>
</template>
<script>
import XddTabbar from '@/components/xdd-tabbar'
import XddProductItem from '@/components/xdd-product-item'
import { getCouponReceive } from '@/api/user'
import { getHomeData, getShareImage } from '@/api/public'
import { sharpBannar } from '@/api/goods'
import { pageListenMixins } from '@/mixins/pageListenMixins'
import {
getCurAddress,
getLocationPromise,
getLocationSetting,
openLocationSettting
} from "@/utils/common"
export default {
name: 'IndexPage',
components: {
XddTabbar,
XddProductItem
},
mixins: [pageListenMixins],
data() {
return {
webUrl: this.$VUE_APP_RESOURCES_URL,
// 状态栏高度
statusBarHeight: 20,
// 右侧距离
rightDistance: 10,
banner: [],
menus: [],
// 定位中
isLocating: true,
cityName: '',
// 地标好物
landmarkGoodsImage: {},
// 千县名品
countyFamousImage: {},
// 尖货推荐左侧
bastLeftList: [],
// 尖货推荐右侧
bastRightList: [],
// 尖货推荐横幅
bannerList: [],
// 分享图片
shareAppImg: '',
// 老用户弹窗
isOldUser: true,
oldUserPopup: {},
// 民宿专题轮播
contentHomestay: [],
// 节日专题
contentFestival: {},
pageKeyId: Object.freeze('appIndex'),
scrollTop: 0
}
},
onLoad() {
uni.hideTabBar()
const _this = this
_this.init()
uni.getSystemInfo({
success: (e) => {
let statusBar = 0
// #ifdef MP-WEIXIN
statusBar = e.statusBarHeight
const custom = uni.getMenuButtonBoundingClientRect()
_this.rightDistance = e.windowWidth - custom.left + 10
// #endif
// 状态栏高度
_this.statusBarHeight = statusBar
}
})
},
onHide() {
this.pageToHideHandle()
},
onShareAppMessage() {
return {
title: '探寻有趣有味的生活方式',
path: '/pages/home/index',
imageUrl: this.shareAppImg
}
},
onPageScroll(e) {
this.scrollTop = e.scrollTop
},
methods: {
init() {
getShareImage().then(({ data }) => this.shareAppImg = data)
sharpBannar().then(res => {
const { data } = res
this.bannerList = data.banner
this.getPageData()
})
this.getLocationData()
},
// 定位失败,重新唤起定位授权
reLocateHandle() {
if (this.cityName) return
getLocationSetting(() => openLocationSettting().then(() => {
this.getLocationData()
}))
},
async getLocationData() {
this.isLocating = true
const mapData = await getLocationPromise()
if (mapData.errMsg) {
const { latitude, longitude } = mapData
const address = await getCurAddress(latitude, longitude)
this.cityName = address[1].data.result.ad_info.city
this.isLocating = false
this.getPageData()
} else {
this.isLocating = false
}
},
getPageData() {
const _this = this
uni.showLoading({ title: '加载中' })
getHomeData({ cityName: this.cityName }).then(res => {
const { data } = res
_this.$set(_this, 'banner', data.banner)
_this.$set(_this, 'menus', data.menus)
_this.$set(_this, 'landmarkGoodsImage', data.landmarkGoodsImage)
_this.$set(_this, 'countyFamousImage', data.countyFamousImage)
_this.$set(_this, 'oldUserPopup', data.oldUserPopup)
_this.$set(_this, 'contentHomestay', data.contentHomestay)
_this.$set(_this, 'contentFestival', data.contentFestival)
_this.bastLeftList = []
_this.bastRightList = []
for (let i = 0; i < data.bastList.length; i++) {
if (i % 2 === 0) {
// 店铺排名
if (i === 4 && data.hotelList.length > 0) {
_this.bastLeftList.push({
type: 'hotel',
list: data.hotelList
})
}
_this.bastLeftList.push(data.bastList[i])
}
if (i % 2 === 1) {
// 尖货专题
if (i === 3 && data.contentBest.length > 0) {
_this.bastRightList.push({
type: 'swiper',
list: data.contentBest
})
}
_this.bastRightList.push(data.bastList[i])
}
}
uni.hideLoading()
}).catch(() => {
uni.hideLoading()
})
},
goRoll(item) {
if (item.uniapp_url) {
this.$yrouter.push(item.uniapp_url)
}
},
goGoodSearch() {
this.$yrouter.push('/pages/shop/GoodSearch/index')
},
goGoodsCon(item) {
this.$yrouter.push({
path: '/pages/shop/GoodsCon/index',
query: {
id: item.id
}
})
},
changeOldPopup(state) {
this.isOldUser = state
},
// 民宿专题
goHomeStay(stay) {
if (stay.uniappUrl) {
this.$global.commonJump(stay.uniappUrl)
return
}
if (stay.type === 2 && stay.isLinkToProduct) {
this.$yrouter.push({
path: '/pages/shop/GoodsCon/index',
query: {
id: stay.productId
}
})
return
}
if (stay.type === 1) {
uni.navigateTo({url: '/pkg_product/views/homestay?id=' + stay.id})
}
},
// 节日专题
goFestival() {
uni.navigateTo({url: '/pkg_product/views/festival'})
},
tapOld() {
this.isOldUser = false
const {
type,
text,
jumpTime,
pageLevel,
url,
params,
couponId
} = this.oldUserPopup
if (couponId != null) {
getCouponReceive(couponId).then(res => {
if (res.status === 200) {
uni.showToast({
title: text,
icon: 'none',
success: () => {
}
})
}
}).catch((err) => {
uni.showToast({
title: err.data.msg + '',
icon: 'none',
duration: 3000
})
})
}
// type 1-定时跳转,2-点击跳转,3-不跳转
if (type === 1) {
setTimeout(() => {
this.$global.levelJump(pageLevel, url, params)
}, jumpTime * 1000)
} else if (type === 2) {
this.$global.levelJump(pageLevel, url, params)
}
},
// 千县名品和地标好物
landAndFamousItemClickHandle(item) {
const url = item.url
if (!url) return
if (item.level === '1') {
uni.switchTab({ url })
}
if (item.level === '2') {
uni.navigateTo({ url })
}
},
// 店铺排名
hotelItemClickHandle(item) {
uni.navigateTo({ url: `/pagesInn/inn/innHome?id=${item.id}&from=index` })
},
// 尖货专题
productSwiperItemClickHandle(item) {
// 类型:1-专题页 2-商品详情 3-时令尝鲜
const type = item.type
if (type === 1) {
uni.navigateTo({ url: `/pkg_product/views/festival?id=${item.id}&from=index&theme=best` })
}
// 链接到特定页面
if (type === 2 && item.uniappUrl) {
this.$global.commonJump(stay.uniappUrl)
return
}
// 商品详情
if (type === 2 && item.productId) {
this.$yrouter.push({
path: '/pages/shop/GoodsCon/index',
query: {
id: item.productId
}
})
}
if (type === 3) {
uni.navigateTo({ url: '/pkg_product/views/seasonList' })
}
},
setTopHandle() {
uni.pageScrollTo({
scrollTop: 0,
duration: 200
})
}
}
}
</script>
<style scoped lang="less">
.swiper-item {
height: 100%;
}
.slider-banner {
position: relative;
z-index: 2;
}
.subject-box {
padding: 12rpx;
margin: 16rpx 0 0 0;
border-radius: 20rpx;
background: #fff;
image {
vertical-align: middle;
}
.section-full {
image {
width: 336rpx;
height: 480rpx;
border-radius: 20rpx;
}
.swiper {
width: 336rpx;
height: 480rpx;
border-radius: 20rpx;
overflow: hidden;
}
}
}
.popup-old-user {
image {
vertical-align: middle;
}
.main {
width: 560rpx;
height: 840rpx;
border-radius: 40rpx;
}
.icon-box {
width: 96rpx;
height: 96rpx;
margin-top: 40rpx;
background: rgba(51, 51, 51, .4);
border-radius: 50%;
image {
width: 40rpx;
height: 40rpx;
}
}
}
.bast-box {
.bast-title {
width: 350rpx;
height: 52rpx;
margin: 21rpx 0 0 0;
}
.bannar-swiper {
height: 534rpx;
image {
width: 332rpx;
height: 534rpx;
}
}
.bast-list {
display: flex;
justify-content: space-between;
.bast-list-left,
.bast-list-right {
width: calc(50% - 11rpx);
}
.item {
position: relative;
margin: 21rpx 0 0 0;
.swiper-wrap {
width: 100%;
border-radius: 20rpx;
overflow: hidden;
}
.swiper {
width: 100%;
height: 486rpx;
.swiper-img {
width: 100%;
height: 486rpx;
}
}
}
}
}
.tabbar-page {
padding: 0 0 180rpx 0;
background-color: #F0F0F0;
}
.home-body {
position: relative;
z-index: 5;
padding: 21rpx 21rpx 0 21rpx;
}
.menus-wrap {
position: relative;
.menus-list {
position: relative;
z-index: 5;
display: flex;
flex-shrink: 0;
padding: 12rpx 24rpx;
margin: -120rpx 0 0 0;
border-radius: 16rpx;
background-color: #fff;
overflow-x: auto;
.item + .item {
margin: 0 0 0 36rpx;
}
.item {
width: 150rpx;
.img {
width: 86rpx;
height: 86rpx;
}
.menu-name {
margin: 16rpx 0 0 0;
color: #666;
font-size: 26rpx;
}
}
}
.menus-bg {
position: absolute;
top: 0;
left: -21rpx;
z-index: 2;
width: calc(100% + 40rpx);
height: 180rpx;
background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, #F0F0F0 40%, #F0F0F0 100%);
content: " ";
}
}
.land-famous-wrap {
position: relative;
display: flex;
flex-shrink: 0;
justify-content: space-between;
padding: 20rpx;
margin: 21rpx 0 0 0;
border-radius: 16rpx;
background: linear-gradient(180deg, rgba(243, 231, 209, 0.5) 0%, rgba(243, 232, 214, 0.5) 100%);
.pic-wrap {
.img + .img {
margin: 0 0 0 20rpx;
}
.img {
display: block;
height: 188rpx;
}
}
}
.hotel-list-wrap {
position: relative;
width: 344rpx;
.bg {
position: absolute;
top: 0;
left: 0;
right: 0;
z-index: 2;
width: 100%;
}
.list {
position: relative;
z-index: 5;
padding: 100rpx 21rpx 21rpx 21rpx;
.hotel-item + .hotel-item {
margin: 21rpx 0 0 0;
}
.hotel-item {
position: relative;
display: flex;
padding: 8rpx 16rpx 8rpx 8rpx;
border-radius: 16rpx;
background-color: #fff;
.mark {
position: absolute;
top: 8rpx;
left: 20rpx;
z-index: 5;
width: 26rpx;
height: 26rpx;
}
.btn {
position: absolute;
bottom: 8rpx;
right: 0;
z-index: 5;
width: 60rpx;
height: 22rpx;
}
.logo {
display: block;
width: 116rpx;
height: 116rpx;
border-radius: 16rpx;
}
.info {
width: calc(100% - 116rpx);
padding: 0 0 0 16rpx;
box-sizing: border-box;
.name {
font-size: 24rpx;
color: #333;
line-height: 40rpx;
font-weight: bold;
}
.desc {
font-size: 20rpx;
color: #999;
line-height: 28rpx;
}
}
}
}
}
.fix-header {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 99;
display: flex;
align-items: center;
height: 44px;
padding-left: 21rpx;
line-height: 32px;
&.blur {
backdrop-filter: blur(5px);
}
.location {
display: flex;
align-items: center;
margin: -4px 20rpx 0 0;
color: #fff;
font-size: 32rpx;
.icon {
display: block;
width: 32rpx;
height: 32rpx;
margin: 0 0 0 10rpx;
}
}
.search-wrap {
display: flex;
align-items: center;
flex: 1;
height: 36px;
margin: -4px 0 0 0;
border-radius: 18px;
background-color: rgba(255, 255, 255, 0.5);
.icon {
display: block;
width: 36rpx;
height: 36rpx;
margin: 0 0 0 20rpx;
}
}
}
</style>