<template>
    <div class="basic-info-detail">
        <div class="basic-info-title">
            <img src="@/assets/enterpriseLibrary/legalperson.png" alt="法人信息">
            <span>法人信息</span>
        </div>

        <div class="detail-content">
            <!-- 身份证人像面 -->
            <div class="detail-item">
                <div class="item-label">身份证人像面</div>
                <div class="item-value">
                    <el-image :src="form.url" class="license-image">
                    </el-image>
                </div>
            </div>
            <!-- 身份证国徽面 -->
            <div class="detail-item">
                <div class="item-label">身份证国徽面</div>
                <div class="item-value">
                    <el-image :src="form.url2" class="license-image">
                    </el-image>
                </div>
            </div>
            <!-- 法人姓名 -->
            <div class="detail-item">
                <div class="item-label">法人姓名</div>
                <div class="item-value">{{ form.legalPersonName || '--' }}</div>
            </div>

            <!-- 法人身份证号 -->
            <div class="detail-item">
                <div class="item-label">法人身份证号</div>
                <div class="item-value">{{ form.legalPersonIdCard || '--' }}</div>
            </div>

            <!-- 身份证有效期 -->
            <div class="detail-item">
                <div class="item-label">身份证有效期</div>
                <div class="item-value">{{ form.idCardStartDate || '--' }}</div>
            </div>

            <!-- 法人职务 -->
            <div class="detail-item">
                <div class="item-label">法人职务</div>
                <div class="item-value">{{ form.legalPersonPosition || '--' }}</div>
            </div>

            <!-- 法人联系方式 -->
            <div class="detail-item">
                <div class="item-label">法人联系方式</div>
                <div class="item-value">{{ form.legalPersonPhone || '--' }}</div>
            </div>

        </div>
    </div>
</template>

<script>
export default {
    name: 'LegalPersonDetail',
    props: {
        detailData: {
            type: Object,
            default: () => { }
        }
    },
    data() {
        return {
            form:{
                legalPersonName:'',
                legalPersonIdCard:'',
                idCardStartDate:'',
                legalPersonPosition:'',
                legalPersonPhone:'',
                url:null,
                url2:null,
            }
        }
    },
    methods: {
        setDetailData() {
            const fileList = this.getFileList('face_id_card_portrait')
            const fileList2 = this.getFileList('national_emblem_id_card')
            this.form = {
                legalPersonName: this.detailData.legalPersonName,
                legalPersonIdCard: this.detailData.legalPersonIdCard,
                idCardStartDate: this.detailData.idCardStartDate,
                legalPersonPosition: this.detailData.legalPersonPosition,
                legalPersonPhone: this.detailData.legalPersonPhone,
                url:fileList[0].lsFilePath,
                url2:fileList2[0].lsFilePath,
            }
        },
        getFileList(businessType){
            return this.detailData.fileList.filter(item => item.businessType === businessType).map(item => {
                return {
                    name: item.fileName,
                    filePath: item.filePath,
                    lsFilePath:item.lsFilePath,
                    fileType:item.fileType
                };
            });
        }
    },
    watch: {
        detailData: {
            handler(newVal) {
                if (Object.keys(newVal).length > 0) {
                    this.setDetailData();
                }
            },
            immediate: true, // 立即执行一次
            deep: true
        }
    },
}
</script>

<style scoped lang="scss">
.basic-info-title {
    display: flex;
    align-items: center;
    margin: 10px 0;

    span {
        margin: 0 5px;
        font-size: 20px;
    }
}

.detail-content {
    .detail-item {
        margin-bottom: 16px;
        .item-label {
            color: #424242;
            font-size: 18px;
            font-weight: 500;
            margin-bottom: 8px;
        }

        .item-value {
            color: #424242;
            font-size: 16px;
            line-height: 1.5;

            .license-image {
                max-width: 200px;
                max-height: 120px;
                border-radius: 6px;
                box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
                object-fit: cover;
            }
        }
    }
}
</style>