<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">
            <!-- 营业执照 -->
            <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">{{ form.enterpriseName || '--' }}</div>
            </div>

            <!-- 统一社会信用代码 -->
            <div class="detail-item">
                <div class="item-label">统一社会信用代码</div>
                <div class="item-value">{{ form.enterpriseCode || '--' }}</div>
            </div>

            <!-- 注册资本 -->
            <div class="detail-item">
                <div class="item-label">注册资本</div>
                <div class="item-value">{{ form.registeredCapital || '--' }}</div>
            </div>

            <!-- 成立日期 -->
            <div class="detail-item">
                <div class="item-label">成立日期</div>
                <div class="item-value">{{ form.establishedDate || '--' }}</div>
            </div>

            <!-- 营业期限 -->
            <div class="detail-item">
                <div class="item-label">营业期限</div>
                <div class="item-value">{{ form.businessTerm || '--' }}</div>
            </div>

            <!-- 住所 -->
            <div class="detail-item">
                <div class="item-label">住所</div>
                <div class="item-value">{{ form.residence || '--' }}</div>
            </div>

            <!-- 经营范围 -->
            <div class="detail-item">
                <div class="item-label">经营范围</div>
                <div class="item-value">{{ form.businessScope || '--' }}</div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name: 'BasicInfoDetail',
    props: {
        detailData: {
            type: Object,
            default: () => { }
        }
    },
    data() {
        return {
            form: {
                enterpriseName: '',
                enterpriseCode: '',
                registeredCapital: '',
                establishedDate:'',
                businessTerm: '',
                residence: '',
                businessScope: '',
                url:null
            }
        }
    },
    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].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;
                cursor: pointer;
            }
        }
    }
}
</style>