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

        <div class="detail-content">
            <el-row>
                <el-col :span="8">
                    <!-- 营业执照 -->
                    <FileOrImageDisplay label="营业执照" :file="form.fileList[0]" :image-url="form.url" />
                </el-col>
            </el-row>
            <el-row :gutter="24">
                <el-col :span="8">
                    <!-- 企业名称 -->
                    <DetailItem label="企业名称" :value="form.enterpriseName" />
                </el-col>
                <el-col :span="8">
                    <!-- 统一社会信用代码 -->
                    <DetailItem label="统一社会信用代码" :value="form.enterpriseCode" />
                </el-col>
                <el-col :span="8">
                    <!-- 注册资本 -->
                    <DetailItem label="注册资本" :value="form.registeredCapital" />
                </el-col>
            </el-row>
            <el-row :gutter="24">
                <el-col :span="8">
                    <!-- 成立日期 -->
                    <DetailItem label="成立日期" :value="form.establishedDate" />
                </el-col>
                <el-col :span="8">
                    <!-- 营业期限 -->
                    <DetailItem label="营业期限" :value="form.businessTerm" />
                </el-col>
                <el-col :span="8">
                    <!-- 住所 -->
                    <DetailItem label="住所" :value="form.residence" />
                </el-col>
            </el-row>
            <el-row :gutter="24">
                <el-col :span="24">
                    <!-- 经营范围 -->
                    <DetailItem label="经营范围" :value="form.businessScope" />
                </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: 'BasicInfoDetail',
    components: {
        FileOrImageDisplay,
        DetailItem
    },
    props: {
        detailData: {
            type: Object,
            default: () => { }
        }
    },
    data() {
        return {
            form: {
                enterpriseName: '',
                enterpriseCode: '',
                registeredCapital: '',
                establishedDate: '',
                businessTerm: '',
                residence: '',
                businessScope: '',
                url: null,
                fileList: []
            }
        }
    },
    methods: {
        setDetailData() {
            const fileList = this.getFileList('business_license');
            this.form = {
                enterpriseName: this.detailData.enterpriseName,
                enterpriseCode: this.detailData.enterpriseCode,
                registeredCapital: this.detailData.registeredCapital,
                establishedDate: this.detailData.establishedDate,
                businessTerm: this.detailData.businessTerm,
                residence: this.detailData.residence,
                businessScope: this.detailData.businessScope,
                url: fileList[0]?.fileType === '1' ? fileList[0]?.lsFilePath : null,
                fileList: fileList,
            }
        },
        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>