<template>
    <div class="edit-add-detail">
        <div v-loading="detailLoading" class="form-content" element-loading-text="加载中...">
            <div class="page-form">
                <!-- 主要内容区域 -->
                <div class="main-content">
                    <!-- 左侧菜单 -->
                    <div class="sidebar-menu">
                        <div class="menu-section">
                            <el-divider content-position="center">
                                <div class="menu-title">供应商信息</div>
                            </el-divider>
                            <div class="menu-items">
                                <div
                                    v-for="item in menuItems"
                                    :key="item.id"
                                    class="menu-item"
                                    :class="{ active: activeMenuItem === item.id }"
                                    @click="scrollToSection(item.id)"
                                >
                                    <span>{{ item.title }}</span>
                                    <el-icon :class="getSaveStatusClass(item.id)">
                                        <CircleCheck v-if="getSaveStatus(item.id)" />
                                        <CircleCheck v-else />
                                    </el-icon>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- 右侧内容区域 -->
                    <div class="content-area">
                        <el-form
                            ref="addEditFormRef"
                            :model="addEditForm"
                            :rules="addEditFormRules"
                            size="large"
                            label-position="left"
                            label-suffix="："
                        >
                            <el-collapse v-model="activeCollapse">
                                <!-- 准入申请信息 -->
                                <div
                                    v-if="hasMenuItem('access-application')"
                                    class="content-section"
                                    id="access-application"
                                >
                                    <div class="content-title">
                                        <div class="content-title-left">准入申请信息</div>
                                        <div class="content-title-right">
                                            <el-button type="primary" @click="handleSave('accessApplication')"
                                                >保存</el-button
                                            >
                                        </div>
                                    </div>
                                    <el-collapse-item name="access-application">
                                        <template #title>
                                            <div class="section-title">
                                                <el-icon><Document /></el-icon>
                                                <span>申请信息</span>
                                            </div>
                                        </template>
                                        <div class="section-content">
                                            <el-descriptions :column="2" border>
                                                <el-descriptions-item :span="2">
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        企业名称
                                                    </template>
                                                    <el-form-item prop="a">
                                                        <el-input
                                                            v-model="addEditForm.a"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item>
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        推荐人
                                                    </template>
                                                    <el-form-item prop="b">
                                                        <el-input
                                                            v-model="addEditForm.b"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item>
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        推荐单位
                                                    </template>
                                                    <el-form-item prop="c">
                                                        <el-input
                                                            v-model="addEditForm.c"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item :span="2">
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        申请时间
                                                    </template>
                                                    <el-form-item prop="d">
                                                        <el-date-picker
                                                            v-model="addEditForm.d"
                                                            placeholder="请选择"
                                                            type="datetime"
                                                            value-format="YYYY-MM-DD HH:mm:ss"
                                                        />
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item :span="2">
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        拟供应物资
                                                    </template>
                                                    <el-form-item prop="e">
                                                        <el-select
                                                            v-model="addEditForm.e"
                                                            placeholder="请选择"
                                                            clearable
                                                        >
                                                            <el-option
                                                                v-for="item in []"
                                                                :key="item.value"
                                                                :label="item.label"
                                                                :value="item.value"
                                                            >
                                                            </el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item :span="2">
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        推荐理由
                                                    </template>
                                                    <el-form-item prop="f">
                                                        <el-checkbox-group
                                                            v-model="addEditForm.f"
                                                        >
                                                            <el-checkbox
                                                                v-for="item in recommendList"
                                                                :key="item.id"
                                                                :label="item.name"
                                                                :value="item.id"
                                                            ></el-checkbox>
                                                        </el-checkbox-group>
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item :span="2">
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        供应商合作意愿
                                                    </template>
                                                    <el-form-item prop="s">
                                                        <el-checkbox-group
                                                            v-model="addEditForm.s"
                                                        >
                                                            <el-checkbox
                                                                v-for="item in cooperateList"
                                                                :key="item.id"
                                                                :label="item.name"
                                                                :value="item.id"
                                                            ></el-checkbox>
                                                        </el-checkbox-group>
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item :span="2">
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        简要说明
                                                    </template>
                                                    <el-form-item prop="g">
                                                        <el-input
                                                            v-model="addEditForm.g"
                                                            placeholder="请输入"
                                                            clearable
                                                            type="textarea"
                                                            :rows="4"
                                                        />
                                                    </el-form-item>
                                                </el-descriptions-item>
                                            </el-descriptions>
                                        </div>
                                    </el-collapse-item>
                                </div>

                                <!-- 基本情况 -->
                                <div
                                    v-if="hasMenuItem('basic-info')"
                                    class="content-section"
                                    id="basic-info"
                                >
                                    <div class="content-title">
                                        <div class="content-title-left">基本情况</div>
                                        <div class="content-title-right">
                                            <el-button type="primary" @click="handleSave('basicInfo')"
                                                >保存</el-button
                                            >
                                        </div>
                                    </div>
                                    <el-collapse-item name="basic-info">
                                        <template #title>
                                            <div class="section-title">
                                                <el-icon><Document /></el-icon>
                                                <span>供应商基本情况表</span>
                                            </div>
                                        </template>
                                        <div class="section-content">
                                            <el-descriptions :column="2" border>
                                                <el-descriptions-item :span="2">
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        供应商名称
                                                    </template>
                                                    <el-form-item prop="h">
                                                        <el-input
                                                            v-model="addEditForm.h"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item>
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        企业性质
                                                    </template>
                                                    <el-form-item prop="i">
                                                        <el-select
                                                            v-model="addEditForm.i"
                                                            clearable
                                                            placeholder="请选择"
                                                        >
                                                            <el-option
                                                                v-for="item in industryList"
                                                                :key="item.value"
                                                                :label="item.label"
                                                                :value="item.value"
                                                            >
                                                            </el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item>
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        注册资金
                                                    </template>
                                                    <el-form-item prop="j">
                                                        <el-input
                                                            placeholder="请输入"
                                                            v-model="addEditForm.j"
                                                        >
                                                            <template #append>万元（RMB）</template>
                                                        </el-input>
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item>
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        法定代表人
                                                    </template>
                                                    <el-form-item prop="k">
                                                        <el-input
                                                            v-model="addEditForm.k"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item>
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        成立年份
                                                    </template>
                                                    <el-form-item prop="l">
                                                        <el-date-picker
                                                            v-model="addEditForm.l"
                                                            placeholder="请选择"
                                                            type="date"
                                                            value-format="YYYY-MM-DD"
                                                        />
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item :span="2">
                                                    <template #label> 生产地址 </template>
                                                    <el-form-item prop="m">
                                                        <el-input
                                                            v-model="addEditForm.m"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item :span="2">
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        开户银行
                                                    </template>
                                                    <el-form-item prop="n">
                                                        <el-input
                                                            v-model="addEditForm.n"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item>
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        账号
                                                    </template>
                                                    <el-form-item prop="o">
                                                        <el-input
                                                            v-model="addEditForm.o"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item>
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        税号
                                                    </template>
                                                    <el-form-item prop="p">
                                                        <el-input
                                                            v-model="addEditForm.p"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item>
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        业务联系人
                                                    </template>
                                                    <el-form-item prop="q">
                                                        <el-input
                                                            v-model="addEditForm.q"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item>
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        电话
                                                    </template>
                                                    <el-form-item prop="r">
                                                        <el-input
                                                            v-model="addEditForm.r"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item>
                                                    <template #label> 公司网址 </template>
                                                    <el-form-item prop="t">
                                                        <el-input
                                                            v-model="addEditForm.t"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item>
                                                    <template #label> 传真 </template>
                                                    <el-form-item prop="u">
                                                        <el-input
                                                            v-model="addEditForm.u"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item>
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        手机
                                                    </template>
                                                    <el-form-item prop="v">
                                                        <el-input
                                                            v-model="addEditForm.v"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item>
                                                    <template #label> 邮箱 </template>
                                                    <el-form-item prop="w">
                                                        <el-input
                                                            v-model="addEditForm.w"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item>
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        质量联系人
                                                    </template>
                                                    <el-form-item prop="x">
                                                        <el-input
                                                            v-model="addEditForm.x"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item>
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        电话
                                                    </template>
                                                    <el-form-item prop="y">
                                                        <el-input
                                                            v-model="addEditForm.y"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </el-form-item>
                                                </el-descriptions-item>
                                            </el-descriptions>
                                        </div>
                                    </el-collapse-item>
                                </div>

                                <!-- 企业规模 -->
                                <div
                                    v-if="hasMenuItem('other-notes')"
                                    class="content-section"
                                    id="other-notes"
                                >
                                    <div class="content-title">
                                        <div class="content-title-left">企业规模</div>
                                        <div class="content-title-right">
                                            <el-button type="primary" @click="handleSave('otherNotes')"
                                                >保存</el-button
                                            >
                                        </div>
                                    </div>
                                    <el-collapse-item name="other-notes">
                                        <template #title>
                                            <div class="section-title">
                                                <el-icon><Document /></el-icon>
                                                <span>企业规模表</span>
                                            </div>
                                        </template>
                                        <div class="section-content">
                                            <el-descriptions :column="2" border>
                                                <el-descriptions-item>
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        固定资产
                                                    </template>
                                                    <el-form-item prop="c">
                                                        <el-input
                                                            placeholder="请输入"
                                                            v-model="addEditForm.c"
                                                        >
                                                            <template #append>万元（RMB）</template>
                                                        </el-input>
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item>
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        上年销售额
                                                    </template>
                                                    <el-form-item prop="c">
                                                        <el-input
                                                            placeholder="请输入"
                                                            v-model="addEditForm.c"
                                                        >
                                                            <template #append>万元（RMB）</template>
                                                        </el-input>
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item>
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        主营产品上年度销量
                                                    </template>
                                                    <el-form-item prop="b">
                                                        <el-input
                                                            v-model="addEditForm.b"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item>
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        主营产品上年度销量额
                                                    </template>
                                                    <el-form-item prop="c">
                                                        <el-input
                                                            placeholder="请输入"
                                                            v-model="addEditForm.c"
                                                        >
                                                            <template #append>万元（RMB）</template>
                                                        </el-input>
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item>
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        员工人数
                                                    </template>
                                                    <el-form-item prop="c">
                                                        <el-input
                                                            placeholder="请输入"
                                                            v-model="addEditForm.c"
                                                        >
                                                            <template #append>人</template>
                                                        </el-input>
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item>
                                                    <template #label> 生产作业人员 </template>
                                                    <el-form-item prop="c">
                                                        <el-input
                                                            placeholder="请输入"
                                                            v-model="addEditForm.c"
                                                        >
                                                            <template #append>人</template>
                                                        </el-input>
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item>
                                                    <template #label> 技术工程师 </template>
                                                    <el-form-item prop="c">
                                                        <el-input
                                                            placeholder="请输入"
                                                            v-model="addEditForm.c"
                                                        >
                                                            <template #append>人</template>
                                                        </el-input>
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item>
                                                    <template #label> 质量管理人员 </template>
                                                    <el-form-item prop="c">
                                                        <el-input
                                                            placeholder="请输入"
                                                            v-model="addEditForm.c"
                                                        >
                                                            <template #append>人</template>
                                                        </el-input>
                                                    </el-form-item>
                                                </el-descriptions-item>
                                            </el-descriptions>
                                        </div>
                                    </el-collapse-item>
                                </div>

                                <!-- 企业资质 -->
                                <div
                                    v-if="hasMenuItem('qualification')"
                                    class="content-section"
                                    id="qualification"
                                >
                                    <div class="content-title">
                                        <div class="content-title-left">企业资质</div>
                                        <div class="content-title-right">
                                            <el-button type="primary" @click="handleSave('qualification')"
                                                >保存</el-button
                                            >
                                        </div>
                                    </div>
                                    <el-collapse-item name="qualification">
                                        <template #title>
                                            <div class="section-title">
                                                <el-icon><Document /></el-icon>
                                                <span>必填资质</span>
                                            </div>
                                        </template>
                                        <div class="section-content">
                                            <el-table
                                                :data="addEditForm.qualificationData"
                                                border
                                                stripe
                                            >
                                                <el-table-column
                                                    label="序号"
                                                    width="60"
                                                    align="center"
                                                >
                                                    <template #default="{ $index }">
                                                        {{ $index + 1 }}
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="资质名称"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.qualificationName"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="资质类型"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.qualificationName"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="编号"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.qualificationCode"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="所属权分类"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row }">
                                                        <el-select
                                                            v-model="row.ownershipCategory"
                                                            placeholder="请选择"
                                                            clearable
                                                        >
                                                            <el-option
                                                                v-for="item in ownershipCategoryOptions"
                                                                :key="item.value"
                                                                :label="item.label"
                                                                :value="item.value"
                                                            />
                                                        </el-select>
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="资质所属权"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row }">
                                                        <el-select
                                                            v-model="row.qualificationOwnership"
                                                            placeholder="请选择"
                                                            clearable
                                                        >
                                                            <el-option
                                                                v-for="item in qualificationOwnershipOptions"
                                                                :key="item.value"
                                                                :label="item.label"
                                                                :value="item.value"
                                                            />
                                                        </el-select>
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="有效开始期"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row }">
                                                        <el-date-picker
                                                            v-model="row.effectiveStartDate"
                                                            placeholder="请选择"
                                                            type="date"
                                                            style="width: 100%"
                                                            value-format="YYYY-MM-DD"
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="有效截止期"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row }">
                                                        <el-date-picker
                                                            v-model="row.effectiveEndDate"
                                                            placeholder="请选择"
                                                            type="date"
                                                            style="width: 100%"
                                                            value-format="YYYY-MM-DD"
                                                        />
                                                    </template>
                                                </el-table-column>
                                                <el-table-column
                                                    label="附件"
                                                    align="center"
                                                    width="200"
                                                >
                                                    <template #default="{ row }"
                                                        ><CustomUploader
                                                            :fileList="fileList"
                                                            :previewAndDownload="false"
                                                            :typeRegularArr="typeRegularArr"
                                                            @change="handleFileChange"
                                                            @startUpload="handleStartUpload"
                                                        >
                                                        </CustomUploader>
                                                    </template>
                                                </el-table-column>
                                                <el-table-column
                                                    label="操作"
                                                    align="center"
                                                    width="120"
                                                    fixed="right"
                                                >
                                                    <template #default="{ row, $index }">
                                                        <div class="operation-buttons">
                                                            <el-link
                                                                type="primary"
                                                                :underline="false"
                                                                @click="addQualification()"
                                                            >
                                                                添加
                                                            </el-link>
                                                            <el-link
                                                                type="danger"
                                                                :underline="false"
                                                                @click="deleteQualification($index)"
                                                            >
                                                                删除
                                                            </el-link>
                                                        </div>
                                                    </template>
                                                </el-table-column>
                                            </el-table>
                                        </div>
                                    </el-collapse-item>
                                    <el-collapse-item name="qualification">
                                        <template #title>
                                            <div class="section-title">
                                                <el-icon><Document /></el-icon>
                                                <span>非必填资质</span>
                                            </div>
                                        </template>
                                        <div class="section-content">
                                            <el-table
                                                :data="addEditForm.qualificationData"
                                                border
                                                stripe
                                            >
                                                <el-table-column
                                                    label="序号"
                                                    width="60"
                                                    align="center"
                                                >
                                                    <template #default="{ $index }">
                                                        {{ $index + 1 }}
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="资质名称"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.qualificationName"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="资质类型"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.qualificationName"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="编号"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.qualificationCode"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="所属权分类"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row }">
                                                        <el-select
                                                            v-model="row.ownershipCategory"
                                                            placeholder="请选择"
                                                            clearable
                                                        >
                                                            <el-option
                                                                v-for="item in ownershipCategoryOptions"
                                                                :key="item.value"
                                                                :label="item.label"
                                                                :value="item.value"
                                                            />
                                                        </el-select>
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="资质所属权"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row }">
                                                        <el-select
                                                            v-model="row.qualificationOwnership"
                                                            placeholder="请选择"
                                                            clearable
                                                        >
                                                            <el-option
                                                                v-for="item in qualificationOwnershipOptions"
                                                                :key="item.value"
                                                                :label="item.label"
                                                                :value="item.value"
                                                            />
                                                        </el-select>
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="有效开始期"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row }">
                                                        <el-date-picker
                                                            v-model="row.effectiveStartDate"
                                                            placeholder="请选择"
                                                            type="date"
                                                            style="width: 100%"
                                                            value-format="YYYY-MM-DD"
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="有效截止期"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row }">
                                                        <el-date-picker
                                                            v-model="row.effectiveEndDate"
                                                            placeholder="请选择"
                                                            type="date"
                                                            style="width: 100%"
                                                            value-format="YYYY-MM-DD"
                                                        />
                                                    </template>
                                                </el-table-column>
                                                <el-table-column
                                                    label="附件"
                                                    align="center"
                                                    width="200"
                                                >
                                                    <template #default="{ row }"
                                                        ><CustomUploader
                                                            :fileList="fileList"
                                                            :previewAndDownload="false"
                                                            :typeRegularArr="typeRegularArr"
                                                            @change="handleFileChange"
                                                            @startUpload="handleStartUpload"
                                                        >
                                                        </CustomUploader>
                                                    </template>
                                                </el-table-column>
                                                <el-table-column
                                                    label="操作"
                                                    align="center"
                                                    width="120"
                                                    fixed="right"
                                                >
                                                    <template #default="{ row, $index }">
                                                        <div class="operation-buttons">
                                                            <el-link
                                                                type="primary"
                                                                :underline="false"
                                                                @click="addQualification()"
                                                            >
                                                                添加
                                                            </el-link>
                                                            <el-link
                                                                type="danger"
                                                                :underline="false"
                                                                @click="deleteQualification($index)"
                                                            >
                                                                删除
                                                            </el-link>
                                                        </div>
                                                    </template>
                                                </el-table-column>
                                            </el-table>
                                        </div>
                                    </el-collapse-item>
                                    <el-collapse-item name="qualification">
                                        <template #title>
                                            <div class="section-title">
                                                <el-icon><Document /></el-icon>
                                                <span>其他资质</span>
                                            </div>
                                        </template>
                                        <div class="section-content">
                                            <el-table
                                                :data="addEditForm.qualificationData"
                                                border
                                                stripe
                                            >
                                                <el-table-column
                                                    label="序号"
                                                    width="60"
                                                    align="center"
                                                >
                                                    <template #default="{ $index }">
                                                        {{ $index + 1 }}
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="资质名称"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.qualificationName"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="资质类型"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.qualificationName"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="编号"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.qualificationCode"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="所属权分类"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row }">
                                                        <el-select
                                                            v-model="row.ownershipCategory"
                                                            placeholder="请选择"
                                                            clearable
                                                        >
                                                            <el-option
                                                                v-for="item in ownershipCategoryOptions"
                                                                :key="item.value"
                                                                :label="item.label"
                                                                :value="item.value"
                                                            />
                                                        </el-select>
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="资质所属权"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row }">
                                                        <el-select
                                                            v-model="row.qualificationOwnership"
                                                            placeholder="请选择"
                                                            clearable
                                                        >
                                                            <el-option
                                                                v-for="item in qualificationOwnershipOptions"
                                                                :key="item.value"
                                                                :label="item.label"
                                                                :value="item.value"
                                                            />
                                                        </el-select>
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="有效开始期"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row }">
                                                        <el-date-picker
                                                            v-model="row.effectiveStartDate"
                                                            placeholder="请选择"
                                                            type="date"
                                                            style="width: 100%"
                                                            value-format="YYYY-MM-DD"
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="有效截止期"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row }">
                                                        <el-date-picker
                                                            v-model="row.effectiveEndDate"
                                                            placeholder="请选择"
                                                            type="date"
                                                            style="width: 100%"
                                                            value-format="YYYY-MM-DD"
                                                        />
                                                    </template>
                                                </el-table-column>
                                                <el-table-column
                                                    label="附件"
                                                    align="center"
                                                    width="200"
                                                >
                                                    <template #default="{ row }"
                                                        ><CustomUploader
                                                            :fileList="fileList"
                                                            :previewAndDownload="false"
                                                            :typeRegularArr="typeRegularArr"
                                                            @change="handleFileChange"
                                                            @startUpload="handleStartUpload"
                                                        >
                                                        </CustomUploader>
                                                    </template>
                                                </el-table-column>
                                                <el-table-column
                                                    label="操作"
                                                    align="center"
                                                    width="120"
                                                    fixed="right"
                                                >
                                                    <template #default="{ row, $index }">
                                                        <div class="operation-buttons">
                                                            <el-link
                                                                type="primary"
                                                                :underline="false"
                                                                @click="addQualification()"
                                                            >
                                                                添加
                                                            </el-link>
                                                            <el-link
                                                                type="danger"
                                                                :underline="false"
                                                                @click="deleteQualification($index)"
                                                            >
                                                                删除
                                                            </el-link>
                                                        </div>
                                                    </template>
                                                </el-table-column>
                                            </el-table>
                                        </div>
                                    </el-collapse-item>
                                </div>

                                <!-- 主营产品情况及质量业绩 -->
                                <div
                                    v-if="hasMenuItem('products-quality')"
                                    class="content-section"
                                    id="products-quality"
                                >
                                    <div class="content-title">
                                        <div class="content-title-left">
                                            主营产品情况及质量业绩表
                                        </div>
                                        <div class="content-title-right">
                                            <el-button type="primary" @click="handleSave('productsQuality')"
                                                >保存</el-button
                                            >
                                        </div>
                                    </div>
                                    <el-collapse-item name="products-quality">
                                        <template #title>
                                            <div class="section-title">
                                                <el-icon><Document /></el-icon>
                                                <span>主营产品生产销售情况</span>
                                            </div>
                                        </template>
                                        <div class="section-content">
                                            <el-table
                                                :data="addEditForm.productsQualityData"
                                                border
                                                stripe
                                            >
                                                <el-table-column
                                                    label="序号"
                                                    width="60"
                                                    align="center"
                                                >
                                                    <template #default="{ $index }">
                                                        {{ $index + 1 }}
                                                    </template>
                                                </el-table-column>

                                                <el-table-column label="产品种类" align="center">
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.productType"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column label="规格" align="center">
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.specification"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="近三年年产量"
                                                    align="center"
                                                >
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.annualProduction"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column label="交货周期" align="center">
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.deliveryCycle"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="主要客户及市场"
                                                    align="center"
                                                >
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.mainCustomersAndMarkets"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="操作"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row, $index }">
                                                        <div class="operation-buttons">
                                                            <el-link
                                                                type="primary"
                                                                :underline="false"
                                                                @click="addProductsQuality()"
                                                            >
                                                                添加
                                                            </el-link>
                                                            <el-link
                                                                type="danger"
                                                                :underline="false"
                                                                @click="
                                                                    deleteProductsQuality($index)
                                                                "
                                                            >
                                                                删除
                                                            </el-link>
                                                        </div>
                                                    </template>
                                                </el-table-column>
                                            </el-table>
                                        </div>
                                    </el-collapse-item>
                                    <el-collapse-item name="products-quality">
                                        <template #title>
                                            <div class="section-title">
                                                <el-icon><Document /></el-icon>
                                                <span>主营产品质量表现</span>
                                            </div>
                                        </template>
                                        <div class="section-content">
                                            <el-table
                                                :data="addEditForm.qualityPerformanceData"
                                                border
                                                stripe
                                            >
                                                <el-table-column
                                                    label="序号"
                                                    width="60"
                                                    align="center"
                                                >
                                                    <template #default="{ $index }">
                                                        {{ $index + 1 }}
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="产品名称及规格"
                                                    align="center"
                                                >
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="
                                                                row.productNameAndSpecification
                                                            "
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="去年质量目标"
                                                    align="center"
                                                >
                                                    <el-table-column label="指标" align="center">
                                                        <template #default="{ row }">
                                                            <el-input
                                                                v-model="row.indicator"
                                                                placeholder="请输入"
                                                                clearable
                                                            />
                                                        </template>
                                                    </el-table-column>

                                                    <el-table-column label="实际值" align="center">
                                                        <template #default="{ row }">
                                                            <el-input
                                                                v-model="row.actualValue"
                                                                placeholder="请输入"
                                                                clearable
                                                            />
                                                        </template>
                                                    </el-table-column>
                                                </el-table-column>

                                                <el-table-column
                                                    label="今年质量目标"
                                                    align="center"
                                                >
                                                    <el-table-column label="指标" align="center">
                                                        <template #default="{ row }">
                                                            <el-input
                                                                v-model="row.indicator"
                                                                placeholder="请输入"
                                                                clearable
                                                            />
                                                        </template>
                                                    </el-table-column>

                                                    <el-table-column label="实际值" align="center">
                                                        <template #default="{ row }">
                                                            <el-input
                                                                v-model="row.actualValue"
                                                                placeholder="请输入"
                                                                clearable
                                                            />
                                                        </template>
                                                    </el-table-column>
                                                </el-table-column>

                                                <el-table-column
                                                    label="操作"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row, $index }">
                                                        <div class="operation-buttons">
                                                            <el-link
                                                                type="primary"
                                                                :underline="false"
                                                                @click="addQualityPerformance()"
                                                            >
                                                                添加
                                                            </el-link>
                                                            <el-link
                                                                type="danger"
                                                                :underline="false"
                                                                @click="
                                                                    deleteQualityPerformance($index)
                                                                "
                                                            >
                                                                删除
                                                            </el-link>
                                                        </div>
                                                    </template>
                                                </el-table-column>
                                            </el-table>
                                            <el-descriptions :column="2" border>
                                                <el-descriptions-item :span="2">
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        拟提供我司产品
                                                    </template>
                                                    <el-form-item prop="b">
                                                        <el-input
                                                            v-model="addEditForm.b"
                                                            placeholder="请输入"
                                                            clearable
                                                            type="textarea"
                                                            :rows="4"
                                                        />
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item :span="2">
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        企业业绩
                                                    </template>
                                                    <el-form-item prop="b">
                                                        <el-input
                                                            v-model="addEditForm.b"
                                                            placeholder="请输入"
                                                            clearable
                                                            type="textarea"
                                                            :rows="4"
                                                        />
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item :span="2">
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        附件
                                                    </template>
                                                    <el-form-item prop="b">
                                                        <CustomUploader
                                                            type="button"
                                                            :fileList="fileList"
                                                            :previewAndDownload="false"
                                                            :typeRegularArr="typeRegularArr"
                                                            @change="handleFileChange"
                                                            @startUpload="handleStartUpload"
                                                        >
                                                        </CustomUploader>
                                                    </el-form-item>
                                                </el-descriptions-item>
                                            </el-descriptions>
                                        </div>
                                    </el-collapse-item>
                                    <el-collapse-item name="products-quality">
                                        <template #title>
                                            <div class="section-title">
                                                <el-icon><Document /></el-icon>
                                                <span>客户抱怨</span>
                                            </div>
                                        </template>
                                        <div class="section-content">
                                            <el-table
                                                :data="addEditForm.productsQualityData"
                                                border
                                                stripe
                                            >
                                                <el-table-column
                                                    label="序号"
                                                    width="60"
                                                    align="center"
                                                >
                                                    <template #default="{ $index }">
                                                        {{ $index + 1 }}
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="客户抱怨问题"
                                                    align="center"
                                                >
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.productType"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column label="控制措施" align="center">
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.specification"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="操作"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row, $index }">
                                                        <div class="operation-buttons">
                                                            <el-link
                                                                type="primary"
                                                                :underline="false"
                                                                @click="addProductsQuality()"
                                                            >
                                                                添加
                                                            </el-link>
                                                            <el-link
                                                                type="danger"
                                                                :underline="false"
                                                                @click="
                                                                    deleteProductsQuality($index)
                                                                "
                                                            >
                                                                删除
                                                            </el-link>
                                                        </div>
                                                    </template>
                                                </el-table-column>
                                            </el-table>
                                        </div>
                                    </el-collapse-item>
                                </div>

                                <!-- 主要原材料及供应商表 -->
                                <div
                                    v-if="hasMenuItem('raw-materials')"
                                    class="content-section"
                                    id="raw-materials"
                                >
                                    <div class="content-title">
                                        <div class="content-title-left">主要原材料及供应商表</div>
                                        <div class="content-title-right">
                                            <el-button type="primary" @click="handleSave('rawMaterials')"
                                                >保存</el-button
                                            >
                                        </div>
                                    </div>
                                    <el-collapse-item name="raw-materials">
                                        <template #title>
                                            <div class="section-title">
                                                <el-icon><Document /></el-icon>
                                                <span>主要原材料信息</span>
                                            </div>
                                        </template>
                                        <div class="section-content">
                                            <el-table
                                                :data="addEditForm.materialsAndSuppliersData"
                                                border
                                                stripe
                                            >
                                                <el-table-column
                                                    label="序号"
                                                    width="60"
                                                    align="center"
                                                >
                                                    <template #default="{ $index }">
                                                        {{ $index + 1 }}
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="主要原料名称"
                                                    align="center"
                                                >
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.mainMaterialName"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column label="供应厂家" align="center">
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.supplierName"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="上年度业绩表现"
                                                    align="center"
                                                >
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.annualPerformance"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="操作"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row, $index }">
                                                        <div class="operation-buttons">
                                                            <el-link
                                                                type="primary"
                                                                :underline="false"
                                                                @click="addMaterialsAndSuppliers()"
                                                            >
                                                                添加
                                                            </el-link>
                                                            <el-link
                                                                type="danger"
                                                                :underline="false"
                                                                @click="
                                                                    deleteMaterialsAndSuppliers(
                                                                        $index
                                                                    )
                                                                "
                                                            >
                                                                删除
                                                            </el-link>
                                                        </div>
                                                    </template>
                                                </el-table-column>
                                            </el-table>
                                        </div>
                                    </el-collapse-item>
                                </div>

                                <!-- 生产制造过程绩效 -->
                                <div
                                    v-if="hasMenuItem('manufacturing')"
                                    class="content-section"
                                    id="manufacturing"
                                >
                                    <div class="content-title">
                                        <div class="content-title-left">生产制造过程绩效表</div>
                                        <div class="content-title-right">
                                            <el-button type="primary" @click="handleSave('manufacturing')"
                                                >保存</el-button
                                            >
                                        </div>
                                    </div>
                                    <el-collapse-item name="manufacturing">
                                        <template #title>
                                            <div class="section-title">
                                                <el-icon><Document /></el-icon>
                                                <span>生产制造过程绩效</span>
                                            </div>
                                        </template>
                                        <div class="section-content">
                                            <el-descriptions :column="2" border>
                                                <el-descriptions-item :span="2">
                                                    <template #label>
                                                        <span class="required-asterisk">*</span>
                                                        生产工艺流程(可附页说明)
                                                    </template>
                                                    <el-form-item prop="b">
                                                        <el-input
                                                            v-model="addEditForm.b"
                                                            placeholder="请输入"
                                                            clearable
                                                            type="textarea"
                                                            :rows="4"
                                                        />
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item :span="2">
                                                    <template #label> 附件 </template>
                                                    <el-form-item prop="b">
                                                        <CustomUploader
                                                            type="button"
                                                            :fileList="fileList"
                                                            :previewAndDownload="false"
                                                            :typeRegularArr="typeRegularArr"
                                                            @change="handleFileChange"
                                                            @startUpload="handleStartUpload"
                                                        >
                                                        </CustomUploader>
                                                    </el-form-item>
                                                </el-descriptions-item>
                                            </el-descriptions>
                                            <el-table
                                                :data="addEditForm.manufacturingPerformanceData"
                                                border
                                                stripe
                                            >
                                                <el-table-column
                                                    label="序号"
                                                    width="60"
                                                    align="center"
                                                >
                                                    <template #default="{ $index }">
                                                        {{ $index + 1 }}
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="关键&重要过程"
                                                    align="center"
                                                >
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.keyAndImportantProcess"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="控制参数或特性"
                                                    align="center"
                                                >
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="
                                                                row.controlParameterOrCharacteristic
                                                            "
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="过程能力指数"
                                                    align="center"
                                                >
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.processCapabilityIndex"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="操作"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row, $index }">
                                                        <div class="operation-buttons">
                                                            <el-link
                                                                type="primary"
                                                                :underline="false"
                                                                @click="
                                                                    addManufacturingPerformance()
                                                                "
                                                            >
                                                                添加
                                                            </el-link>
                                                            <el-link
                                                                type="danger"
                                                                :underline="false"
                                                                @click="
                                                                    deleteManufacturingPerformance(
                                                                        $index
                                                                    )
                                                                "
                                                            >
                                                                删除
                                                            </el-link>
                                                        </div>
                                                    </template>
                                                </el-table-column>
                                            </el-table>
                                        </div>
                                    </el-collapse-item>
                                </div>

                                <!-- 生产及检验设备 -->
                                <div
                                    v-if="hasMenuItem('equipment')"
                                    class="content-section"
                                    id="equipment"
                                >
                                    <div class="content-title">
                                        <div class="content-title-left">生产及检验设备表</div>
                                        <div class="content-title-right">
                                            <el-button type="primary" @click="handleSave('equipment')"
                                                >保存</el-button
                                            >
                                        </div>
                                    </div>
                                    <el-collapse-item name="equipment">
                                        <template #title>
                                            <div class="section-title">
                                                <el-icon><Document /></el-icon>
                                                <span>主要生产设备</span>
                                            </div>
                                        </template>
                                        <div class="section-content">
                                            <el-table
                                                :data="addEditForm.mainProductionEquipmentData"
                                                border
                                                stripe
                                            >
                                                <el-table-column
                                                    label="序号"
                                                    width="60"
                                                    align="center"
                                                >
                                                    <template #default="{ $index }">
                                                        {{ $index + 1 }}
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="生产设备名称/型号"
                                                    align="center"
                                                >
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="
                                                                row.productionEquipmentNameAndModel
                                                            "
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column label="产能" align="center">
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.capacity"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column label="数量" align="center">
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.quantity"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column label="生产厂家" align="center">
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.productionFactory"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column label="使用年限" align="center">
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.useYears"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="操作"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row, $index }">
                                                        <div class="operation-buttons">
                                                            <el-link
                                                                type="primary"
                                                                :underline="false"
                                                                @click="
                                                                    addMainProductionEquipment()
                                                                "
                                                            >
                                                                添加
                                                            </el-link>
                                                            <el-link
                                                                type="danger"
                                                                :underline="false"
                                                                @click="
                                                                    deleteMainProductionEquipment(
                                                                        $index
                                                                    )
                                                                "
                                                            >
                                                                删除
                                                            </el-link>
                                                        </div>
                                                    </template>
                                                </el-table-column>
                                            </el-table>
                                            <el-descriptions :column="2" border>
                                                <el-descriptions-item :span="2">
                                                    <template #label> 附件 </template>
                                                    <el-form-item prop="b">
                                                        <CustomUploader
                                                            type="button"
                                                            :fileList="fileList"
                                                            :previewAndDownload="false"
                                                            :typeRegularArr="typeRegularArr"
                                                            @change="handleFileChange"
                                                            @startUpload="handleStartUpload"
                                                        >
                                                        </CustomUploader>
                                                    </el-form-item>
                                                </el-descriptions-item>
                                            </el-descriptions>
                                        </div>
                                    </el-collapse-item>
                                    <el-collapse-item name="equipment">
                                        <template #title>
                                            <div class="section-title">
                                                <el-icon><Document /></el-icon>
                                                <span>主要检验设备</span>
                                            </div>
                                        </template>
                                        <div class="section-content">
                                            <el-table
                                                :data="addEditForm.mainInspectionEquipmentData"
                                                border
                                                stripe
                                            >
                                                <el-table-column
                                                    label="序号"
                                                    width="60"
                                                    align="center"
                                                >
                                                    <template #default="{ $index }">
                                                        {{ $index + 1 }}
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="生产设备名称/型号"
                                                    align="center"
                                                >
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="
                                                                row.productionEquipmentNameAndModel
                                                            "
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column label="产能" align="center">
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.capacity"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column label="数量" align="center">
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.quantity"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column label="生产厂家" align="center">
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.productionFactory"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column label="使用年限" align="center">
                                                    <template #default="{ row }">
                                                        <el-input
                                                            v-model="row.useYears"
                                                            placeholder="请输入"
                                                            clearable
                                                        />
                                                    </template>
                                                </el-table-column>

                                                <el-table-column
                                                    label="操作"
                                                    align="center"
                                                    width="120"
                                                >
                                                    <template #default="{ row, $index }">
                                                        <div class="operation-buttons">
                                                            <el-link
                                                                type="primary"
                                                                :underline="false"
                                                                @click="
                                                                    addMainInspectionEquipment()
                                                                "
                                                            >
                                                                添加
                                                            </el-link>
                                                            <el-link
                                                                type="danger"
                                                                :underline="false"
                                                                @click="
                                                                    deleteMainInspectionEquipment(
                                                                        $index
                                                                    )
                                                                "
                                                            >
                                                                删除
                                                            </el-link>
                                                        </div>
                                                    </template>
                                                </el-table-column>
                                            </el-table>
                                            <el-descriptions :column="2" border>
                                                <el-descriptions-item :span="2">
                                                    <template #label> 附件 </template>
                                                    <el-form-item prop="b">
                                                        <CustomUploader
                                                            type="button"
                                                            :fileList="fileList"
                                                            :previewAndDownload="false"
                                                            :typeRegularArr="typeRegularArr"
                                                            @change="handleFileChange"
                                                            @startUpload="handleStartUpload"
                                                        >
                                                        </CustomUploader>
                                                    </el-form-item>
                                                </el-descriptions-item>
                                            </el-descriptions>
                                        </div>
                                    </el-collapse-item>
                                </div>

                                <!-- 其他特别说明 -->
                                <div
                                    v-if="hasMenuItem('company-scale')"
                                    class="content-section"
                                    id="company-scale"
                                >
                                    <div class="content-title">
                                        <div class="content-title-left">其他特别说明</div>
                                        <div class="content-title-right">
                                            <el-button type="primary" @click="handleSave('companyScale')"
                                                >保存</el-button
                                            >
                                        </div>
                                    </div>
                                    <el-collapse-item name="company-scale">
                                        <template #title>
                                            <div class="section-title">
                                                <el-icon><Document /></el-icon>
                                                <span>附件说明</span>
                                            </div>
                                        </template>
                                        <div class="section-content">
                                            <el-descriptions :column="2" border>
                                                <el-descriptions-item :span="2">
                                                    <template #label> 特别说明 </template>
                                                    <el-form-item prop="template">
                                                        <el-input
                                                            v-model="addEditForm.template"
                                                            placeholder="请输入"
                                                            clearable
                                                            type="textarea"
                                                            :rows="4"
                                                        />
                                                    </el-form-item>
                                                </el-descriptions-item>
                                                <el-descriptions-item :span="2">
                                                    <template #label> 附件 </template>
                                                    <el-form-item prop="scaleFiles">
                                                        <CustomUploader
                                                            type="button"
                                                            :fileList="fileList"
                                                            :previewAndDownload="false"
                                                            :typeRegularArr="typeRegularArr"
                                                            @change="handleFileChange"
                                                            @startUpload="handleStartUpload"
                                                        >
                                                        </CustomUploader>
                                                    </el-form-item>
                                                </el-descriptions-item>
                                            </el-descriptions>
                                        </div>
                                    </el-collapse-item>
                                </div>
                            </el-collapse>
                        </el-form>
                    </div>
                </div>
            </div>
        </div>
        <div class="footer">
            <el-button type="primary" @click="handleSubmit" :loading="submitLoading">提 交</el-button>
            <el-button @click="handleCancel"> 取 消</el-button>
        </div>
    </div>
