<style scoped>
	.couponDetail {
		width: 100%;
		height: 100vh;
		background: #FFFFFF;
		font-family: aa;
		
	}
	.couponDetail .cd-t{
		width: 100%;
		padding: 15px;

	}
	.couponDetail .cd-t-box{
		width: 100%;
		height: 115px;
		background-image: url('https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/cpoun.png');
		background-repeat: no-repeat;
		background-size: cover ;
		padding:15px 20px;
		color:#EFDCCB ;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		border-radius: 6px;
		position: relative;
	}
	.couponDetail .cd-tt{
		width: 100%;
		display: inline-block;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		line-clamp: 2;
		-webkit-box-orient: vertical;
		font-size: 15px;
		
	}
	.couponDetail .setmeal-pl{
		position: absolute;
		top:45.5px;
		width: 24px;
		height: 24px;
		border-radius: 12px;
		background: #FFF;
		
	}
	.couponDetail .c-d-box{
		width: 100%;
		padding: 15px;
	}
	.couponDetail .c-d-store{
		width: 100%;
		padding:0 15px 80px;
	}
	.couponDetail .title{
		width: 100%;
		height: 45px;
		font-size: 16px;
		color: #1B1D1E;
		font-weight: bold;
		line-height: 45px;
	}
	.couponDetail .min-title{
		width: 100%;
		height: 30px;
		font-size: 13px;
		color: #1B1D1E;
		font-weight: bold;
		line-height: 30px;
	}
	.couponDetail .useRange{
		padding: 10px 0;
		font-size: 12px;color: #999999;
	}
	.couponDetail .storebox{
		width: 100%;
	}
	.couponDetail .storeitem{
		display: flex;
		flex-direction: row;
		align-items: center;
		margin-top: 15px;
	}
	.couponDetail .storeitem-r{
		width: 1;
		flex: 1;
		height: 72px;
		margin-left: 10px;
		display: flex;flex-direction: column;
		justify-content: space-between;
		
	}
	.couponDetail .s-r-l{
		width: 1;
		flex: 1;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}
	.couponDetail .storeitem-f{
		display: flex;flex-direction: row;align-items: center;
	}
	.couponDetail .good-rb-text{
		font-size: 13px;
		color: #FEC471;
		margin-left: 2px;
	}
	.couponDetail .submit{
		width: 100%;
		height: 60px;
		background: #FFF;
		position: fixed;
		left: 0;
		bottom: 0;
		padding: 0 15px;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		z-index: 99;
		
	}
