<template>
	<u-popup mode="bottom" border-radius="20" :popup="false" v-model="show" :maskCloseAble="true" length="auto"
	 :safeAreaInsetBottom="true" @close="popupClose" :z-index="9999" close-icon="cross" :closeable="true">
		<view class="course">
			<scroll-view :scroll-y="true" style="max-height: 70vh;"> 
			<view class="title">套餐卡</view>
			<view class="chosentips">请选择要使用的套餐卡</view>
			<view class="details">
				<view class="item" v-for="(x, i) in ts" :key="i" :style="{'margin-bottom':ts.length==i+1?'50px':'10px'}">
					<view class="ticket">
						<image mode="aspectFill" :src="x.coupon_data.couponIco" style="width: 100%; height: 100%;border-top-left-radius: 5px;border-bottom-left-radius: 5px;"></image>
					</view>
					<view class="detail">
						<view class="coupond">
							<view class="name">{{x.coupon_data.name}}</view>
							<view class="rule">{{x.coupon_data.rule}}</view>
							<view class="date">{{x.start_time+"-"+x.end_time}}</view>

						</view>
						<view class="chosen">
							<u-radio-group v-model="currentChosen">
								<u-radio shape="circle" :name="x.id" :icon-size="36" :active-color="mc"></u-radio>
							</u-radio-group>
						</view>
					</view>
				</view>
			</view>
			</scroll-view>
			<view class="btton-box">
				<u-button size="80" :ripple="true" shape="circle" :custom-style="{
            backgroundColor: mc,
            height: '80rpx',
            color: '#FFF',
            fontSize: '14px',
            margin: '0 3vw',
            width: '90vw',
          }"
				 @click="popupClose">确定</u-button>
			</view>
		</view>
	</u-popup>
</template>

<script>
	export default {
		props: ["list", "current"],
		data() {
			return {
				mc: "",
				show: true,
				currentChosen: "",
				ts: []
			};
		},
		mounted() {
			this.mc = this.$uiConfig.mainColor;
			this.currentChosen = this.current;
			this.ts = this.list
			this.ts.forEach(x => {
				x.start_time = x.start_time.split(' ')[0].replace(/-/g, '.')
				x.end_time = x.end_time.split(' ')[0].replace(/-/g, '.')
			})
		},
		methods: {
			popupClose() {
				if (this.currentChosen != this.current) {
					this.$emit('close', this.currentChosen)
				} else {
					this.$emit('close', -1)
				}
			},
		},
	};
</script>

<style>
	.course {
		max-height: 70vh;
		background: #f5f5f5;
		/* padding-bottom: 50px; */
		text-align: left !important;
		border-top-left-radius: 20rpx;
		border-top-right-radius: 20rpx;
		/* overflow: scroll; */
		overflow: hidden;
	}

	.course .title {
		font-size: 22px;
		color: #000;
		padding: 20px;
		background: #fff;
	}

	.course .chosentips {
		padding: 12px 20px;
		border-bottom: 1px solid #f5f5f5;
		border-top: 1px solid #f5f5f5;
		color: #777;
		background: #fff;
		font-size: 12px;
	}

	.course .details {
		padding: 10px;
		display: flex;
		flex-direction: column;
	}

	.course .details .item {
		display: flex;
		margin-bottom: 10px;
		align-items: flex-start;
		background: #fff;
		border-radius: 5px;
		box-shadow: 0 4px 6px 1px rgba(76, 76, 76, 0.1);
	}

	.course .details .item .ticket {
		width: 104px;
		height: 78px;
	}

	.course .details .item .detail {
		width: 1px;
		flex: 1;
		background: #fff;
		padding: 10px;
		display: flex;
		align-items: center;
	}

	.course .details .item .detail .coupond {
		flex: 1;
	}

	.course .details .item .detail .coupond .name {
		font-size: 13px;
		font-weight: 600;
		color: #000;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical;
	}

	.course .details .item .detail .coupond .date {
		margin-top: 5px;
		font-size: 11px;
		color: #777;
	}

	.course .details .item .detail .coupond .rule {
		font-size: 11px;
		color: #777;
		margin-top: 5px;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical;
	}

	.course .details .item .detail .chosen {
		width: 20px;
	}
</style>