</template>

<script lang="ts" setup>
import type { FormInstance, FormRules } from 'element-plus'
import { Document, Tickets, Check, CircleCheck } from '@element-plus/icons-vue'
import CustomUploader from '@/components/CustomUploader/index.vue'
import {dataDetail,dataAdd,dataEdit} from '@/api/supplierMonitor/QualificationAudit/SupplyInfo'

interface AddEditForm {
    [key: string]: string | number | undefined | null | any
}

interface FileItem {
    id?: string
    fileId?: string
    status: string

    [key: string]: any
}

const route = useRoute()
const router = useRouter()

// UI状态
// 折叠面板激活状态 - 只包含存在的菜单项
const activeCollapse = computed(() => {
    return menuItems.value.map((item) => item.id)
})
const activeMenuItem = ref('access-application') // 当前激活的菜单项
const detailLoading = ref(false) // 详情加载状态

// 表单相关
const addEditFormRef = ref<FormInstance>()
const addEditFormRules = reactive<FormRules>({
    //准入申请
    a:[{ required: true, message: '请输入企业名称', trigger: 'blur' }],
    b:[{ required: true, message: '请输入推荐人', trigger: 'blur' }],
    c:[{ required: true, message: '请输入推荐单位', trigger: 'blur' }],
    d:[{ required: true, message: '请选择申请时间', trigger: 'change' }],
    e:[{ required: true, message: '请选择拟供应物资', trigger: 'change' }],
    f:[{ required: true, message: '请选择推荐理由', trigger: 'change' }],
    s:[{ required: true, message: '请选择供应商合作意愿', trigger: 'change' }],
    g:[{ required: true, message: '请输入简要说明', trigger: 'blur' }],

    //基本情况
    h: [{ required: true, message: '请输入供应商名称', trigger: 'blur' }],
    i: [{ required: true, message: '请输入企业性质', trigger: 'blur' }],
    j: [{ required: true, message: '请输入注册资金', trigger: 'blur' }],
    k: [{ required: true, message: '请输入法定代表人', trigger: 'blur' }],
    l: [{ required: true, message: '请选择成立年份', trigger: 'change' }],
    m: [{ required: true, message: '请输入生产地址', trigger: 'blur' }],
    n: [{ required: true, message: '请输入开户银行', trigger: 'blur' }],
    o: [{ required: true, message: '请输入账号', trigger: 'blur' }],
    p: [{ required: true, message: '请输入税号', trigger: 'blur' }],
    q: [{ required: true, message: '请输入业务联系人', trigger: 'blur' }],
    r: [{ required: true, message: '请输入电话', trigger: 'blur' }],
    t: [{ required: true, message: '请输入公司网址', trigger: 'blur' }],
    u: [{ required: true, message: '请输入传真', trigger: 'blur' }],
    v: [{ required: true, message: '请输入手机', trigger: 'blur' }],
    w: [{ required: true, message: '请输入邮箱', trigger: 'blur' }],
    x: [{ required: true, message: '请输入质量联系人', trigger: 'blur' }],
    y: [{ required: true, message: '请输入电话', trigger: 'blur' }]
})
const addEditForm = reactive<AddEditForm>({
    agree: 1,
    comments: '',
    qualificationData: [
        {
            id: 1,
            qualificationName: '',
            qualificationCode: '',
            ownershipCategory: '',
            qualificationOwnership: '',
            effectiveStartDate: '',
            effectiveEndDate: ''
        }
    ],
    productsQualityData: [
        {
            id: 1,
            productType: '',
            specification: '',
            annualProduction: '',
            deliveryCycle: '',
            mainCustomersAndMarkets: ''
        }
    ],
    qualityPerformanceData: [
        {
            id: 1,
            productNameAndSpecification: '',
            indicator: ''
        }
    ],
    materialsAndSuppliersData: [
        {
            id: 1,
            mainMaterialName: '',
            supplierName: '',
            annualPerformance: ''
        }
    ],
    manufacturingPerformanceData: [
        {
            id: 1,
            keyAndImportantProcess: '',
            controlParameterOrCharacteristic: '',
            processCapabilityIndex: ''
        }
    ],
    mainProductionEquipmentData: [
        {
            id: 1,
            productionEquipmentNameAndModel: '',
            capacity: '',
            quantity: '',
            productionFactory: '',
            useYears: ''
        }
    ],
    mainInspectionEquipmentData: [
        {
            id: 1,
            inspectionEquipmentNameAndModel: '',
            capacity: '',
            quantity: '',
            productionFactory: '',
            useYears: ''
        }
    ]
})

