<template>
    <view class="new-user-coupon" v-if="showPopup">
        <view class="mask" @click="closePopup"></view>
        <view class="coupon-container">
            <view class="coupon-content">
                <view style="position: relative;">
                    <image class="coupon-image"
                    style="height: 800rpx;"
                    src="http://wxa.mp.video.tencent-cloud.com/271/20304/stodownload?m=e32f5f803d62036cc76c2de769355081&filekey=30340201010420301e0202010f040253480410e32f5f803d62036cc76c2de76935508102020d9e040d00000004627466730000000132&hy=SH&storeid=2689416ee0007c1f4000000000000010f00004f50534805aab171568b33d14&bizid=1023"
                    mode="aspectFill"></image>

                    <image 
                    style="width: 280rpx;height: 70rpx;
                    position: absolute;
                    left: 50%;
                    top: 20rpx;
                    transform: translate(-50%, 0%);"
                    mode="aspectFill"
                    src="https://image.hhlm1688.com/2025/08/07767f2fc0a686433bb9e3f90bc6e60990Group%201000001612@3x.png"/>

                    <image class="coupon-image"
                        style="position: absolute;left: 50%;top: 50%;
                        width: 80%;
                        transform: translate(-50%, -50%);"
                        :src="NewUserCoupon.couponPoster || image"
                        mode="widthFix"></image>
                </view>
                <view class="coupon-btn" @click="getCoupon">立即领取</view>
            </view>
            <view class="close-btn" @click="closePopup">
                <text class="close-icon">×</text>
            </view>
        </view>
    </view>
</template>

<script>
import { getToken } from '@/utils/auth'
import { mapState } from 'vuex'

export default {
    name: 'NewUserCoupon',
    data() {
        return {
            showPopup: true,
            image : 'https://img.teyizhao.com/2025-08-07/a7535f42-6726-4630-9552-6940331ddb8b.png',
        }
    },
    computed : {
        ...mapState(['NewUserCoupon']),
    },
    methods: {
        closePopup() {
            this.showPopup = false
            this.$emit('close')
        },
        getCoupon() {
            // 检查用户是否已登录
            if (!getToken() || !this.userInfo.phone) {

                // 未登录，跳转到登录页面
                uni.navigateTo({
                    url: '/pages_order/auth/login?url=/pages_order/newUser/index'
                })
            } else {
                // 已登录，跳转到新用户优惠券页面
                this.closePopup()
                uni.navigateTo({
                    url: '/pages_order/newUser/index'
                })
            }
        }
    }
}
</script>

<style lang="scss">
.new-user-coupon {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;

    .mask {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.6);
    }

    .coupon-container {
        position: relative;
        width: 560rpx;
        z-index: 1000;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .coupon-content {
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .coupon-image {
        width: 560rpx;
        border-radius: 20rpx;
    }

    .coupon-btn {
        position: relative;
        margin-top: -100rpx;
        width: 300rpx;
        height: 80rpx;
        background: #FFB13F;
        color: #FFFFFF;
        font-size: 32rpx;
        font-weight: bold;
        border-radius: 40rpx;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .close-btn {
        position: relative;
        margin-top: 40rpx;
        width: 60rpx;
        height: 60rpx;
        background: rgba(255, 255, 255, 0.8);
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;

        .close-icon {
            color: #666;
            font-size: 40rpx;
            font-weight: bold;
        }
    }
}
</style>