<template>
	<view :class="[showCardNo ? `show-card-no ${adorn.cardClass}`:'']">
		<view :class="['card-box', adorn.bgClass]" :style="styles" @click.stop="onCard(cardInfo)">
			<view class="card-left">
				<view class="card-name">{{cardInfo.cardTypeName}}</view>
				<view class="card-title">
					<text class="card-title-name">面值:</text>
					<view class="card-money">
						<text class="card-money-tag">￥</text>
						<text class="card-money-num">{{cardInfo.currentAmount}}</text>
						<text class="card-money-tag">元</text>
					</view>
				</view>
			</view>
			<view class="card-right">
				<image class="card-icon" :src="adorn.icon" mode="aspectFit" />
				<view class="card-expire-time">
					到期时间：{{ adorn.validTime }}
					<!-- <text>到期时间：</text>
					<text>{{cardInfo.expireTime}}</text> -->
				</view>
			</view>
		</view>
		<view class="card-no" v-if="cardInfo.cardNo">
			No {{cardInfo.cardNo}}
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			showCardNo: {
				type: Boolean,
				default: false
			},
			styles: {
				type: Object,
				default: () => {}
			},
			cardInfo: {
				required: true,
				type: Object,
				default: () => {}
			}
		},
		data() {
			return {
				adorn: {
					bgClass: '',
					icon: '',
					cardClass: '',
					validTime:'',
				}
			}
		},
		watch: {
			cardInfo: {
				handler(newV, oldV) {
					this.getBg(newV || {})
				},
				immediate: true,
				deep: true
			}
		},
		methods: {
			getBg(cardInfo) {
				const { status } = cardInfo;
				switch (status) {
					// 未使用
					case 'ACTIVED':
						this.adorn = {
							bgClass: 'bg-01',
							icon: require("@/static/images/card_03.png"),
							cardClass: 'card_01',
							validTime:'长期有效'
						};
						break;
					case 'FROZEN':
					case 'EXPIRED':
						// 已停用 / 已过期
						this.adorn = {
							bgClass: 'bg-02',
							icon: require("@/static/images/card_03.png"),
							cardClass: 'card_02',
							validTime: status === 'FROZEN' ? '停用' : '已过期'
						};
						break;

				}
			},
			onCard(cardInfo) {
				this.$emit('onClickCard', cardInfo)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.card-box {
		width: 100%;
		min-height: 200rpx;
		display: flex;
		justify-content: space-between;
		align-items: stretch;
		padding: 29rpx 39rpx 28rpx;

		.card-right {
			flex-shrink: 0;
			display: flex;
			flex-direction: column;
			align-items: flex-end;

			.card-icon {
				width: 130.52rpx;
				height: 115.46rpx;
				margin-right: 40rpx;
			}

			.card-expire-time {
				padding-top: 17.5rpx;
				line-height: 1.2;
				font-size: 24rpx;
				font-family: PingFang SC, PingFang SC-Regular;
				font-weight: 400;
				text-align: left;
				color: #6c5b42;
				letter-spacing: -0.48px;
				display: flex;
				flex-direction: column;
				align-items: center;
			}
		}

		.card-left {
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			.card-name {
				font-size: 36rpx;
				font-family: PingFang SC, PingFang SC-Bold;
				font-weight: 700;
				color: #3f1c00;
			}

			.card-title {
				.card-title-name {
					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC-Regular;
					font-weight: 400;
					color: #4e2405;
				}

				.card-money {
					display: flex;
					align-items: flex-end;
					color: #e2403e;

					.card-money-tag {
						font-size: 22rpx;
					}

					.card-money-num {
						font-weight: bold;
						font-size: 30rpx;
						padding: 0 2px;
					}
				}
			}
		}
	}

	.card-no {
		display: none;
	}

	.show-card-no {
		border-radius: 20rpx;

		.card-no {
			display: block;
			width: 100%;
			padding: 20rpx 39rpx;
			color: #fff;
			font-size: 28rpx;
		}
	}


	.bg-01 {
		background: url("@/static/images/card_01.png") no-repeat center center;
		background-size: 100% 100%;
	}

	.bg-02 {
		background: url("@/static/images/card_02.png") no-repeat center center;
		background-size: 100% 100%;
	}

	.card_01 {
		background-color: #b99262;
	}

	.card_02 {
		background-color: #9f9f9f;
	}
</style>