const detailForm = reactive<AddEditForm>({})

// 表格数据
const industryList = ref([
    {
        value: '有限责任公司',
        label: '有限责任公司'
    },
    {
        value: '股份有限公司',
        label: '股份有限公司'
    }
])

// 下拉选项数据
const ownershipCategoryOptions = ref([
    { value: '企业', label: '企业' },
    { value: '个人', label: '个人' },
    { value: '政府', label: '政府' }
])

const qualificationOwnershipOptions = ref([
    { value: 'A供应商', label: 'A供应商' },
    { value: 'B供应商', label: 'B供应商' },
    { value: 'C供应商', label: 'C供应商' }
])

const recommendList = ref([])

const cooperateList = ref([])

// 检查菜单项是否存在的辅助函数
const hasMenuItem = (menuId: string) => {
    return menuItems.value.some((item) => item.id === menuId)
}

// 菜单配置数据
const menuItems = ref([
    {
        id: 'access-application',
        title: '准入申请信息',
        saveStatusKey: 'accessApplication'
    },
    {
        id: 'basic-info',
        title: '基本情况',
        saveStatusKey: 'basicInfo'
    },
    {
        id: 'other-notes',
        title: '企业规模',
        saveStatusKey: 'otherNotes'
    },
    {
        id: 'qualification',
        title: '企业资质表',
        saveStatusKey: 'qualification'
    },
    {
        id: 'products-quality',
        title: '主营产品情况及质量业绩',
        saveStatusKey: 'productsQuality'
    },
    {
        id: 'raw-materials',
        title: '主要原材料及供应商',
        saveStatusKey: 'rawMaterials'
    },
    {
        id: 'manufacturing',
        title: '生产制造过程绩效',
        saveStatusKey: 'manufacturing'
    },
    {
        id: 'equipment',
        title: '生产及检验设备',
        saveStatusKey: 'equipment'
    },
    {
        id: 'company-scale',
        title: '其他特别说明',
        saveStatusKey: 'companyScale'
    }
])

