<template>
	<view>
		<image src="@/static/bg.png" mode="" class="bg" style="width: 100%;height: 928rpx;"></image>
		<view class="top" :style="{'padding-top': top+'px'}">
			<view class="location">
				<image class="dw" src="@/static/定位.png" mode="" style="width: 30rpx;height: 30rpx;"></image>
				<view class="xuzou">{{city}}</view>
			</view>
			<image src="@/static/bg.png" mode="widthFix" class="hs"></image>
		</view>
		<view class="content" :style="{'top': (top+44)+'px'}">
			<view class="topimg">
				<image class="topimg1" src="https://bodybuilding.bsdong.cn/images/banner.png" mode=""></image>
			</view>
			<view class="mendian">
				<view class="mendian1">
					<view class="tj">门店推荐</view>
					<view class="data1" @click="mendianlist">
						切换门店<uni-icons type="right" color="#999" size="18"></uni-icons>
					</view>
				</view>
				<view class="mddz" v-for="(item,index) in tuijianlist" :key="index">
					<view class="mddz1">
						<image class="mddz1img" style="border-radius: 10rpx;" :src="item.image.url" mode=""></image>
						<view class="mddz1wz">{{item.name}}</view>
					</view>
					<view class="mddz2">
						<view style='width:570rpx' @click="handleNavigation(item)">
							<image class="mddz1img1" src="@/static/定位1.png" mode=""></image>
							<text class="dz">{{item.address}}</text>
						</view>
						
						<image class="mddz1img2" src="@/static/电话o.png" mode="" @click="makePhoneCall(item.mobile)"></image>
					</view>
				</view>
			</view>
			<view class="btn" @click="tuanquan">
				<view class="btnwz">团购验券</view>
				<view class="btnwz1">美团/抖音，验券进场</view>
			</view>
			<view class="hy">会员套餐</view>
			<view class="btboxs">
				<view class="btbox" v-for="(item,index) in viplist" :key="index" @click="taochan(item)">
					<image :src="item.img.url" mode="aspectFill" class="btimg"></image>
					<view class="bttitle">{{item.name}}</view>
					<view class="btwz" v-if="item.validity_day>0">期限：{{item.validity_day}}天</view>
					<view class="btwz" v-if='item.validity_num>0'>次数：{{item.validity_num}}次</view>
					<view class="btwzjg">
						<text class="btwzjg1">￥{{item.price}}</text>
						<text class="btwzjg2">原价：￥{{item.original_price}}</text>
					</view>
				</view>
			</view>
		</view>
		<uni-popup ref="popup" background-color="#fff" :mask-click='false' :animation="false">
			<view class="popbox">
				<view class="close">
					<image src="@/static/close-l.png" mode="" style="width: 44rpx;height: 44rpx;" @click="close">
					</image>
				</view>
				<view class="popuptitle">
					团购验券
				</view>
				<view class="input">
					<input class="input1" type="text" placeholder="请输入抖音/美团券码"  v-model="scanCode"/>
					<image class="saoma" @click="openScan()" src="@/static/扫一扫.png" mode=""></image>
				</view>
				<view class="yqbtn" @click="numberCheck">
					验券
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				scanCode: "",
				city:'',
				number:'',
				viplist:[],
				mendainlist:[],
				latitude:'',
				longitude:'',
				tuijianlist:[],
				iswanjie:false,
				shoujidingwei:true,
				top: 0
				
			}
		},
		onShareAppMessage() {
		 return {
			  title: '运动湾24小时健身',
			  path: '/pages/index/index'
			}
		},
		onLoad() {
			const that = this;
			this.top = uni.getSystemInfoSync().statusBarHeight;
			uni.$on("changeStoreInfo",function(res){
				that.tuijianlist = [res]
				console.log(res)
			})
		},
		onReady() {
			this.viplist=[]
			this.cardList(1)
			// this.storeList(1)
			if(!this.city){
				this.getLocation()
			}
		},
		onReachBottom(){
			if(!this.iswanjie){
				this.cardList(this.page+1)
			}
		},
		methods: {
			openScan() {
				const that = this;
				uni.scanCode({
					success(res) {
						that.scanCode = res.result;
					}
				})
			},
			handleNavigation(i) {
				uni.openLocation({
					longitude:Number(i.longitude),
					latitude:Number(i.latitude),
					name:i.name,
					address: i.address,
					success: function(res) {
					},
					fail: function(error) {
						console.log(error)
					}
				})
			},
			numberCheck(){
				if(!uni.getStorageSync("token")) {
					uni.navigateTo({
						url: "/pages/login/login"
					})
					return ;
				}
				uni.showLoading({
					title: "核销中"
				})
				this.$api.numberCheck({number:this.scanCode, storeId: this.tuijianlist[0].id}).then(res=>{
					if(res.code==200){
						uni.hideLoading();
						uni.showToast({
							icon: "none",
							title: res.data.msg,
							duration: 3000
						});
						this.$refs.popup.close('center')
					}else{
						uni.hideLoading();
					}
				})
			},
			getLocation(){
				console.log(1234);
				var that=this
				uni.getLocation({
				  type: 'wgs84',
				  success: function (res) {
					  that.shoujidingwei=true
					  that.latitude= res.latitude;
					  that.longitude= res.longitude;
					  that.$api.nearStore({latitude:that.latitude,longitude:that.longitude,limit:1}).then(res=>{
						  that.tuijianlist=res.data
					  })
					 that.$api.newGetCity({locations:that.longitude+","+that.latitude}).then(res=>{
						 console.log('res',res);
						 that.city=res.data.city
					 })
					 },
				  fail: function (error) {
					that.shoujidingwei=false
					uni.getSystemInfo({
						success: function (res) {
							console.log(998,);
							if(!res.locationEnabled){
								uni.showModal({
									icon: "none",
									title: '手机定位未开启',
									duration: 3000
								})
							}else{
								uni.showModal({
									title: '获取位置',
									content: '小程序定位未开启是否开启',
									success: function (res) {
										if (res.confirm) {
											uni.openSetting({
											  success(res) {
											    console.log(9998,res.authSetting)
											  }
											});
										} else if (res.cancel) {
										}
									}
								});
							}
						}
					})
				  }
				});
			},
			
			cardList(page){
				this.$api.cardList({page:page}).then(res=>{
					let arr = res.data.list
					this.viplist = [...this.viplist, ...arr]
					if(this.viplist.length>=res.data.total){
						this.iswanjie=true
					}
				})
			},
			storeList(page){
				this.$api.storeList({page:page}).then(res=>{
					this.mendainlist=res.data.list
				})
			},
			makePhoneCall(e){
				uni.makePhoneCall({
					phoneNumber: e 
				});
			},
			mendianlist() {
				uni.navigateTo({
					url: '/pages/mendainlist/mendainlist?item='+'shouye'+'&id='+this.tuijianlist[0].id
				})
			},
			tuanquan() {
				this.number=''
				this.$refs.popup.open('center')
			},
			close() {
				this.$refs.popup.close('center')
			},
			taochan(i) {
				if(!uni.getStorageSync("token")) {
					uni.navigateTo({
						url: "/pages/login/login"
					})
					return ;
				}
				uni.setStorageSync('xzmd','')
				var that=this
				var tuijianlist=JSON.stringify(that.tuijianlist[0])
				var item=JSON.stringify(i)
				if(that.shoujidingwei){
					uni.navigateTo({
						url: `/pages/order/order?tuijianlist=${tuijianlist}&item=${item}`
					})
				}else{
					 uni.reLaunch({
					      url: '/pages/index/index' 
					    });
				}
				
			},
		}
	}
