<template>
	<view class="pad-x180" style="padding-bottom: 240rpx;">
		<!-- 状态栏 -->
		<status-nav :titleVal="title" :statusTitle="true"></status-nav>
		<!-- 列表 -->
		<view :style="{paddingTop: (statusHeight+15)+'px'}" class="pad-zy32">
			<view class="fon28 mar-x50" style="color: #1A1A1A; line-height: 40rpx;">
				<rich-text :nodes="richText"></rich-text>
			</view>
			<view class="pad-x30">
				<view v-if="dataList.length!=0" class="mar-x20 animated fadeInLeft" v-for="(item,index) in dataList" :key="index">
					<view style="height: 200rpx;" class="disjbac posir">
						<view class="disjcac fc recerve-left" style="width: 218rpx;height: 200rpx;flex-shrink: 0;text-align: center;color: #FFFFFF;">
							<image v-if="item.get" class="posia quan-img" src="/static/public/quan-left-two.png" mode=""></image>
							<image v-else class="posia quan-img" src="/static/public/quan-left.png" mode=""></image>
							<view class="posir disjcac fc" style="z-index: 1;">
								<view class="fon28 mar-s20 mar-x36"><span class="bold" style="font-size: 56rpx;">{{item.num}}</span><span v-if="item.unit">{{item.unit}}</span></view>
								<view @tap="useEv(item.id)" class="fon24 quan-btn" :style="{color: item.get ? '#b3b3b3' : '#3875F6'}">{{['立即领取','已领取'][item.get]}}</view>
							</view>
						</view>
						<view class="quan-right-box">
							<view class="fon28 col3 mar-s20">{{item.title}}</view>
							<view class="fon24 col80">满{{item.manPrice}}元可使用</view>
							<view class="fon20 col80 mar-x20">有效期:{{item.startTime}}至{{item.endTime}}</view>
						</view>
					</view>
				</view>
			</view>
			<view class="posixzy bacf pad-sx25" style="background: none; bottom: 150rpx;">
				<view @tap="allReceive" class="fon30 radius20 tc colf bold" style="margin: 0 83rpx;height: 90rpx;line-height: 90rpx;" :style="{background:publicColor}">{{['一键领取','立即使用'][dataList[0].get]}}</view>
			</view>
		</view>
		<view class="disjcac" v-if="ifLing" style="position: fixed;top: 0;left: 0;bottom: 0;right: 0;background-color: rgba(0, 0, 0, .7);z-index: 2;padding: 0 100rpx;">
			<view class="tcenter radius30 bacf width100 pad-sx50">
				<view class="bold pad-s30" style="font-size: 48rpx;">恭喜您领取成功</view>
				<view @tap="allReceive" class="disjcac fon38" style="width: 426rpx;height: 80rpx;border-radius: 20rpx;color: #FFFFFF;margin: 0 auto;margin-top: 100rpx;margin-bottom: 10rpx;" :style="{backgroundColor:publicColor}">立即使用</view>
			</view>
		</view>
		<!-- 用户信息授权,手机号授权 -->
		<auth-userInfo-mobileInfo></auth-userInfo-mobileInfo>
		<!-- 底部导航 -->
		<view class="posixzy">
			<bottom-tab></bottom-tab>
		</view>
	</view>
</template>

<script>
	import bottomTab from '@/components/bottom-tab.vue';
	export default {
		components: {
			bottomTab,
		},
		data() {
			return {
				dataList:[],
				zcList:[],
				page:1,
				size:10,
				sizeq: 162,
				title:'优惠券组',
				richText:'',
				groupId:'',
				ifLing:false,
				share_img:'', //分享图片
				share_title:'', //分享标签
			}
		},
		computed:{
			// 主题颜色
			publicColor() {
				return this.$store.state.publicColor
			},
			statusHeight() {
				return this.$store.state.statusHeight
			}
		},
		onShareAppMessage() {
			// 调用tools.js中的种植埋点事件
			console.log(`${this.$http}${this.share_img}`,`${this.share_title}`,212121212)
			var shareObj = {
				title: `${this.share_title}`, // 默认是小程序的名称(可以写slogan等)
				path: `/pagesB/couponGroup/couponGroup?group_id=${this.groupId}&share_id=${uni.getStorageSync('userId')}&invite_code=${uni.getStorageSync('invite_code')}`, // 默认是当前页面,必须是以‘/’开头的完整路径
				imageUrl: `${this.$http}${this.share_img}`  //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
			};
			return shareObj;
		},
		onLoad(op) {
			if(uni.getStorageSync('phone_active')!=0 && uni.getStorageSync('is_active')!=0){
				this.checkAllList(op.group_id);
			}
		},
		onUnload() {
			
		},
		methods: {
			allReceive(){
				if(this.dataList[0].get) {
					uni.reLaunch({
						url:'/pagesA/coupon/coupon'
					})
				} else {
					this.$requst.post('user/get-coupon-group',{group_id:this.groupId}).then(res=>{
						if(res.code==0){
							// this.$toolAll.tools.showToast('领取成功(*^▽^*)');
							this.ifLing = true;
							this.checkAllList(this.groupId);
						} else {
							this.$toolAll.tools.showToast(res.msg);
						}
					})
				}
			},
			checkAllList(group_id){//查询所有优惠券列表
				this.$requst.post('user/get-coupon-group-info',{group_id}).then(res=>{
					console.log(res,'优惠券列表')
					if(res.code==0){
						this.groupId = res.data.id;
						this.title = res.data.title;
						this.richText = this.$toolAll.tools.escape2Html(res.data.content);
						this.dataList = [];
						this.zcList = [];
						this.share_img = res.data.share_img;
						this.share_title = res.data.title;
						if(res.data.coupon.length!=0){
							res.data.coupon.forEach(item=>{
								let obj = {
									id:item.id,
									num:item.amount/100,
									title:item.name,
									cover:this.$http + item.cover,
									manPrice:item.condition/100,
									startTime:item.begin_at.slice(0,10),
									endTime:item.end_at.slice(0,10),
									get:item.get,
									type:item.type,
									unit:item.unit
								}
								this.dataList.push(obj);//渲染的列表
								this.zcList.push(obj);//暂存的列表
							})
						}
					}
				})
			},
			useEv(id){
				this.$requst.post('user/get-coupon',{coupon_id:id}).then(res=>{
					if(res.code==0){
						this.$toolAll.tools.showToast('领取成功');
						this.checkAllList(this.groupId);
					} else {
						this.$toolAll.tools.showToast(res.msg);
					}
				})
			},
		}
	}
</script>

<style>
	.isWen{color: #3875F6;}
	.isWen::after{
		content: '';
		display: block;
		height: 8rpx;
		width: 100%;
		position: absolute;
		bottom: -20rpx;
		background: #3875F6;
	}
</style>