// 保存状态数据
const saveStatus = reactive({
    basicInfo: false,
    otherNotes: false,
    qualification: false,
    productsQuality: false,
    rawMaterials: false,
    manufacturing: false,
    equipment: false,
    companyScale: false
})

// 导航相关
const scrollToSection = (sectionId: string) => {
    // 设置滚动标志，防止滚动监听干扰
    isScrolling = true

    // 更新激活的菜单项
    activeMenuItem.value = sectionId

    const element = document.getElementById(sectionId)
    if (element) {
        element.scrollIntoView({
            behavior: 'smooth',
            block: 'start'
        })

        // 滚动完成后重置标志
        setTimeout(() => {
            isScrolling = false
        }, 1000)
    } else {
        isScrolling = false
    }
}

// 滚动监听相关
let scrollContainer: HTMLElement | null = null
let isScrolling = false

// 监听滚动事件，更新激活的菜单项
const handleScroll = () => {
    if (isScrolling) return

    const sections = menuItems.value
        .map((item) => ({
            id: item.id,
            element: document.getElementById(item.id)
        }))
        .filter((section) => section.element)

    if (sections.length === 0) return

    // 获取滚动容器的滚动位置
    const scrollTop = scrollContainer?.scrollTop || window.pageYOffset
    const containerHeight = scrollContainer?.clientHeight || window.innerHeight
    const scrollHeight = scrollContainer?.scrollHeight || document.documentElement.scrollHeight

    // 检查是否滚动到底部（距离底部100px以内）
    const isNearBottom = scrollTop + containerHeight >= scrollHeight - 100

    // 如果接近底部，直接选中最后一个section
    if (isNearBottom) {
        const lastSection = sections[sections.length - 1]
        if (lastSection && activeMenuItem.value !== lastSection.id) {
            activeMenuItem.value = lastSection.id
        }
        return
    }

    // 找到当前可见的section
    let currentSection = sections[0]

    for (const section of sections) {
        if (!section.element) continue

        const rect = section.element.getBoundingClientRect()
        const elementTop = rect.top + scrollTop
        const elementBottom = elementTop + rect.height

        // 如果section的顶部在视口范围内
        if (elementTop <= scrollTop + containerHeight / 2 && elementBottom > scrollTop) {
            currentSection = section
        }
    }

    // 更新激活的菜单项
    if (currentSection && activeMenuItem.value !== currentSection.id) {
        activeMenuItem.value = currentSection.id
    }
}

