<template>
	<view>
		<u-navbar :placeholder="true" bgColor="#fff" :autoBack="true" :border="true" title="优惠券详情"></u-navbar>
		<view class="detail">
			<!-- 优惠券信息 -->
			<view class="flex detail-item">
				<!-- <image src="../../static/icon/coupon.png" mode=""></image>
				<view class="flex info">
					<view class="flex desc">
						<view class="title">{{ info.title }}</view>
						<view class="txt">使用期限：{{ $parseTime(info.validStart, '{y}.{m}.{d}') }}-{{ $parseTime(info.validEnd, '{y}.{m}.{d}') }}</view>
						<view class="txt">使用范围：{{ info.useAreaDesc || '-' }}</view>
					</view>
					<view class="flex btn">
						<view class="amt"><text>￥</text>{{ info.discount / 100 }}</view>
					</view>
				</view> -->
				<view class="content flex">
					<view class="content-left flex">
						<image src="../static/prize_coupon.png" mode=""></image>
						<view class="price flex">
							<text>{{ info.discount / 100 }}</text>
							<text>元</text>
						</view>
					</view>
					<view class="content-right flex">
						<view class="title ells-one">{{ info.title }}</view>
						<view class="desc">适用范围：{{ info.useAreaDesc || '-' }}</view>
						<view class="desc">使用期限：{{ $parseTime(info.validStart, '{y}.{m}.{d}') }} ~ {{ $parseTime(info.validEnd, '{y}.{m}.{d}') }}</view>
					</view>
				</view>
			</view>
			
			<!-- 间隔 -->
			<view class="detail-interval flex">
				<view class="detail-interval__left"></view>
				<view class="detail-interval__line"></view>
				<view class="detail-interval__right"></view>
			</view>
				
			<!-- 二维码 -->
			<view class="flex detail-code" v-if = "info && info.useArea && JSON.parse(info.useArea).value  != 4">
				<canvas style="width: 220px;height: 220px;" canvas-id="couponQrcode"></canvas>
			</view>
			
			<!-- 说明 -->
			<view class="detail-explain">
				<view class="txt">使用说明：</view>
				<view class="txt">{{ info.description }}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import $http from '@/utils/request.js'
	const qrCode = require('@/common/weapp-qrcode.js')
	export default {
		data() {
			return {
				info: {},
				id: null,
			};
		},
		onLoad(options) {
			this.id = options.id
			this.getDetail()
		},
		methods: {
			getDetail() {
				uni.showLoading({
					title: '加载中'
				});
				$http.post('/api/v1/mp/user/mine/coupon/detail', {
					id: this.id
				}).then(res => {
					uni.hideLoading();
					if (res.code == 0) {
						this.info = res.data
						setTimeout(() => {
							uni.hideLoading();
							this.couponQrCode()
						}, 50)
					}
				}).catch(() => {
					uni.hideLoading();
				})
			},
			// 二维码生成工具
			couponQrCode() {
				new qrCode('couponQrcode', {
					text: this.info.verifyCode,
					width: 213,
					height: 213,
					colorDark: "#333333",
					colorLight: "#FFFFFF",
					correctLevel: qrCode.CorrectLevel.H
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.detail {
		margin: 20rpx;
		background-color: #FFFFFF;
		border-radius: 10rpx;
		overflow: hidden;
		
		// 优惠券信息
		&-item {
			padding: 30rpx 0 30rpx;
			background-color: #fff;
			
			.content {
				width: 100%;
				height: 184rpx;
				justify-content: flex-start;
				
				&-left {
					width: 210rpx;
					height: 100%;
					margin-right: 20rpx;
					
					image {
						width: 100%;
						height: 100%;
					}
					
					.price {
						position: absolute;
						color: #fff;
						
						text:first-child {
							font-size: 70rpx;
							padding-right: 20rpx;
						}
						
						text:last-child {
							font-size: 40rpx;
						}
					}
				}
				
				&-right {
					flex: 1;
					align-items: flex-start;
					flex-direction: column;
					justify-content: space-between;
					height: 100%;
					padding: 24rpx 0;
					
					.title {
						font-size: 32rpx;
						line-height: 32rpx;
						height: 32rpx;
						overflow: hidden;
						font-weight: bold;
					}
					
					.desc {
						font-size: 24rpx;
						line-height: 24rpx;
						color: #999999;
					}
				}
			}
		}

		// 间隔
		&-interval {
			position: relative;
			width: 100%;
			height: 30rpx;
			margin-bottom: 10rpx;
			
			&__left {
				position: absolute;
				left: -15rpx;
				width: 30rpx;
				height: 30rpx;
				background: #F9F7F5;
				border-radius: 50%;
			}
			
			&__line {
				height: 1px;
				background-color: #F9F7F5;
				width: 90%;
			}
			
			&__right {
				position: absolute;
				right: -15rpx;
				width: 30rpx;
				height: 30rpx;
				background: #F9F7F5;
				border-radius: 50%;
			}
		}
		
		// 二维码
		&-code {
			width: 100%;
			height: 460rpx;
			margin-bottom: 20rpx;
		}
		
		// 说明
		&-explain {
			font-size: 26rpx;
			padding: 0 34rpx 34rpx;

			.txt {
				line-height: 40rpx;
			}
		}
	}
</style>
