<template>
    <view class="coupon-item" :class="{ 'used': coupon.status === '1', 'expired': coupon.status === '2' }">
        <!-- 左侧金额 -->
        <view class="coupon-left">
            <view class="coupon-amount">
                <text class="currency">¥</text>
                <text class="number">{{  Number(coupon.discount) }}</text>
            </view>
        </view>

        <!-- 中间信息 -->
        <view class="coupon-middle">
            <view class="coupon-type">{{ coupon.couponId_dictText }}</view>
            <view class="coupon-validity">{{ coupon.validDate }} 前有效</view>
        </view>

        <!-- 右侧使用按钮 -->
        <view class="coupon-right">
            <view class="use-btn" @click="useCoupon" v-if="coupon.status === '0'">
                <text>立即</text>
                <text>使用</text>
            </view>
            <view class="use-btn" v-if="coupon.status === '1'">
                <text>已使用</text>
            </view>
            <view class="use-btn" v-if="coupon.status === '2'">
                <text>已过期</text>
            </view>
        </view>

        <!-- 装饰元素 -->
        <view class="coupon-left-dot"></view>
        <view class="coupon-right-dot"></view>

        <!-- Logo -->
        <!-- <image src="/static/image/logo.png" class="logo-image"></image> -->
    </view>
</template>

<script>
export default {
    name: 'CouponItem',
    props: {
        coupon: {
            type: Object,
            default: () => ({
                couponId: '',
                discount: 0,
                couponId_dictText: '新人专享优惠券',
                validDate: '2025/4/12 23:59',
                status: "0" // 0-未使用 1-已使用 2-已过期
            })
        }
    },
    methods: {
        useCoupon() {
            this.$emit('use', this.coupon)
        }
    }
}
</script>

<style lang="scss" scoped>
.coupon-item {
    position: relative;
    width: 100%;
    height: 160rpx;
    background-color: #fff;
    display: flex;
    border-radius: 16rpx;
    margin-bottom: 30rpx;
    overflow: hidden;
    box-shadow: 0 4rpx 8rpx rgba(0, 0, 0, 0.05);

    &::before {
        content: '';
        position: absolute;
        left: 0;
        top: 0;
        width: 20rpx;
        height: 100%;
        background-color: $uni-color;
        border-radius: 16rpx 0 0 16rpx;
    }

    &.used,
    &.expired {
        opacity: 0.6;
    }

    .coupon-left {
        width: 200rpx;
        display: flex;
        align-items: center;
        justify-content: center;
        background-color: #f9f9f9;
        position: relative;

        .coupon-amount {
            display: flex;
            align-items: baseline;
            color: $uni-color;

            .currency {
                font-size: 36rpx;
                font-weight: bold;
            }

            .number {
                font-size: 80rpx;
                font-weight: bold;
                line-height: 1;
            }
        }
    }

    .coupon-middle {
        flex: 1;
        padding: 20rpx 20rpx 20rpx 30rpx;
        display: flex;
        flex-direction: column;
        justify-content: center;

        .coupon-type {
            font-size: 28rpx;
            color: #333;
            margin-bottom: 16rpx;
            font-weight: bold;
        }

        .coupon-validity {
            font-size: 24rpx;
            color: #999;
        }
    }

    .coupon-right {
        width: 120rpx;
        display: flex;
        align-items: center;
        justify-content: center;

        .use-btn {
            width: 80rpx;
            height: 80rpx;
            background-color: $uni-color;
            border-radius: 50%;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            color: #fff;
            font-size: 24rpx;
            font-weight: bold;
        }

        .status-image {
            width: 80rpx;
            height: 80rpx;
        }
    }

    .coupon-left-dot,
    .coupon-right-dot {
        position: absolute;
        width: 30rpx;
        height: 30rpx;
        background-color: #f5f5f5;
        border-radius: 50%;
        z-index: 1;
    }

    .coupon-left-dot {
        left: 185rpx;
        top: -15rpx;
    }

    .coupon-right-dot {
        left: 185rpx;
        bottom: -15rpx;
    }

    .logo-image {
        position: absolute;
        width: 60rpx;
        height: 60rpx;
        right: 30rpx;
        top: 10rpx;
        opacity: 0.2;
    }
}
</style>