// 防抖处理滚动事件
const debouncedHandleScroll = () => {
    if (isScrolling) return
    requestAnimationFrame(() => {
        handleScroll()
    })
}

// 数据获取
const getDetail = async (id: string) => {
    // 获取详情逻辑
    detailLoading.value = true
    const { ...rest } = (await dataDetail(id)) as AddEditForm
    Object.assign(addEditForm, {
        ...rest
    })
    detailLoading.value = false
}

// 企业资质相关方法
const addQualification = () => {
    addEditForm.qualificationData.push({
        id: 1,
        qualificationName: '',
        qualificationCode: '',
        ownershipCategory: '',
        qualificationOwnership: '',
        effectiveStartDate: '',
        effectiveEndDate: '',
        attachment: '',
        attachmentStatus: 'uploaded'
    })
}

const deleteQualification = (index: number) => {
    ElMessageBox.confirm('确定要删除这条资质信息吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
    })
        .then(() => {
            addEditForm.qualificationData.splice(index, 1)
            ElMessage.success('删除成功')
        })
        .catch(() => {
            ElMessage.info('已取消删除')
        })
}

//主营产品生产销售情况
const addProductsQuality = () => {
    addEditForm.productsQualityData.push({
        id: 1,
        productType: '',
        specification: '',
        annualProduction: '',
        deliveryCycle: '',
        mainCustomersAndMarkets: ''
    })
}

