<template>
	<view class="coupon-list">
		<view v-for="(item,index) in couponData" style="padding:20rpx;" :key="index">
			<view>
				<view class="card">
					<view class="card-left">{{switchType(item.stockType)}}</view>
					<view class="card-center">
						<view class="card-center-top"></view>
						<view class="card-center-bottom"></view>
					</view>
					<view class="card-right">
						<view class="card-content">
							<view class="card-info">{{item.stockName}}</view>
							<view class="card-type">可用于
								<text class="card-type-text">专业喂养</text>
								<text class="card-type-text">专业遛狗</text>
							</view>
							<view class="card-time">有效期至: {{item.availableEndTime.slice(0, 16)}}</view>
						</view>
						<!-- <view style="width: 22%;">
							<u-button @click="receiveCoupon(item.id)" shape="circle" size="mini" color="#ffaa48" text="立即领取"></u-button>
						</view> -->
						<view style="width: 132rpx;height: 52rpx;background-color: #FFAA48; display: flex;align-items: center;justify-content: center;border-radius: 56rpx;">
							<text @click="receiveCoupon(item.id)" style="font-size: 24rpx; font-weight: 500; color: #FFFFFF;">立即领取</text>
						</view>
					</view>
				</view>
				<view class="card-bottom">
					<view class="card-bottom-text">
						优惠券不可兑换现金
					</view>
					<view class="card-bottom-text">
						查看详细规则>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		getCouponList,
		receiveCoupon,
	} from "@/api/system/user"
	export default {
		data() {
			return {
				couponData: [],
			}
		},
		onLoad() {
			// this.openIdStr = this.$globalData.openIdStr;
			this.getCouponListAuth()
		},
		methods: {
			getCouponListAuth() {
				getCouponList().then(res => {
					if (res.code == 200) {
						this.couponData = res.data
						console.log("this.couponData", this.couponData)
					} else {
						this.$modal.showToast('获取优惠券失败')
					}
				})
			},
			switchType(type) {
				if (type == 'PNORMAL') {
					return '满减券'
				}
				if (type == 'PDISCOUNT') {
					return '折扣券'
				}
				if (type == 'PTRAIL') {
					return '体验券'
				}
				return '优惠券'
			},
			receiveCoupon (id) {
				let data = {
					stockId: id
				}
				receiveCoupon(data).then(res => {
					console.log("this.receiveCoupon", res)
					if (res.code == 200) {
						this.$modal.showToast('优惠券领取成功')
					} else {
						this.$modal.showToast('领取优惠券失败')
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.coupon-list {
		.card {
			display: flex;
			align-items: center;
			width: 100%;
			padding: 10px 0;
			background: #fff;
			border-radius: 8px 8px 0 0;
		}
		
		.card-bottom {
			display: flex;
			background-color: #FFF1E0;
			height: 50rpx;
			align-items: center;
			justify-content: space-between;
			padding: 0 20rpx 0 20rpx;
			border-radius: 0 0 8px 8px;
		
			.card-bottom-text {
				color: #AAAAAA;
				font-size: 24rpx;
				font-weight: 400;
			}
		}

		.card-left {
			width: 88px;
			text-align: center;
			color: #FF530A;
			font-size: 28rpx;
			font-weight: 900;
		}
		
		.card-center {
			display: flex;
			flex-direction: column;
			// align-items: center;
		
			.card-center-top {
				width: 40rpx;
				height: 20rpx;
				border-radius: 0 0 20rpx 20rpx;
				background-color: #F5F5F7;
				line-height: 20rpx;
				// border-bottom: 1px solid #FDA714;
				// border-left: 1px solid #FDA714;
				// border-right: 1px solid #FDA714;
				margin-top: -22rpx;
				margin-bottom: 20rpx;
				margin-left: -19rpx;
			}
		
			.card-center-bottom {
				border-right: 1px dashed #AAAAAA;
				width: 1px;
				height: 120rpx;
			}
		}

		.card-right {
			padding: 0px 12px;
			display: flex;
			flex: 1;
			/* flex-direction: column; */
			justify-content: space-between;
			align-items: center;
			height: 60px;

			.card-content {
				width: 77%;
			}

			.card-icon {
				position: relative;
				right: -10px;
				top: -10px;
			}
		}

		.card-info {
			margin: 0;
			font-size: 28rpx;
			line-height: 28rpx;
			color: #333333;
			font-weight: 500;
		}
		
		.card-type {
			font-size: 24rpx;
			font-weight: 400;
			line-height: 24rpx;
			font-weight: 400;
			color: #AAAAAA;
			margin-top: 10rpx;
		
			.card-type-text {
				color: #FFAA48;
				font-size: 24rpx;
				font-weight: 400;
				line-height: 24rpx;
				border: #FFAA48 1px solid;
				border-radius: 7rpx;
				margin-left: 8rpx;
			}
		}

		.card-time {
			font-size: 24rpx;
			font-weight: 400;
			line-height: 24rpx;
			font-weight: 400;
			color: #AAAAAA;
			margin-top: 10rpx;
		}
	}
</style>