<template>
    <view class="container">
        <!-- 自定义头部 -->
        <view class="custom-header">
            <view class="header-left" @click="navBack">
                <image class="back-icon" src="/static/icons/chevron_right_dark.svg" style="transform: rotate(180deg);"></image>
            </view>
            <text class="header-title">认证信息</text>
            <view class="header-right"></view>
        </view>
        <view class="header-placeholder"></view>

        <!-- 身份认证 -->
        <view class="card">
            <view class="section-header">
                <view class="orange-bar"></view>
                <text class="section-title">身份认证</text>
                <view class="tag-green">已认证</view>
            </view>
            <view class="info-row">
                <text class="label">真实姓名</text>
                <text class="value">{{ authInfo.realName || '未设置' }}</text>
            </view>
            <view class="info-row">
                <text class="label">证件号码</text>
                <text class="value">{{ maskIdCard(authInfo.idCard) || '未设置' }}</text>
            </view>
            <view class="id-card-row">
                <view class="id-card-box green-bg" v-if="authInfo.idCardFront">
                    <image class="id-card-img" :src="authInfo.idCardFront" mode="aspectFill"></image>
                    <view class="corner-tag">人像面</view>
                </view>
                <view class="id-card-box green-bg" v-else>
                    <text class="id-text">ID Front</text>
                    <view class="corner-tag">人像面</view>
                </view>
                <view class="id-card-box green-bg" v-if="authInfo.idCardBack">
                    <image class="id-card-img" :src="authInfo.idCardBack" mode="aspectFill"></image>
                    <view class="corner-tag">国徽面</view>
                </view>
                <view class="id-card-box green-bg" v-else>
                    <text class="id-text">ID Back</text>
                    <view class="corner-tag">国徽面</view>
                </view>
            </view>
        </view>

        <!-- 服务类型 -->
        <view class="card">
            <view class="section-header">
                <view class="orange-bar"></view>
                <text class="section-title">服务类型</text>
            </view>
            <view class="tags-row">
                <view class="service-tag" v-for="(type, index) in authInfo.serviceTypes" :key="index">{{ type }}</view>
                <text v-if="authInfo.serviceTypes.length === 0" class="empty-text">暂无服务类型</text>
            </view>
        </view>

        <!-- 资质证书 -->
        <view class="card">
            <view class="section-header">
                <view class="orange-bar"></view>
                <text class="section-title">资质证书</text>
            </view>
            
            <text class="sub-title">{{ authInfo.authQual ? '已认证' : '未认证' }}</text>
            <view class="cert-row">
                <view class="cert-box yellow-bg" v-for="(img, index) in authInfo.qualImages" :key="index">
                    <image class="cert-img" :src="img" mode="aspectFill"></image>
                </view>
                <text v-if="authInfo.qualImages.length === 0" class="empty-text">暂无资质证书</text>
            </view>
        </view>

        <!-- 修改按钮 -->
        <view class="bottom-btn-area">
            <button class="action-btn" @click="editAuth">修改认证信息</button>
            <text class="tips">修改认证信息需要重新审核，审核期间无法接单</text>
        </view>
    </view>
</template>

<script>
import { getAuthInfo } from '@/api/fulfiller'

export default {
    data() {
        return {
            authInfo: {
                realName: '',
                idCard: '',
                idCardFront: '',
                idCardBack: '',
                serviceTypes: [],
                authQual: '',
                qualImages: []
            }
        }
    },
    onLoad() {
        this.loadAuthInfo()
    },
    methods: {
        navBack() {
            uni.navigateBack({
                delta: 1
            });
        },
        async loadAuthInfo() {
            try {
                const res = await getAuthInfo()
                if (res.code === 200 && res.data) {
                    this.authInfo = {
                        realName: res.data.realName || '',
                        idCard: res.data.idCard || '',
                        idCardFront: res.data.idCardFrontUrl || '',
                        idCardBack: res.data.idCardBackUrl || '',
                        serviceTypes: res.data.serviceTypeList || [],
                        authQual: res.data.authQual,
                        qualImages: res.data.qualImageUrls || []
                    }
                }
            } catch (e) {
                console.error('加载认证信息失败', e)
                uni.showToast({ title: '加载失败', icon: 'none' })
            }
        },
        maskIdCard(idCard) {
            if (!idCard || idCard.length < 8) return idCard
            return idCard.substring(0, 4) + '**********' + idCard.substring(idCard.length - 4)
        },
        editAuth() {
            uni.showToast({ title: '跳转修改认证页', icon: 'none' });
        }
    }
}
</script>

