<template>
	<view class="coupon-list">
		<view class="coupon-box" v-for="item in list" :key="item.id" @click="checked(item)">
			<view class="coupon-head">
				<view class="coupon-sel coupon-checked" v-if="item.checked"></view>
				<view class="coupon-sel" v-else></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>
	</view>
</template>

<script>
	export default{
		name: 'couponTpl',
		props: {
			showCheck: {
				type: Boolean,
				default: false
			},
			list:{
				type: Array,
				default: function(){
					return []
				}
			}
		},
		methods: {
			// 选中优惠卷
			checked(item) {
				if(this.showCheck){
					let has = this.list.find(item=>item.checked)
					if(has){
						has.checked = false
					}
					item.checked = true
					this.$emit('checkOk',item)
				}
			},
		},
	}
</script>

<style lang="scss">
	.coupon-list{
		padding: 25rpx;
	}
	.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>
