<template>
	<view class="coupon-list">
		<view class="coupon-box">
			<view class="coupon-head">
				<view class="coupon-sel"></view>
				<view class="coupon-title">
					<view class="coupon-title-1">满100减50</view>
				</view>
				<view class="coupon-price">
					￥<text>100</text>
				</view>
			</view>
			<view class="coupon-desc">
				<view><u-icon class="icon" size="30" name="clock"></u-icon> 有效期至：2020-05-12</view>
				<view><u-icon class="icon" size="30" name="info-circle"></u-icon> 优惠卷使用说明优惠卷使用说明优惠卷使用说明优惠卷使用说明</view>
			</view>
		</view>
		<u-button class="handleSubmit" type="error">确认领取</u-button>
	</view>
</template>

<script>
	import {couponData, receivesCoupon} from '@/api/coupon.js'
	export default{
		name: 'getCoupon',
		data () {
			return {
				couponInfo: {}, // 领取优惠券信息
			}
		},
		onLoad(options) {
			// 存储当前扫码的券码
			if (options.scene) {
				let scene = decodeURIComponent(options.scene);
				//&是我们定义的参数链接方式
				let couponCode = scene;
				//其他逻辑处理。。。。。
				this.$store.state.vuex_couponCode = couponCode
				// 获取要领取的优惠券
				this.getCoupon(couponCode)
			} else {
				// 判断是否扫码过
				if (this.$store.state.vuex_couponCode != '') {
					let couponCode = this.$store.state.vuex_couponCode
					this.getCoupon(couponCode)
				} else {
					// 返回首页
					uni.reLaunch({
						url: "/pages/index/index"
					})
				}
			}
		},
		methods: {
			// 获取要领取的优惠券
			getCoupon (code) {
				couponData({couponCode:code}).then(res=>{
					if (res.status == 200) {
						this.couponInfo = res.data
					}
				})
			},
			// 确认领取优惠券
			handleSubmit () {
				let couponCode = this.$store.state.vuex_couponCode
				receivesCoupon({couponCode:couponCode}).then(res =>{
					if (res.status == 200) {
						this.toashMsg('领取成功')
						setTimeout(()=>{
							uni.navigateTo({
								url: '/pages/coupon/index/index'
							})
						},500)
					}
				})
			}
			
		},
	}
</script>

<style lang="scss">
	.coupon-list{
		width: 100%;
		height: 100%;
		padding: 25rpx;
		.handleSubmit{
			width: 80%;
			margin-top: 40%;
		}
	}
	.coupon-box.diabled{
		background: #999;
	}
	.coupon-box{
		margin-bottom: 30rpx;
		border-radius: 15rpx;
		box-shadow: 2rpx 2rpx 10rpx #ddd;
		background: #ff0000;
		color: #FFFFFF;
		.coupon-head{
			display: flex;
			align-items: center;
			padding: 20rpx 30rpx;
			position: relative;
			border-bottom: 15rpx dotted #FFFFFF;
			margin-bottom: -8rpx;
			.coupon-sel{
				position: absolute;
				width: 56rpx;
				height: 46rpx;
				right: 0;
				top: 0;
			}
			.coupon-checked{
				background: url(/static/img/select.png) no-repeat center;
				background-size: 100% 100%;
			}
			.coupon-title{
				flex-grow: 1;
				font-size: 32rpx;
			}
			.coupon-price{
				padding: 0 15rpx;
				color: #FFFFFF;
				text{
					font-size: 60rpx;
				}
			}
		}
		.coupon-desc{
			padding: 10rpx 30rpx;
			color: #666;
			background: #FFFFFF;
			border-bottom-left-radius:10rpx;
			border-bottom-right-radius: 10rpx;
			>view{
				padding: 5rpx 0;
			}
			.icon{
				margin-right: 10rpx;
			}
		}
		
	}
</style>
