<template>
	<view class="c-coupon" v-if="goodsClass.length" @click="use">
		<view :class="couponInfo.voucher_state != 1 ? 'coupon-unable' : 'coupon-usable'" :style="{'width': type ? '650rpx' : '' }">
			<view class="info-type" :style="{ backgroundImage: 'url(' + (couponInfo.voucher_state == 1 ? '/static/image/mine/30.png' : '/static/image/mine/31.png') + ')', backgroundSize:'contain', backgroundRepeat: 'no-repeat' }">
				<div class="wrap_left_top" v-if="couponInfo.type == 1">{{ couponInfo.vouchertemplate_id == 1 ? '新人专享' : '平台优惠券' }}</div>
				<div class="wrap_left_top" v-else-if="couponInfo.type == 2">店铺优惠券</div>
			</view>
			<view class="coupon-info">
				<view class="info-usable">
					<view class="price">￥<span>{{ couponInfo.voucher_price }}</span></view>
					<view class="condition">满{{ couponInfo.voucher_limit }}使用</view>
				</view>
				<view class="info-store u-line-1">仅限{{ couponInfo.type == 1 ? '指定商品' : couponInfo.store_name }}{{ couponInfo.gc_id | showClass(goodsClass) }}商品使用</view>
				<view class="info-integral">兑换积分：{{ couponInfo.voucher_points }}积分</view>
				<view class="info-date">有效期{{ couponInfo.voucher_startdate }}-{{ couponInfo.voucher_enddate }}</view>
			</view>
			<view class="coupon-btn" :style="{'right': type ? '110rpx' : '' }">
				<text v-if="couponInfo.voucher_state == 1">立即使用</text>
				<image v-if="couponInfo.voucher_state == 2" src="/static/image/mine/28.png"></image>
				<image v-if="couponInfo.voucher_state == 3" src="/static/image/mine/29.png"></image>
			</view>
		</view>
		<image v-if="type" style="width:35rpx;height:35rpx;margin-left:14rpx;" :src="'/static/image/mine/' + (sel ? '41.png' : '42.png') "></image>
	</view>
</template>
<script>
/**
 * coupon 领取的优惠券 自己的优惠券
 * @description 优惠券组件
 * @property {Object} coupon-info 优惠券信息
 * @event {Function} use 使用优惠券
 */
export default {
	data() {
		return {}
	},
	props: {
		status: Number,
		couponInfo: Object,
		goodsClass: Array,
		type:Boolean,
		sel:Boolean
	},
	created() {
		// console.log(this.goodsClass);
		// console.log(this.couponInfo);
	},
	filters: {
		showClass(value, classList) {
			const ids = classList.filter(element => {
				return element.gc_id == value;
			});
			// console.log(ids);
			return ids.length ? ids[0].gc_name : '';
		}
	},
	methods: {
		use() {
			if(this.couponInfo.voucher_state != 1) return;
			this.$emit('use', this.couponInfo);
		},
	},
};
</script>
<style lang="scss" scoped>
.c-coupon {
	position: relative;
	z-index: 9;
	margin-bottom: 30rpx;
	display: flex;
	align-items: center;
	@mixin coupon-image($url) {
		width: 690rpx;
		height: 194rpx;
		background: url($url) no-repeat left top / contain;
		color: #FFFFFF;
		.info-type {
			width: 150rpx;
			height: 30rpx;
			line-height: 30rpx;
			font-size: 20rpx;
			border-radius: 10rpx 0rpx 10rpx 0rpx;
			padding-left: 25rpx;
			margin-bottom: 6rpx;
		}
		.coupon-info {
			z-index: 10;
			position: absolute;
			top: 36rpx;
			left: 0;
			font-weight: 500;
			padding-left: 20rpx;
			width: 360rpx;
			.info-usable{
				margin-bottom: 6rpx;
				display: flex;
				align-items: center;
				.price {
					margin-right: 16rpx;
					font-size: 40rpx;
					> span {
						font-size: 50rpx;
					}
				}
				.condition {
					font-size: 24rpx;
				}
			}
			.info-store{
				margin-bottom: 10rpx;
				font-size: 22rpx;
			}
			.info-integral{
				margin-bottom: 10rpx;
				font-size: 22rpx;
			}
			.info-date{
				font-size: 20rpx;
			}
		}
		.coupon-btn {
			z-index: 10;
			position: absolute;
			right: 60rpx;
			top: 50%;
			transform: translate(0, -50%);
			> text {
				font-size: 32rpx;
				font-weight: 500;
				color: rgba(255,255,255,1);
				position: relative;
				// 增大按钮点击范围
				&::after {
					content:"";
					position: absolute;
					top: -30rpx;
					left: -40rpx;
					width: 200rpx;
					height: 100rpx;
				}
			}
			> image {
				width: 122rpx;
				height: 122rpx;
			}
		}
	}
	.coupon-usable {
		@include coupon-image('/static/image/mine/26.png');
	}
	.coupon-unable {
		@include coupon-image('/static/image/mine/27.png');
	}
}
</style>