<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">
            <el-row :gutter="24">
                <el-col :span="8">
                    <!-- 身份证人像面 -->
                    <FileOrImageDisplay label="身份证人像面" :file="form.fileList[0]" :image-url="form.url" />
                </el-col>
                <el-col :span="8">
                    <!-- 身份证国徽面 -->
                    <FileOrImageDisplay label="身份证国徽面" :file="form.fileList2[0]" :image-url="form.url2" />
                </el-col>
            </el-row>
            <el-row :gutter="24">
                <el-col :span="8">
                    <!-- 法人姓名 -->
                    <DetailItem label="法人姓名" :value="form.legalPersonName" />
                </el-col>
                <el-col :span="8">
                    <!-- 法人身份证号 -->
                    <DetailItem label="法人身份证号" :value="form.legalPersonIdCard" />
                </el-col>
                <el-col :span="8">
                    <!-- 身份证有效期 -->
                    <DetailItem label="身份证有效期" :value="form.idCardStartDate" />
                </el-col>
            </el-row>

            <el-row :gutter="24">
                <el-col :span="8">
                    <!-- 法人职务 -->
                    <DetailItem label="法人职务" :value="form.legalPersonPosition" />
                </el-col>
                <el-col :span="8">
                    <!-- 法人联系方式 -->
                    <DetailItem label="法人联系方式" :value="form.legalPersonPhone" />
                </el-col>
            </el-row>
        </div>
    </div>
</template>

<script>
import FileOrImageDisplay from '@/views/common/FileOrImageDisplay.vue';
import DetailItem from '@/views/common/DetailItem.vue';
export default {
    name: 'LegalPersonDetail',
    props: {
        detailData: {
            type: Object,
            default: () => { }
        }
    },
    components: {
        FileOrImageDisplay,
        DetailItem
    },
    data() {
        return {
            form: {
                legalPersonName: '',
                legalPersonIdCard: '',
                idCardStartDate: '',
                legalPersonPosition: '',
                legalPersonPhone: '',
                url: null,
                url2: null,
                fileList: [],
                fileList2: [],
            }
        }
    },
    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]?.fileType === '1' ? fileList[0]?.lsFilePath : null,
                url2: fileList2[0]?.fileType === '1' ? fileList2[0]?.lsFilePath : null,
                fileList: fileList,
                fileList2: fileList2,
            }
        },
        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;
    }
}
</style>