</script>
<style scoped>
	.yqbtn {
		width: 550rpx;
		height: 90rpx;
		background: #F8A617;
		box-shadow: 0rpx 4rpx 13rpx 0rpx rgba(19, 14, 4, 0.08);
		border-radius: 45rpx;
		text-align: center;
		line-height: 90rpx;
		margin: 0 auto;
		margin-top: 35rpx;
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 30rpx;
		color: #FFFFFF;
	}

	.input1 {
		flex: 1;
		font-size: 30rpx;
		color: #333;
	}

	.saoma {
		width: 44rpx;
		height: 44rpx;
	}
	.bg{
		width: 100%;
		height: 100%;
		position: absolute;
		left: 0;
		top: 0;
		z-index: 1;
		background: #f5f5f5;
	}
	.content{
		width: 100%;
		min-height: 100vh;
		position: relative;
		left: 0;
		top: 0;
		z-index: 2;
	}
	.input {
		width: 531rpx;
		height: 91rpx;
		background: #FFFFFF;
		border-radius: 10rpx;
		border: 1px solid #CCCCCC;
		padding: 0 20rpx;
		margin: 0 auto;
		margin-top: 48rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.popbox {
		width: 630rpx;
		height: 400rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
	}

	.popuptitle {
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 36rpx;
		color: #222222;
		text-align: center;
		margin-top: -20rpx;
	}

	.close {
		text-align: right;
		padding-right: 30rpx;
		padding-top: 24rpx;
	}

	.btbox {
		width: 340rpx;
		margin-left: 24rpx;
		background: #FFFFFF;
		margin-top: 30rpx;
		box-shadow: 0px 4rpx 13rpx 0px rgba(19,14,4,0.08);
		border-radius: 20rpx;
		overflow: hidden;
	}

	.btboxs {
		display: flex;
		flex-wrap: wrap;
		padding-bottom: 25rpx;
		overflow: hidden;
	}

	.btwz {
		font-family: Alibaba PuHuiTi;
		font-weight: 400;
		font-size: 24rpx;
		color: #999999;
		margin-top: 15rpx;
		margin-left: 24rpx;
	}

	.btwzjg {
		margin-top: 15rpx;
		margin-left: 15rpx;
		margin-bottom: 26rpx;
		white-space: nowrap;
		overflow: hidden;
	}

	.btwzjg1 {
		font-family: Alibaba PuHuiTi;
		font-weight: 400;
		font-size: 28rpx;
		color: #EF3D25;
	}

	.btwzjg2 {
		font-family: Alibaba PuHuiTi;
		font-weight: 400;
		font-size: 22rpx;
		color: #CCCCCC;
		padding-left: 10rpx;
		text-decoration-line: line-through;
	}

	.bttitle {
		font-family: Alibaba PuHuiTi;
		font-weight: 400;
		font-size: 30rpx;
		color: #333333;
		margin-top: 15rpx;
		margin-left: 24rpx;
	}

	.btimg {
		width: 340rpx;
		height: 200rpx;
	}

	.hy {
		font-family: PingFang SC;
		font-weight: bold;
		font-size: 34rpx;
		color: #222222;
		margin-top: 40rpx;
		margin-left: 22rpx;
	}

	.btn {
		text-align: center;
		width: 700rpx;
		height: 120rpx;
		background: #F8A617;
		box-shadow: 0rpx 4rpx 13rpx 0rpx rgba(19, 14, 4, 0.14);
		border-radius: 60rpx;
		margin: 0 auto;
		margin-top: 20rpx;
	}

	.btnwz {
		font-family: PingFang SC;
		font-weight: bold;
		font-size: 30rpx;
		color: #FFFFFF;
		padding-top: 23rpx;
		margin-bottom: 17rpx;
	}

	.btnwz1 {
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 24rpx;
		color: #FFFFFF;
	}

	.mddz1img2 {
		width: 44rpx;
		height: 44rpx;
		position: absolute;
		right: 70rpx;
	}

	.mddz2 {
		margin-top: 25rpx;
		display: flex;
	}
	
	.dz {
		font-size: 26rpx;
		color: #999;
		margin-left: 17rpx;
	}

	.mddz1img1 {
		width: 22rpx;
		height: 27rpx;
	}

	.mddz1 {
		display: flex;
	}

	.mddz1img {
		width: 60rpx;
		height: 60rpx;
	}

	.mddz1wz {
		font-family: PingFang SC;
		font-weight: bold;
		font-size: 30rpx;
		color: #222222;
		margin-left: 21rpx;
		margin-top: 12rpx;
	}

	.mddz {
		width: 643rpx;
		/* height: 142rpx; */
		background: #FFFFFF;
		box-shadow: 0rpx 3rpx 9rpx 0rpx rgba(19, 14, 4, 0.08);
		border-radius: 20rpx;
		margin-top: 24rpx;
		padding: 20rpx 17rpx;
	}

	.tj {
		font-family: PingFang SC;
		font-weight: bold;
		font-size: 34rpx;
		color: #222222;
	}
	.mendian1 .data1{
		font-size: 24rpx;
		color: #999;
		display: flex;
		align-items: center;
	}
	.mendian1 {
		display: flex;
		justify-content: space-between;
	}

	.mendian {
		width: 670rpx;
		/* height: 278rpx; */
		background: #EBEFF0;
		border-radius: 20rpx;
		margin: 0 auto;
		margin-top: 20rpx;
		padding: 29rpx 23rpx;
	}

	.top {
		width: 100%;
		left: 0;
		z-index: 22;
		height: 88rpx;
		overflow: hidden;
		position: fixed;
	}
	.top .location{
		width: 100%;
		height: 88rpx;
		display: flex;
		position: fixed;
		align-items: center;
		position: relative;
		z-index: 23;
	}
	.top .hs{
		width: 100%;
		height: 100%;
		position: absolute;
		left: 0;
		top: 0;
		z-index: 1;
	}
	.jiantou {
		margin-left: 18rpx;
		margin-top: 10rpx;
	}

	.xuzou {
		margin-left: 13rpx;
		font-family: Alibaba PuHuiTi;
		font-weight: 400;
		font-size: 30rpx;
		color: #222222;
	}

	.dw {
		margin-top: 2rpx;
		margin-left: 22rpx;
	}

	.topimg {
		width: 700rpx;
		height: 361rpx;
		background: #E1E5E6;
		box-shadow: 0rpx 4rpx 13rpx 0rpx rgba(19, 14, 4, 0.14);
		border-radius: 20rpx;
		margin: 0 auto;
	}

	.topimg1 {
		width: 700rpx;
		height: 361rpx;
	}
</style>