const deleteProductsQuality = (index: number) => {
    ElMessageBox.confirm('确定要删除这条主营产品生产销售情况吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
    })
        .then(() => {
            addEditForm.productsQualityData.splice(index, 1)
            ElMessage.success('删除成功')
        })
        .catch(() => {
            ElMessage.info('已取消删除')
        })
}

//主营产品质量表现
const addQualityPerformance = () => {
    addEditForm.qualityPerformanceData.push({
        id: 1,
        productNameAndSpecification: '',
        indicator: '',
        actualValue: ''
    })
}

const deleteQualityPerformance = (index: number) => {
    ElMessageBox.confirm('确定要删除这条主营产品质量表现吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
    })
        .then(() => {
            addEditForm.qualityPerformanceData.splice(index, 1)
            ElMessage.success('删除成功')
        })
        .catch(() => {
            ElMessage.info('已取消删除')
        })
}

//主要原材料信息
const addMaterialsAndSuppliers = () => {
    addEditForm.materialsAndSuppliersData.push({
        id: 1,
        mainMaterialName: '',
        supplierName: '',
        annualPerformance: ''
    })
}

const deleteMaterialsAndSuppliers = (index: number) => {
    ElMessageBox.confirm('确定要删除这条主要原材料信息吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
    })
        .then(() => {
            addEditForm.materialsAndSuppliersData.splice(index, 1)
            ElMessage.success('删除成功')
        })
        .catch(() => {
            ElMessage.info('已取消删除')
        })
}