</style>
<template>
	<view class="couponDetail" v-if="loading">
		<view class="cd-t">
			<view class="cd-t-box">
				<text style="font-size: 12px;color: rgba(239, 220, 203, 0.6);">{{cdetail.Name}}</text>
				<text  class="cd-tt" >{{cdetail.Describe}}</text>
				<text style="font-size: 13px;">核销次数:{{cdetail.HeXiao}}次</text>
				<view class="setmeal-pl" style="left: -12px;"></view>
				<view class="setmeal-pl" style="right: -12px;"> </view>
			</view>
		</view>
		<view style="width: 100%;height: 15px;background: #FAF8F9;" ></view>
		<view class="sticky">
			<u-sticky>
				<view class="store-tabs">
					<u-tabs :list="list" :is-scroll="false" :current="current" @change="change" :active-color="mc"></u-tabs>
				</view>	
			</u-sticky>
		</view>
		<view class="c-d-box">
			<view class="title" >套餐详情</view>
			<view class="min-title">使用范围</view>
			<view class="useRange" >
				<text v-if="cdetail.UseType==1"><text v-for="(x, j) in cdetail.ProductList" :key="x">{{x.Relevance+'、'}}</text></text>
				<text v-if="cdetail.UseType==2"><text v-for="(x, j) in cdetail.ProductList" :key="x">{{x.Relevance+'、'}}</text></text>
				<text v-if="cdetail.UseType==3">全场通用</text>
			</view>
			<view class="min-title">使用时间</view>
			<view style="font-size: 12px;color: #999999;">
				有效期：{{cdetail.IndateType==1?'领取后'+cdetail.IndateDay+'天内有效':cdetail.StartDate+'-'+cdetail.EndDate}}
			</view>
		</view>
		<view style="width: 100%;height: 15px;background: #FAF8F9;" ></view>
		
		<view class="c-d-store">
			<view class="title" >适用门店</view>
			<view class="storebox">
				<view class="storeitem" v-for="(x, j) in cdetail.StoresList" :key="x" @click="gostore(x)">
					<image mode="aspectFill"  :src="x.CoverImg" style="width: 75px;height: 75px;border-radius: 6px;" ></image>
					<view class="storeitem-r">
						<view class="storeitem-f">
							<view class="s-r-l" style="width:calc(100vw - 165px); 15px;color: #000000;font-weight: bold;">{{x.Name}}</view>
							<view style="width: 50px;text-align: right;font-size: 12px;color: #111111;">{{x.KM>=1000?(x.KM/1000).toFixed(2)+'km':x.KM+'m'}}</view>
						</view>
						<view class="storeitem-f">
							<u-rate
								:current="x.Score!=null &&x.Score>0?x.Score:'5'"
								active-color="#FEC471" inactive-color="#DDDDDD"
								active-icon="star"
								inactive-icon="star-o"
								size="26"
								:disabled="true"
							></u-rate>
							<text class="good-rb-text">{{x.Score?x.Score.toFixed(1):'5.0'}}分</text>
						</view>
						<view class="storeitem-f">
							<image mode="aspectFill"  src="../../../static/images/Icon.png" style="width: 9px;height: 12px;" ></image>
							<text class="s-r-l" style="width: calc(100vw - 133px);margin-left: 3px;">{{x.Address}}</text>
						</view>
					</view>
						
				</view>
			</view>
		</view>
		<view class="submit">
			<text>{{cdetail.Name}}</text>
			
			<u-button
				size="80"
				
				:ripple="true"
				shape="circle"
				@click="submitreceive()"
				:custom-style="{
					backgroundColor:mc,
					height: '80rpx',
					color: '#FFF',
					fontSize: '14px',
				}"
			>
				{{cdetail.MemberNum>0?'去使用':'立即领取'}}
			</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		
		data() {
			return {
				pageTitle: "套餐卡详情",
				mc: "",
				loading: false,
				ID:0,
				storeId:0,
				cdetail:{},
				current:0,
				submitOrder:false,
				list:[
					{name: '套餐详情'},
					{name: '适用门店'},
					
				],
				
				cstore:0,
			};
		},
		
		onLoad(option) {
			this.mc = this.$uiConfig.mainColor;
			if(option && option.ID){
				this.ID = option.ID
			}
			if(option && option.storeId){
				this.storeId = option.storeId
			}
			this.getDetail()//获取套餐卡详情
			
			
		},
		
		mounted() {
			uni.setNavigationBarTitle({
				title: this.pageTitle,
			});
			
			
		},
	
		methods: {
			getDetail(){
				uni.showLoading({
					title: '加载中'
				});
				let storeId = uni.getStorageSync("storeId") && uni.getStorageSync("storeId").storeId ? uni.getStorageSync("storeId")
					.storeId : 0;
				this.request2({
						url: '/api/AppletStores/GetReserveCouponDetail',
						data: {ID:this.ID,StoreId:storeId}
					},
					res => {
						if (res.resultCode == 1) {
							this.loading = true
							this.cdetail=res.data
						}
						uni.hideLoading();
					}
				);
			},
			submitreceive(){
				if(this.cdetail.MemberNum==0){
					this.request2({
							url: '/api/AppletStores/GrantCoupon',
							data: {CouponId:this.ID,StoreId:this.storeId}
						},
						res => {
							if (res.resultCode == 1) {
								uni.showToast({
								    title: res.message,
								    icon: "none",
								});
								this.cdetail.MemberNum=1
							}
						}
					);
				}else{
					let data = []
					let g = this.cdetail
					if(g.UseType==1 || g.UseType==2){
						g.ProductList.forEach(x=>{
							data.push(x.ProductId)
						})
						let id = data.toString()
						uni.redirectTo({ url: '/pages/goods/list?coupon_id='+ id+'&UseType='+g.UseType });
					}else{
						uni.redirectTo({ url: '/pages/goods/list'});
					}
				}
				
			},
			change(e){
				this.current= e;
				
				switch (e) {
					case 0:
						uni.createSelectorQuery().in(this).select(".c-d-box").boundingClientRect(data=>{//目标节点
							uni.pageScrollTo({
								scrollTop: data.top-40
							})
						}).exec();	
						break;
					case 1:
						uni.createSelectorQuery().in(this).select(".c-d-store").boundingClientRect(data=>{//目标节点
							uni.pageScrollTo({
								scrollTop: data.top-40
							})
						}).exec();
						break;
				}
			},
			gostore(x){
				uni.setStorageSync("storeId", {storeId:x.Id});
				uni.navigateTo({
					url: "/pages/reserve/storeDetails?id="+x.Id,
				});
			}
		},
	};
</script>