<style>
page {
    background-color: #F8F8F8;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}
.custom-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 88rpx;
    padding-top: var(--status-bar-height);
    background-color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-left: 30rpx;
    padding-right: 30rpx;
    box-sizing: content-box;
    z-index: 100;
}
.header-placeholder {
    height: calc(88rpx + var(--status-bar-height));
}
.back-icon {
    width: 40rpx;
    height: 40rpx;
}
.header-title {
    font-size: 28rpx;
    font-weight: bold;
    color: #333;
}
.header-right {
    width: 40rpx;
}

.container {
    padding: 20rpx 30rpx;
    padding-bottom: 100rpx;
}
.card {
    background-color: #fff;
    border-radius: 20rpx;
    padding: 30rpx;
    margin-bottom: 30rpx;
}
.section-header {
    display: flex;
    align-items: center;
    margin-bottom: 30rpx;
}
.orange-bar {
    width: 8rpx;
    height: 32rpx;
    background-color: #FF5722;
    border-radius: 4rpx;
    margin-right: 16rpx;
}
.section-title {
    font-size: 32rpx;
    font-weight: bold;
    color: #333;
    flex: 1;
}
.tag-green {
    font-size: 24rpx;
    color: #4CAF50;
    background-color: #E8F5E9;
    padding: 4rpx 12rpx;
    border-radius: 8rpx;
}

.info-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20rpx;
}
.label {
    font-size: 28rpx;
    color: #999;
}
.value {
    font-size: 28rpx;
    color: #333;
    font-weight: 500;
}

.id-card-row {
    display: flex;
    justify-content: space-between;
    margin-top: 20rpx;
}
.id-card-box {
    width: 48%;
    height: 180rpx;
    border-radius: 12rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}
.green-bg {
    background-color: #E8F5E9;
}
.id-text {
    font-size: 36rpx;
    color: #4CAF50;
    font-weight: bold;
}
.corner-tag {
    position: absolute;
    right: 0;
    bottom: 0;
    background-color: rgba(0,0,0,0.5);
    color: #fff;
    font-size: 20rpx;
    padding: 4rpx 10rpx;
    border-top-left-radius: 8rpx;
}

.tags-row {
    display: flex;
    flex-wrap: wrap;
}
.service-tag {
    background-color: #FFF3E0;
    color: #FF9800;
    font-size: 26rpx;
    padding: 10rpx 30rpx;
    border-radius: 30rpx;
    margin-right: 20rpx;
    margin-bottom: 20rpx;
}

.sub-title {
    font-size: 28rpx;
    color: #666;
    margin-top: 10rpx;
    margin-bottom: 20rpx;
    display: block;
}
.cert-row {
    display: flex;
    flex-wrap: wrap;
    margin-bottom: 20rpx;
}
.cert-box {
    width: 180rpx;
    height: 180rpx;
    border-radius: 12rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 20rpx;
    margin-bottom: 20rpx;
}
.yellow-bg { background-color: #FFF8E1; }
.blue-bg { background-color: #E3F2FD; }
.green-light-bg { background-color: #F1F8E9; }

.cert-text { font-size: 32rpx; font-weight: bold; }
.cert-text.orange { color: #FFA000; }
.cert-text.blue { color: #2196F3; }
.cert-text.green { color: #8BC34A; }

.id-card-img, .cert-img {
    width: 100%;
    height: 100%;
    border-radius: 12rpx;
}
.empty-text {
    font-size: 26rpx;
    color: #999;
}

.bottom-btn-area {
    margin-top: 40rpx;
    text-align: center;
}
.action-btn {
    background-color: #fff;
    color: #FF5722;
    border: 1px solid #FF5722;
    font-size: 32rpx;
    border-radius: 44rpx;
    height: 88rpx;
    line-height: 88rpx;
}
.tips {
    display: block;
    font-size: 24rpx;
    color: #999;
    margin-top: 20rpx;
}
</style>