//生产制造过程绩效
const addManufacturingPerformance = () => {
    addEditForm.manufacturingPerformanceData.push({
        id: 1,
        keyAndImportantProcess: '',
        controlParameterOrCharacteristic: '',
        processCapabilityIndex: ''
    })
}

const deleteManufacturingPerformance = (index: number) => {
    ElMessageBox.confirm('确定要删除这条生产制造过程绩效吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
    })
        .then(() => {
            addEditForm.manufacturingPerformanceData.splice(index, 1)
            ElMessage.success('删除成功')
        })
        .catch(() => {
            ElMessage.info('已取消删除')
        })
}

//主要生产设备
const addMainProductionEquipment = () => {
    addEditForm.mainProductionEquipmentData.push({
        id: 1,
        productionEquipmentNameAndModel: '',
        capacity: '',
        quantity: '',
        productionFactory: '',
        useYears: ''
    })
}

const deleteMainProductionEquipment = (index: number) => {
    ElMessageBox.confirm('确定要删除这条主要生产设备吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
    })
        .then(() => {
            addEditForm.mainProductionEquipmentData.splice(index, 1)
            ElMessage.success('删除成功')
        })
        .catch(() => {
            ElMessage.info('已取消删除')
        })
}

//主要检验设备
const addMainInspectionEquipment = () => {
    addEditForm.mainInspectionEquipmentData.push({
        id: 1,
        inspectionEquipmentNameAndModel: '',
        capacity: '',
        quantity: '',
        productionFactory: '',
        useYears: ''
    })
}

const deleteMainInspectionEquipment = (index: number) => {
    ElMessageBox.confirm('确定要删除这条主要检验设备吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
    })
        .then(() => {
            addEditForm.mainInspectionEquipmentData.splice(index, 1)
            ElMessage.success('删除成功')
        })
        .catch(() => {
            ElMessage.info('已取消删除')
        })
}

//附件上传
const btnLoading = ref<Boolean>(false)
const readyToUpload = ref<Boolean>(false)
const fileList = ref<FileItem[]>([])
const typeRegularArr = [
    'mp4',
    'mov',
    'avi',
    'mkv',
    'wmv',
    'flv',
    'mpeg',
    'mpg',
    '3gp',
    'webm', // 视频格式
    'doc',
    'docx',
    'xls',
    'xlsx',
    'ppt',
    'pptx',
    'txt',
    'rtf',
    'pdf', // 文档格式
    'jpg',
    'png',
    'bmp',
    'gif' // 图像文件
]
const handleStartUpload = () => {
    btnLoading.value = true
}

const handleFileChange = (file: [FileItem]) => {
    fileList.value = file.map((item) => item as FileItem)
    btnLoading.value = !file.every((item: FileItem) => item.status === 'success')
}

// 表单操作
const blockFields = {
    accessApplication: ['a','b','c','d','e','f','s','g'], // 准入申请
    basicInfo: ['h','i','j','k','l','n','o','p','q','r','t','u','v','w','x','y'], // 基本情况
    otherNotes: [], // 企业规模
    qualification: [], // 企业资质表
    productsQuality: [], // 主营产品情况及质量业绩
    rawMaterials: [], // 主要原材料及供应商
    manufacturing: [], // 生产制造过程绩效
    equipments: [], // 生产及检验设备
    companyScale: [], // 其他特别说明
}

// 保存
const handleSave = async (blockKey: string) => {
    const fields = blockFields[blockKey]

    if (!fields) {
        console.error(`未找到块 ${blockKey} 的字段配置`)
        return
    }

    try {
        // 只校验当前块的字段
        if(fields.length > 0){
            await addEditFormRef.value.validateField(fields)
        }

        // 校验通过，提取当前块的数据进行保存
        const blockData = {}
        fields.forEach(field => {
            blockData[field] = addEditForm[field]
        })

        // 调用保存接口
        await saveBlockData(blockKey, blockData)
        ElMessage.success(`${getBlockName(blockKey)}保存成功`)

    } catch (error) {
        console.log(`${getBlockName(blockKey)}校验失败`)
    }
}

// 保存数据到后端
const saveBlockData = async (blockKey, data) => {
    detailLoading.value = true
    console.log(blockKey,'addddddd',data)
    // 调用 API 保存当前块数据
    updateSaveStatus(activeMenuItem.value)
    // return await api.saveBlock(blockKey, data)
}

// 获取块的中文名称（用于提示）
const getBlockName = (blockKey) => {
    const blockNames = {
        accessApplication: '准入申请',
        basicInfo: '基本情况',
    }
    return blockNames[blockKey] || blockKey
}


// 计算属性实时判断是否所有保存
const allCompleted = computed(() => {
    return Object.values(saveStatus).every(value => value === true)
})
const submitLoading = ref<Boolean>(false)
const handleSubmit = () => {
    if(allCompleted.value){
        submitLoading.value = true
        handleCancel()
        console.log(allCompleted.value)
    }else{
        ElMessage.warning('请先填写保存所有必填项')
    }
}

// 更新保存状态
const updateSaveStatus = (sectionId: string) => {
    const menuItem = menuItems.value.find((item) => item.id === sectionId)
    if (menuItem) {
        saveStatus[menuItem.saveStatusKey as keyof typeof saveStatus] = true
    }
}

const handleCancel = () => {
    router.push({ name: 'SupplyInfo' })
}

// 获取保存状态样式类
const getSaveStatusClass = (sectionId: string) => {
    const menuItem = menuItems.value.find((item) => item.id === sectionId)
    if (!menuItem) return 'save-icon not-saved'

    const isSaved = saveStatus[menuItem.saveStatusKey as keyof typeof saveStatus]
    return isSaved ? 'save-icon saved' : 'save-icon not-saved'
}

// 获取保存状态
const getSaveStatus = (sectionId: string) => {
    const menuItem = menuItems.value.find((item) => item.id === sectionId)
    if (!menuItem) return false

    return saveStatus[menuItem.saveStatusKey as keyof typeof saveStatus]
}

onMounted(() => {
    readyToUpload.value = true

    // 确保activeMenuItem指向一个存在的菜单项
    if (!hasMenuItem(activeMenuItem.value) && menuItems.value.length > 0) {
        activeMenuItem.value = menuItems.value[0].id
    }

    // 如果是编辑模式，获取详情数据
    if (route.query.id && typeof route.query.id === 'string') {
        getDetail(route.query.id)
    }

    // 设置滚动监听
    setTimeout(() => {
        // 查找滚动容器
        scrollContainer = document.querySelector('.page-form') as HTMLElement

        // 添加滚动监听器
        if (scrollContainer) {
            scrollContainer.addEventListener('scroll', debouncedHandleScroll)
        } else {
            // 如果没有找到滚动容器，监听window滚动
            window.addEventListener('scroll', debouncedHandleScroll)
        }

        // 初始化滚动位置
        const element = document.getElementById(activeMenuItem.value)
        if (element) {
            element.scrollIntoView({
                behavior: 'instant',
                block: 'start'
            })
        }
    }, 100)
})

onUnmounted(() => {
    // 清理滚动监听器
    if (scrollContainer) {
        scrollContainer.removeEventListener('scroll', debouncedHandleScroll)
    } else {
        window.removeEventListener('scroll', debouncedHandleScroll)
    }
})
</script>

<style lang="scss" scoped>
.edit-add-detail {
    .form-content {
        display: flex;
        flex-direction: column;
        align-items: center;

        .page-form {
            width: 80%;
            overflow-x: hidden;
            overflow-y: auto;
            max-height: 100%;
            padding: 0 20px;

            /* 隐藏滚动条样式 */
            &::-webkit-scrollbar {
                width: 0;
                height: 0;
            }

            &::-webkit-scrollbar-track {
                background: transparent;
            }

            &::-webkit-scrollbar-thumb {
                background: transparent;
            }

            /* Firefox 隐藏滚动条 */
            scrollbar-width: none;
            -ms-overflow-style: none;
        }
        .step-container {
            width: 100%;
            margin-bottom: 20px;
            padding: 20px;
            border-radius: 8px;
        }

        .main-content {
            display: flex;
            gap: 20px;
            width: 100%;
            padding-bottom: 20px;

            .sidebar-menu {
                width: 180px;
                background-color: var(--theme-search-wrapper-bg);
                box-shadow: 0px 0px 20px 0px rgba(0, 36, 65, 0.2);
                border-radius: 16px;
                padding: 10px 20px 20px 20px;
                height: fit-content;
                position: sticky;
                top: 10px;

                .menu-section {
                    margin-bottom: 30px;

                    .menu-title {
                        font-size: 16px;
                        font-weight: bold;
                        color: var(--theme-text-primary);
                        white-space: pre;
                    }

                    .menu-items {
                        .menu-item {
                            font-size: 14px;
                            padding: 10px 15px;
                            margin-bottom: 5px;
                            cursor: pointer;
                            border-radius: 4px;
                            transition: all 0.3s ease;
                            color: var(--theme-text-primary);
                            display: flex;
                            justify-content: space-between;
                            align-items: center;

                            &:hover {
                                background-color: var(--theme-system-module-1);
                                color: var(--theme-primary);
                            }

                            &.active {
                                background-color: var(--theme-primary);
                                color: white;
                            }

                            .save-icon {
                                font-size: 20px;

                                &.saved {
                                    color: #67c23a; /* 绿色 */
                                }

                                &.not-saved {
                                    color: #c0c4cc; /* 灰色 */
                                }
                            }
                        }
                    }
                }
            }

            .content-area {
                width: calc(100% - 180px - 80px);
                background-color: var(--theme-form-content-bg);
                border-radius: 8px;
                padding: 20px 20px 0 20px;

                .content-section {
                    margin-bottom: 20px;

                    .content-title {
                        margin-bottom: 5px;
                        display: flex;
                        justify-content: space-between;
                        align-items: center;
                        .content-title-left {
                            font-size: 14px;
                            font-weight: bold;
                            color: var(--theme-text-primary);
                            display: flex;
                            align-items: center;
                        }
                        .content-title-left::before {
                            content: '';
                            display: inline-block;
                            width: 4px;
                            height: 18px;
                            background-color: #1a8cff;
                            border-radius: 2px;
                            margin-right: 8px;
                        }
                    }

                    .site-inspection-content {
                        background-color: #f5f8fa;
                        padding: 16px;
                        box-sizing: border-box;
                        .review-requirements {
                            margin-bottom: 10px;
                            .review-requirements-title {
                                color: var(--theme-text-primary);
                                margin-bottom: 5px;
                                font-size: 14px;
                                font-weight: bold;
                            }
                            ul {
                                list-style: none;
                                li {
                                    color: var(--theme-text-primary);
                                    line-height: 25px;
                                    font-size: 14px;
                                }
                            }
                        }
                    }

                    .section-content {
                        color: var(--theme-text-inverse);

                        .review-actions {
                            display: flex;
                            padding: 10px 0 10px 10px;
                        }
                    }
                }
            }
        }
    }
}

// 表格相关样式
.operation-buttons {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.table-header {
    margin: 10px 0 10px 10px;
    display: flex;
    justify-content: flex-start;
}

.attachment-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;

    .attachment-name {
        font-size: 12px;
        color: var(--theme-text-color);
    }
}
</style>
