<template>
  <div class="add-project-container">
    <div class="add-project-content" v-loading="loading">
      <routerBack
        :show-save="!loading && !isPreview"
        :loading="loading"
        @save="saveClick"
      />

      <div class="tabs-content">
        <div class="project-tab-content">
          <div class="tab-content">
            <el-form :model="formData" label-width="150" :disabled="isPreview">
              <el-collapse v-model="activeCollapse">
                <!-- 基本信息 -->
                <el-collapse-item title="基本信息" name="基本信息">
                  <el-row :gutter="20">
                    <el-col :span="12">
                      <el-form-item label="参股公司名称" required>
                        <el-select
                          v-model="formData.projectId"
                          placeholder="请选择参股公司名称"
                          no-data-text="暂无数据"
                          @change="changeProject"
                        >
                          <el-option
                            v-for="item in projectList"
                            :key="item.key"
                            :label="item.projectName"
                            :value="item.id"
                          ></el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="统一社会信用代码">
                        <el-input
                          v-model="formData.tyshxydm"
                          placeholder="请输入统一社会信用代码"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="境内/外">
                        <el-select
                          v-model="formData.jnw"
                          placeholder="请选择"
                          no-data-text="暂无数据"
                          clearable
                          @change="changeJnw"
                        >
                          <el-option
                            v-for="item in jnwList"
                            :key="item.key"
                            :label="item.name"
                            :value="item.key"
                          ></el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="省(境内)/洲际(境外)">
                        <el-select
                          v-model="formData.sjnzjjw"
                          placeholder="请选择"
                          no-data-text="暂无数据"
                          clearable
                          @change="changeSzj"
                        >
                          <el-option
                            v-for="item in szjList"
                            :key="item.key"
                            :label="item.name"
                            :value="item.key"
                          ></el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="地市（境内）/国家（境外）">
                        <el-select
                          v-model="formData.dsjngjjw"
                          placeholder="请选择"
                          no-data-text="暂无数据"
                          clearable
                          @change="changeDsgj"
                        >
                          <el-option
                            v-for="item in dsgjList"
                            :key="item.key"
                            :label="item.name"
                            :value="item.key"
                          ></el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="区县(境内)/国家(境外)">
                        <el-select
                          v-model="formData.qxjngjjw"
                          placeholder="请选择"
                          no-data-text="暂无数据"
                          clearable
                        >
                          <el-option
                            v-for="item in qxgjList"
                            :key="item.key"
                            :label="item.name"
                            :value="item.key"
                          ></el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="项目名称">
                        <el-input
                          v-model="formData.projectName"
                          placeholder="请输入项目名称"
                        />
                      </el-form-item>
                    </el-col>

                    <el-col :span="12">
                      <el-form-item label="项目编号">
                        <el-input
                          v-model="formData.projectCode"
                          placeholder="请输入项目编号"
                        />
                      </el-form-item>
                    </el-col>

                    <el-col :span="12">
                      <el-form-item label="申报单位">
                        <el-input
                          v-model="formData.sbdw"
                          placeholder="请输入申报单位"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="所属二级单位">
                        <el-input
                          v-model="formData.ssejdw"
                          placeholder="请输入所属二级单位"
                        />
                      </el-form-item>
                    </el-col>

                    <el-col :span="6">
                      <el-form-item label="投资主体层级">
                        <CommonSelector
                          v-model="formData.tzztcj"
                          dictName="investor_hierarchy"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="投资主体法人层级">
                        <CommonSelector
                          v-model="formData.sfjwqy"
                          dictName="sf"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="形成参股原因">
                        <CommonSelector
                          v-model="formData.xccgyy"
                          dictName="participation_reason"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="其他参股原因">
                        <el-input
                          v-model="formData.qtcgyy"
                          placeholder="请输入其他参股原因"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="参股分类">
                        <CommonSelector
                          v-model="formData.cgfl"
                          dictName="participation_class"
                        />
                      </el-form-item>
                    </el-col>

                    <el-col :span="6">
                      <el-form-item label="项目状态">
                        <el-input
                          v-model="formData.xmzt"
                          placeholder="请输入项目状态"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="是否集团主业">
                        <CommonSelector
                          v-model="formData.sfjtzy"
                          dictName="sf"
                          placeholder="请选择是否集团主业"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="是否属主业关联产业">
                        <CommonSelector
                          v-model="formData.sfszyglcy"
                          dictName="sf"
                          placeholder="请选择是否属主业关联产业"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="是否属于战略性持有或有培育期">
                        <CommonSelector
                          v-model="formData.sfsyzlxcyhzpyq"
                          dictName="sf"
                          placeholder="请选择是否属于战略性持有或有培育期"
                        />
                      </el-form-item>
                    </el-col>

                    <el-col :span="6">
                      <el-form-item label="财务报表类型">
                        <CommonSelector
                          v-model="formData.cwbblx"
                          dictName="participation_industry"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="所属行业">
                        <CommonSelector
                          v-model="formData.sshy"
                          dictName="participation_industry"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="是否为民营企业">
                        <CommonSelector
                          v-model="formData.sswmyqy"
                          dictName="sf"
                          placeholder="请选择是否为民营企业"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="决策批复时间">
                        <el-date-picker
                          v-model="formData.jcpfsj"
                          type="date"
                          placeholder="请选择决策批复时间"
                          format="YYYY-MM-DD"
                          value-format="YYYY-MM-DD"
                        />
                      </el-form-item>
                    </el-col>

                    <el-col :span="6">
                      <el-form-item label="参股形成时间">
                        <el-date-picker
                          v-model="formData.cgxcsj"
                          type="date"
                          placeholder="请选择参股形成时间"
                          format="YYYY-MM-DD"
                          value-format="YYYY-MM-DD"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="是否上市公司">
                        <CommonSelector
                          v-model="formData.sfssgs"
                          dictName="sf"
                          placeholder="请选择是否上市公司"
                        />
                      </el-form-item>
                    </el-col>

                    <el-col :span="6">
                      <el-form-item label="是否有民企股份">
                        <CommonSelector
                          v-model="formData.sfymqgf"
                          dictName="sf"
                          placeholder="请选择是否有民企股份"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="是否计划退出">
                        <CommonSelector
                          v-model="formData.sfjhtc"
                          dictName="sf"
                          placeholder="请选择是否计划退出"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="计划退出年份">
                        <el-date-picker
                          v-model="formData.jhtcnf"
                          type="year"
                          placeholder="请选择计划退出年份"
                          format="YYYY"
                          value-format="YYYY"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="是否为问题整改项目">
                        <CommonSelector
                          v-model="formData.sfwwtzgxm"
                          dictName="sf"
                          placeholder="请选择是否为问题整改项目"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="是否整改完成">
                        <CommonSelector
                          v-model="formData.sfzgwc"
                          dictName="sf"
                          placeholder="请选择是否整改完成"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="风险金额(万元)">
                        <el-input-number
                          precision="2"
                          v-model="formData.fxje"
                          placeholder="请输入风险金额(万元)"
                          :min="0"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="是否我方控制非并表企业">
                        <CommonSelector
                          v-model="formData.sfwfkzfbbqy"
                          dictName="sf"
                          placeholder="请选择是否我方控制非并表企业"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="是否民企团队实际运营">
                        <CommonSelector
                          v-model="formData.sfmqtdsjyy"
                          dictName="sf"
                          placeholder="请选择是否民企团队实际运营"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="是否潜亏">
                        <CommonSelector
                          v-model="formData.sfqk"
                          dictName="sf"
                          placeholder="请选择是否潜亏"
                        />
                      </el-form-item>
                    </el-col>

                    <el-col :span="6">
                      <el-form-item label="参股权持有损益">
                        <el-input
                          v-model="formData.cgqcysy"
                          placeholder="请输入参股权持有损益"
                        />
                      </el-form-item>
                    </el-col>

                    <el-col :span="24">
                      <el-form-item label="主营业务">
                        <el-input
                          v-model="formData.zyyw"
                          type="textarea"
                          :rows="2"
                          placeholder="请输入主营业务"
                        />
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <DynamicTable
                    :showAddButton="!isPreview"
                    :columns="transferColumns"
                    :disabled="isPreview"
                    v-model="formData.gmzbjed"
                  />
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="批复文件">
                        <FileUploader
                          v-model="formData.pfwj"
                          :disabled="isPreview"
                        ></FileUploader>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="营业执照">
                        <FileUploader
                          v-model="formData.yyzz"
                          :disabled="isPreview"
                        ></FileUploader>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="合作协议">
                        <FileUploader
                          v-model="formData.hzxy"
                          :disabled="isPreview"
                        ></FileUploader>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-collapse-item>

                <!-- 填报信息 -->
                <el-collapse-item title="填报信息" name="填报信息">
                  <el-row>
                    <el-col :span="6">
                      <el-form-item label="参股公司管理人员">
                        <el-input
                          v-model="formData.cggsglry"
                          placeholder="请输入参股公司管理人员"
                        ></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="在参股公司任职务">
                        <el-input
                          v-model="formData.zcggsrzzw"
                          placeholder="请输入在参股公司任职务"
                        ></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="电话">
                        <el-input
                          v-model="formData.dh"
                          placeholder="请输入电话"
                        ></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="信息填报人">
                        <el-input
                          v-model="formData.xxtbr"
                          placeholder="请输入信息填报人"
                        ></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="单位及职务">
                        <el-input
                          v-model="formData.dwjzw"
                          placeholder="请输入单位及职务"
                        ></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="联系电话">
                        <el-input
                          v-model="formData.lxdh"
                          placeholder="请输入联系电话"
                        ></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="更新上报年度">
                        <el-date-picker
                          v-model="formData.gxsbnd"
                          type="year"
                          placeholder="请选择更新上报年度"
                          format="YYYY"
                          value-format="YYYY"
                        ></el-date-picker>
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="更新上报季度">
                        <CommonSelector
                          v-model="formData.gxsbjd"
                          dictName="quarter"
                          placeholder="请选择更新上报季度"
                        ></CommonSelector>
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="更新日期">
                        <el-date-picker
                          v-model="formData.gxrq"
                          type="date"
                          placeholder="请选择更新日期"
                          format="YYYY-MM-DD"
                          value-format="YYYY-MM-DD"
                        ></el-date-picker>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-collapse-item>
                <el-collapse-item title="大股东信息" name="大股东信息">
                  <DynamicTable
                    :showAddButton="!isPreview"
                    :columns="dgdxxCok1"
                    :disabled="isPreview"
                    v-model="formData.gd1"
                  />
                  <DynamicTable
                    :showAddButton="!isPreview"
                    :columns="dgdxxCok2"
                    :disabled="isPreview"
                    v-model="formData.gd2"
                  />
                  <DynamicTable
                    :showAddButton="!isPreview"
                    :columns="dgdxxCok3"
                    :disabled="isPreview"
                    v-model="formData.gd3"
                  />

                  <el-row style="margin-top: 16px">
                    <el-col :span="8">
                      <el-form-item
                        label-width="200px"
                        label="国有股东合计股比（%）"
                      >
                        <el-input
                          v-model="formData.gygdhjgb"
                          placeholder="请选择国有股东合计股比（%）"
                        ></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="8">
                      <el-form-item
                        label-width="200px"
                        label="能见参股合计（%）"
                      >
                        <el-input
                          v-model="formData.njcghj"
                          placeholder="请选择能见参股合计（%）"
                        ></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="8">
                      <el-form-item
                        label-width="200px"
                        label="一致行动人股比合计（%）"
                      >
                        <el-input
                          v-model="formData.tzxdrgbhj"
                          placeholder="请选择一致行动人股比合计（%）"
                        ></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-collapse-item>
                <el-collapse-item title="股东信息" name="股东信息">
                  <DynamicTable
                    :showAddButton="!isPreview"
                    :columns="dgdxxCok4"
                    :disabled="isPreview"
                    v-model="formData.gdxx"
                  />
                  <el-row>
                    <el-col :span="24">
                      <el-form-item label-width="90" label="章程">
                        <FileUploader
                          v-model="formData.zc"
                          :disabled="isPreview"
                        ></FileUploader>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-collapse-item>

                <!-- 出资信息 -->
                <el-collapse-item title="出资信息" name="出资信息">
                  <el-row :gutter="20">
                    <el-col :span="8">
                      <el-form-item
                        label-width="300px"
                        label="企业工商注册资本金（万元）"
                      >
                        <el-input-number
                          precision="2"
                          v-model="formData.qygszczbj"
                          placeholder="请输入企业工商注册资本金（万元）"
                        />
                      </el-form-item>
                    </el-col>

                    <el-col :span="8">
                      <el-form-item
                        label-width="300px"
                        label="我方认缴企业工商注册资本金（万元）"
                      >
                        <el-input-number
                          precision="2"
                          v-model="formData.wfrjqygszczbj"
                          placeholder="请输入我方认缴企业工商注册资本金（万元）"
                        />
                      </el-form-item>
                    </el-col>

                    <el-col :span="8">
                      <el-form-item
                        label-width="300px"
                        label="工商注册资本金我方实际已出资金额（万元）"
                      >
                        <el-input-number
                          precision="2"
                          v-model="formData.gszczbjwfsjyczje"
                          placeholder="请输入工商注册资本金我方实际已出资金额（万元）"
                        />
                      </el-form-item>
                    </el-col>

                    <el-col :span="8">
                      <el-form-item
                        label-width="300px"
                        label="企业工商注册资本金我方首次出资时间"
                      >
                        <el-date-picker
                          v-model="formData.qygszczbjwfscczsj"
                          type="date"
                          placeholder="请选择企业工商注册资本金我方首次出资时间"
                          format="YYYY-MM-DD"
                          value-format="YYYY-MM-DD"
                        />
                      </el-form-item>
                    </el-col>

                    <el-col :span="8">
                      <el-form-item
                        label-width="300px"
                        label="我方参股比例（%）"
                      >
                        <el-input-number
                          precision="2"
                          v-model="formData.wfcgbl"
                          placeholder="请输入我方参股比例（%）"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="8">
                      <el-form-item
                        label-width="300px"
                        label="能建合计认缴工商注册资本金比例（%）"
                      >
                        <el-input-number
                          precision="2"
                          v-model="formData.njhjrjgszczbjbl"
                          placeholder="请输入能建合计认缴工商注册资本金比例（%）"
                        />
                      </el-form-item>
                    </el-col>

                    <el-col :span="8">
                      <el-form-item
                        label-width="300px"
                        label="能建合计认缴工商注册资本金（万元）"
                      >
                        <el-input-number
                          precision="2"
                          v-model="formData.njhjrjgszczbj"
                          placeholder="请输入能建合计认缴工商注册资本金（万元）"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="8">
                      <el-form-item
                        label-width="300px"
                        label="能建合计实缴工商注册资本金（万元）"
                      >
                        <el-input-number
                          precision="2"
                          v-model="formData.njhjsjgszczbj"
                          placeholder="请输入能建合计实缴工商注册资本金（万元）"
                        />
                      </el-form-item>
                    </el-col>
                  </el-row>

                  <el-row :gutter="20">
                    <el-col :span="6">
                      <el-form-item
                        label-width="300px"
                        label="项目资本金（万元）"
                      >
                        <el-input-number
                          precision="2"
                          v-model="formData.xmzbj"
                          placeholder="请输入项目资本金（万元）"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item
                        label-width="300px"
                        label="我方认缴项目资本金比例（%）"
                      >
                        <el-input-number
                          precision="2"
                          v-model="formData.wfrjxmzbjbl"
                          placeholder="请输入我方认缴项目资本金比例（%）"
                        />
                      </el-form-item>
                    </el-col>

                    <el-col :span="6">
                      <el-form-item
                        label-width="300px"
                        label="我方认缴项目资本金（万元）"
                      >
                        <el-input-number
                          precision="2"
                          v-model="formData.wfrjxmzbj"
                          placeholder="请输入我方认缴项目资本金（万元）"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item
                        label-width="300px"
                        label="我方实缴项目资本金（万元）"
                      >
                        <el-input-number
                          precision="2"
                          v-model="formData.wfsjxmzbj"
                          placeholder="请输入我方实缴项目资本金（万元）"
                        />
                      </el-form-item>
                    </el-col>

                    <el-col :span="6">
                      <el-form-item
                        label-width="300px"
                        label="项目资本金能建合计持股比例（%）"
                      >
                        <el-input-number
                          precision="2"
                          v-model="formData.xmzbjnjhjcgbl"
                          placeholder="请输入项目资本金能建合计持股比例（%）"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item
                        label-width="300px"
                        label="能建合计认缴项目资本金（万元）"
                      >
                        <el-input-number
                          precision="2"
                          v-model="formData.njhjrjxmzbj"
                          placeholder="请输入能建合计认缴项目资本金（万元）"
                        />
                      </el-form-item>
                    </el-col>

                    <el-col :span="6">
                      <el-form-item
                        label-width="300px"
                        label="能建合计实缴项目资本金（万元）"
                      >
                        <el-input-number
                          precision="2"
                          v-model="formData.njhjsjxmzbj"
                          placeholder="请输入能建合计实缴项目资本金（万元）"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="24">
                      <el-form-item label-width="300px" label="出资文件">
                        <FileUploader
                          v-model="formData.czwj"
                          :disabled="isPreview"
                        ></FileUploader>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-collapse-item>

                <!-- 财务经营信息 -->
                <el-collapse-item title="财务经营信息" name="财务经营信息">
                  <DynamicTable
                    :showAddButton="!isPreview"
                    :columns="dgdxxCok5"
                    :disabled="isPreview"
                    v-model="formData.zxnfcwjyxx"
                  />
                  <DynamicTable
                    :showAddButton="!isPreview"
                    :columns="dgdxxCok10"
                    :disabled="isPreview"
                    v-model="formData.zxnfcwjyxx2"
                  />
                </el-collapse-item>

                <!-- 分红与投资情况 -->
                <el-collapse-item title="分红与投资情况" name="分红与投资情况">
                  <el-row :gutter="20">
                    <el-col :span="12">
                      <el-form-item
                        label-width="260px"
                        label="2019年以前累计确认分红金额（万元）"
                      >
                        <el-input-number
                          precision="2"
                          v-model="formData.yqljqrfhje"
                          placeholder="请输入2019年以前累计确认分红金额（万元）"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item
                        label-width="260px"
                        label="2019年以前累计收到分红金额（万元）"
                      >
                        <el-input-number
                          precision="2"
                          v-model="formData.yqljsdfhje"
                          placeholder="请输入2019年以前累计收到分红金额（万元）"
                        />
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="20">
                    <el-col :span="12">
                      <el-form-item
                        label-width="260px"
                        label="历年累计确认分红金额（万元）"
                      >
                        <el-input-number
                          precision="2"
                          v-model="formData.lnljsdfhje"
                          placeholder="请输入历年累计确认分红金额（万元）"
                        />
                      </el-form-item>
                    </el-col>

                    <el-col :span="12">
                      <el-form-item
                        label-width="260px"
                        label="累计参股投资回报率（%）"
                      >
                        <el-input-number
                          precision="2"
                          v-model="formData.ljcgtzhbl"
                          placeholder="请输入累计参股投资回报率（%）"
                        />
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="20">
                    <el-col :span="12">
                      <el-form-item
                        label-width="260px"
                        label="归属集团内投资主体所有权益（万元）"
                      >
                        <el-input-number
                          precision="2"
                          v-model="formData.gsjtntzztgyqy"
                          placeholder="请输入归属集团内投资主体所有权益（万元）"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item
                        label-width="260px"
                        label="总体参股投资保值增值率（%）"
                      >
                        <el-input-number
                          precision="2"
                          v-model="formData.ztcgtzbzzzl"
                          placeholder="请输入总体参股投资保值增值率（%）"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item
                        label-width="260px"
                        label="是否能够及时掌握财务数据和经营情况"
                      >
                        <CommonSelector
                          v-model="formData.sfnjszwcwsjhjyqk"
                          dictName="sf"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item
                        label-width="260px"
                        label="逾期超过1年的应收款金额（万元）"
                      >
                        <CommonSelector
                          v-model="formData.yqcg1ndyszkje"
                          dictName="sf"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item
                        label-width="260px"
                        label="收回逾期超过1年的应收款金额（万元）"
                      >
                        <CommonSelector
                          v-model="formData.shyqcg1ndyszkje"
                          dictName="sf"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item
                        label-width="260px"
                        label="是否满五年未分红"
                      >
                        <CommonSelector
                          v-model="formData.sfm5nwfh"
                          dictName="sf"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item
                        label-width="260px"
                        label="是否连续5年长期亏损"
                      >
                        <CommonSelector
                          v-model="formData.sflx5ncqks"
                          dictName="sf"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label-width="260px" label="是否非持续经营">
                        <CommonSelector
                          v-model="formData.sffcxjy"
                          dictName="sf"
                        />
                      </el-form-item>
                    </el-col>

                    <el-col :span="12">
                      <el-form-item
                        label-width="260px"
                        label="是否属于低效无效资产"
                      >
                        <CommonSelector
                          v-model="formData.sfsydxwxzc"
                          dictName="sf"
                        />
                      </el-form-item>
                    </el-col>

                    <el-col :span="12">
                      <el-form-item label-width="260px" label="拉动营收">
                        <el-input-number
                          precision="2"
                          v-model="formData.ldys"
                          placeholder="请输入拉动营收"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label-width="260px" label="拉动利润">
                        <el-input-number
                          precision="2"
                          v-model="formData.ldlr"
                          placeholder="请输入拉动利润"
                        />
                      </el-form-item>
                    </el-col>

                    <el-col :span="12">
                      <el-form-item label-width="260px" label="当前持有损益">
                        <el-input-number
                          precision="2"
                          v-model="formData.dqcysy"
                          placeholder="请输入当前持有损益"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="24">
                      <el-form-item label-width="260px" label="财务报表文件">
                        <FileUploader
                          v-model="formData.cwbbwj"
                          :disabled="isPreview"
                        ></FileUploader>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-collapse-item>

                <!-- 法人治理 -->
                <el-collapse-item title="法人治理" name="法人治理">
                  <DynamicTable
                    :showAddButton="!isPreview"
                    :columns="dgdxxCok8"
                    :disabled="isPreview"
                    v-model="formData.frzl"
                  />

                  <DynamicTable
                    :showAddButton="!isPreview"
                    :columns="dgdxxCok9"
                    :disabled="isPreview"
                    v-model="formData.frzl2"
                  />

                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="董监高任命文件">
                        <FileUploader
                          v-model="formData.djgrmwj"
                          :disabled="isPreview"
                        ></FileUploader>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="股东会文件">
                        <FileUploader
                          v-model="formData.gdhwj"
                          :disabled="isPreview"
                        ></FileUploader>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="董事会决议文件">
                        <FileUploader
                          v-model="formData.dshjywj"
                          :disabled="isPreview"
                        ></FileUploader>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-collapse-item>

                <!-- 集团内投资主体相关信息 -->
                <el-collapse-item title="其他信息" name="其他信息">
                  <DynamicTable
                    :showAddButton="!isPreview"
                    :columns="dgdxxCok6"
                    :disabled="isPreview"
                    v-model="formData.qtxx"
                  />
                  <DynamicTable
                    :showAddButton="!isPreview"
                    :columns="dgdxxCok7"
                    :disabled="isPreview"
                    v-model="formData.qtxx2"
                  />
                </el-collapse-item>

                <!-- 股权退出信息 -->
                <el-collapse-item title="股权退出信息" name="股权退出信息">
                  <el-row :gutter="20">
                    <el-col :span="12">
                      <el-form-item
                        label-width="260px"
                        label="股权是否退出"
                        required
                      >
                        <CommonSelector
                          v-model="formData.gqsftc"
                          dictName="sf"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item
                        label-width="260px"
                        label="股权退出收回资金（万元）"
                      >
                        <el-input-number
                          precision="2"
                          v-model="formData.gqtcshzj"
                          placeholder="请输入股权退出收回资金（万元）"
                        />
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="20">
                    <el-col :span="12">
                      <el-form-item label-width="260px" label="股权退出时间">
                        <el-date-picker
                          v-model="formData.gqtcsj"
                          type="date"
                          placeholder="请选择股权退出时间"
                          format="YYYY-MM-DD"
                          value-format="YYYY-MM-DD"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item
                        label-width="260px"
                        label="股权退出收回资金到账金额（万元）"
                      >
                        <el-input-number
                          precision="2"
                          v-model="formData.gqtcshzjdzje"
                          placeholder="请输入股权退出收回资金到账金额（万元）"
                        />
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="20">
                    <el-col :span="12">
                      <el-form-item
                        label-width="260px"
                        label="股权退出收回资金到账时间"
                      >
                        <el-date-picker
                          v-model="formData.gqtcshzjdzsj"
                          type="date"
                          placeholder="请选择股权退出收回资金到账时间"
                          format="YYYY-MM-DD"
                          value-format="YYYY-MM-DD"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="24">
                      <el-form-item label-width="260px" label="股权退出原因">
                        <el-input
                          v-model="formData.gqtcyy"
                          type="textarea"
                          :rows="3"
                          placeholder="请输入股权退出原因"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="24">
                      <el-form-item label-width="260px" label="退出文件">
                        <FileUploader
                          v-model="formData.tcwj"
                          :disabled="isPreview"
                        ></FileUploader>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-collapse-item>

                <!-- 自查问题整改信息 -->
                <el-collapse-item
                  title="自查问题整改信息"
                  label-width="260px"
                  name="自查问题整改信息"
                >
                  <el-row :gutter="20">
                    <el-col :span="12">
                      <el-form-item
                        label="自查是否发现问题"
                        label-width="260px"
                        required
                      >
                        <CommonSelector
                          v-model="formData.sfwwtzgxm"
                          dictName="sf"
                        />
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="20">
                    <el-col :span="24">
                      <el-form-item
                        label-width="260px"
                        label="自查发现的主要问题及整改计划"
                      >
                        <el-input
                          v-model="formData.dbqk"
                          type="textarea"
                          :rows="4"
                          placeholder="请输入自查发现的主要问题及整改计划"
                        />
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="20">
                    <el-col :span="24">
                      <el-form-item label-width="260px" label="备注">
                        <el-input
                          v-model="formData.bz"
                          type="textarea"
                          :rows="4"
                          placeholder="请输入备注"
                        />
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-collapse-item>
              </el-collapse>
            </el-form>
          </div>
        </div>
      </div>
      <div class="add-project-header">
        <div class="header-left"></div>
        <div class="header-right">
          <el-button type="default" @click="backClick">返回</el-button>
          <template v-if="!loading && !isPreview">
            <el-button type="primary" @click="saveClick">保存</el-button>
          </template>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { reactive, ref, onMounted, getCurrentInstance } from "vue";
import { useRouter, useRoute } from "vue-router";
import { ElMessage, ElMessageBox } from "element-plus";
import routerBack from "@/components/common/routerBack.vue";
import DynamicTable from "@/components/FormDynamicTable/index.vue";
import FileUploader from "@/components/FileUploader/index.vue";

const router = useRouter();
const route = useRoute();
const { proxy } = getCurrentInstance();

// 规模指标及额度表格列配置
const transferColumns = ref([
  {
    prop: "njfcgbl1",
    label: "十二大业务板块",
    type: "input",
    headerGroup: "规模指标及额度",
    placeholder: "十二大业务板块名称",
  },
  {
    prop: "njfcgbl2",
    label: "指标名称",
    type: "input",
    headerGroup: "规模指标及额度",
    placeholder: "指标名称",
  },
  {
    prop: "njfcgbl3",
    label: "数量",
    type: "input",
    headerGroup: "规模指标及额度",
    placeholder: "数量",
  },
  {
    prop: "njfcgbl4",
    label: "单位",
    type: "input",
    headerGroup: "规模指标及额度",
    placeholder: "单位",
  },
]);

// 折叠面板默认展开项
const activeCollapse = ref([
  "基本信息",
  "规模指标及额度",
  "填报信息",
  "大股东信息",
  "股东信息",
  "出资信息",
  "财务经营信息",
  "分红与投资情况",
  "法人治理",
  "其他信息",
  "股权退出信息",
  "自查问题整改信息",
]);

// 控股股东信息
const dgdxxCok1 = ref([
  {
    prop: "konggu_gudong_name",
    label: "控股股东",
    type: "input",
    placeholder: "控股股东名称",
  },
  {
    prop: "konggu_gudong_nature",
    label: "股东性质",
    type: "input",
    placeholder: "股东性质名称",
  },
  {
    prop: "konggu_gudong_ratio",
    label: "股比（%）",
    type: "input",
    placeholder: "股比（%）名称",
  },
  {
    prop: "is_group_member_unit",
    label: "是否集团内成员单位",
    type: "select",
    optionKey: "sf",
    placeholder: "是否集团内成员单位名称",
  },
]);

// 第一大股东信息
const dgdxxCok2 = ref([
  {
    prop: "first_gudong_name",
    label: "第一大股东",
    type: "input",
    placeholder: "第一大股东名称",
  },
  {
    prop: "first_gudong_nature",
    label: "股东性质",
    type: "input",
    placeholder: "股东性质名称",
  },
  {
    prop: "first_gudong_ratio",
    label: "股比（%）",
    type: "input",
    placeholder: "股比（%）名称",
  },
  {
    prop: "first_gudong_is_group_member",
    label: "是否集团内成员单位",
    type: "select",
    optionKey: "sf",
    placeholder: "是否集团内成员单位名称",
  },
]);

// 平股股东信息
const dgdxxCok3 = ref([
  {
    prop: "pinggu_gudong_name",
    label: "平股",
    type: "input",
    placeholder: "平股名称",
  },
  {
    prop: "pinggu_gudong_nature",
    label: "股东性质",
    type: "input",
    placeholder: "股东性质名称",
  },
  {
    prop: "pinggu_gudong_ratio",
    label: "股比（%）",
    type: "input",
    placeholder: "股比（%）名称",
  },
  {
    prop: "pinggu_gudong_is_group_member",
    label: "是否集团内成员单位",
    type: "select",
    optionKey: "sf",
    placeholder: "是否集团内成员单位",
  },
]);

// 通用股东信息
const dgdxxCok4 = ref([
  {
    prop: "gudong_name",
    label: "股东名称",
    type: "input",
    placeholder: "股东名称",
  },
  {
    prop: "gudong_nature",
    label: "股东性质",
    type: "input",
    placeholder: "股东性质",
  },
  {
    prop: "gudong_ratio",
    label: "股比（%）",
    type: "input",
    placeholder: "股比（%）",
  },
  {
    prop: "is_konggu_gudong",
    label: "是否控股股东",
    type: "select",
    optionKey: "sf",
    placeholder: "是否控股股东",
  },
  {
    prop: "is_group_member",
    label: "是否集团内成员单位",
    type: "select",
    optionKey: "sf",
    placeholder: "是否集团内成员单位",
  },
  {
    prop: "is_out_of_control",
    label: "是否失控单位",
    type: "select",
    optionKey: "sf",
    placeholder: "是否失控单位",
  },
  {
    prop: "is_consistent_actor",
    label: "是否一致行动人",
    type: "select",
    optionKey: "sf",
    placeholder: "是否一致行动人",
  },
]);

// 最新年份财务经营信息
const dgdxxCok5 = ref([
  {
    prop: "total_assets",
    headerGroup: "最新年份财务经营信息",
    label: "总资产（万元）",
    type: "input",
    placeholder: "总资产（万元）",
  },
  {
    prop: "net_assets_audited",
    headerGroup: "最新年份财务经营信息",
    label: "净资产（审计后）万元",
    type: "input",
    placeholder: "净资产（审计后）万元",
  },
  {
    prop: "net_assets_nengjian",
    headerGroup: "最新年份财务经营信息",
    label: "归属能建方净资产（万元）",
    type: "input",
    placeholder: "归属能建方净资产（万元）",
  },
  {
    prop: "operating_income",
    headerGroup: "最新年份财务经营信息",
    label: "营业收入（万元）",
    type: "input",
    placeholder: "营业收入（万元）",
  },
  {
    prop: "net_profit",
    headerGroup: "最新年份财务经营信息",
    label: "净利润（万元）",
    type: "input",
    placeholder: "净利润（万元）",
  },
  {
    prop: "dividend_nengjian_decision",
    headerGroup: "最新年份财务经营信息",
    label: "归属能建方年度决策分红（万元）",
    type: "input",
    placeholder: "归属能建方年度决策分红（万元）",
  },
  {
    prop: "dividend_decision_time",
    headerGroup: "最新年份财务经营信息",
    label: "股东会决策分红时间",
    type: "input",
    placeholder: "股东会决策分红时间",
  },
  {
    prop: "dividend_decision_time_dup", // 原重复label，保留唯一prop
    headerGroup: "最新年份财务经营信息",
    label: "股东会决策分红时间",
    type: "input",
    placeholder: "股东会决策分红时间",
  },
  {
    prop: "dividend_received_nengjian",
    headerGroup: "最新年份财务经营信息",
    label: "归属能建方年度已收到分红（万元）",
    type: "input",
    placeholder: "古树能建方年度已收到分工（万元）", // 原错别字保留，如需修正可改为"归属能建方年度已收到分红（万元）"
  },
  {
    prop: "dividend_received_time",
    headerGroup: "最新年份财务经营信息",
    label: "实际收到分红时间",
    type: "input",
    placeholder: "实际收到分红时间",
  },
  {
    prop: "related_transaction_ratio",
    headerGroup: "最新年份财务经营信息",
    label: "本年度与集团内投资主体关联交易收入占该被投资企业营业收入比例（%）",
    type: "input",
    placeholder:
      "本年度与集团内投资主体关联交易收入占该被投资企业营业收入比例（%）",
  },
]);

// 历年财务经营信息
const dgdxxCok10 = ref([
  {
    prop: "financial_year",
    label: "年度",
    type: "input",
    placeholder: "年度",
  },
  {
    prop: "yearly_total_assets",
    label: "总资产（万元）",
    type: "input",
    placeholder: "总资产（万元）",
  },
  {
    prop: "yearly_net_assets_audited",
    label: "净资产（审计后）（万元）",
    type: "input",
    placeholder: "净资产（审计后）（万元）",
  },
  {
    prop: "yearly_net_assets_nengjian",
    label: "归属能建方净资产（万元）",
    type: "input",
    placeholder: "归属能建方净资产（万元）",
  },
  {
    prop: "yearly_operating_income",
    label: "营业收入（万元）",
    type: "input",
    placeholder: "营业收入（万元）",
  },
  {
    prop: "yearly_net_profit",
    label: "净利润（万元）",
    type: "input",
    placeholder: "净利润（万元）",
  },
  {
    prop: "yearly_dividend_nengjian_decision",
    label: "归属能建方年度决策分红（万元）",
    type: "input",
    placeholder: "归属能建方年度决策分红（万元）",
  },
  {
    prop: "yearly_dividend_decision_time",
    label: "股东会决策分红时间",
    type: "input",
    placeholder: "股东会决策分红时间",
  },
  {
    prop: "yearly_dividend_received_nengjian",
    label: "归属能建方年度已收到分红（万元）",
    type: "input",
    placeholder: "归属能建方年度已收到分红（万元）",
  },
]);

const dgdxxCok6 = ref([
  {
    prop: "use_group_qualification",
    headerGroup: "是否使用集团内投资主体字号、经营资质",
    label: "是否",
    type: "select",
    optionKey: "sf",
  },
  {
    prop: "qualification_name",
    headerGroup: "是否使用集团内投资主体字号、经营资质",
    label: "字号及经营资质名称",
    type: "input",
    placeholder: "字号及经营资质名称",
  },
  {
    prop: "use_group_trademark",
    headerGroup: "是否使用集团内投资主体产品注册商标",
    label: "是否",
    type: "select",
    optionKey: "sf",
    placeholder: "是否",
  },
  {
    prop: "is_fair_price",
    headerGroup: "是否使用集团内投资主体产品注册商标",
    label: "是否采取公允价格",
    type: "select",
    optionKey: "sf",
    placeholder: "是否采取公允价格",
  },
]);

// 担保及产权登记信息
const dgdxxCok7 = ref([
  {
    prop: "group_guarantee",
    headerGroup: "集团内投资主体实际担保",
    label: "是否",
    type: "select",
    optionKey: "sf",
    placeholder: "是否",
  },
  {
    prop: "guarantee_amount",
    headerGroup: "集团内投资主体实际担保",
    label: "担保金额（万元）",
    type: "input",
    placeholder: "担保金额（万元）",
  },
  {
    prop: "super_ratio_guarantee",
    headerGroup: "集团内投资主体实际担保",
    label: "其中：超级权比担保金额",
    type: "input",
    placeholder: "是否", // 原placeholder可能有误，保留原样
  },
  {
    prop: "state_owned_property_reg",
    headerGroup: " ",
    label: "是否办理国有产权登记",
    type: "select",
    optionKey: "sf",
    placeholder: "是否办理国有产权登记",
  },
]);

// 人员选派及否决权信息
const dgdxxCok8 = ref([
  {
    prop: "shareholder_rep_agreed",
    headerGroup: " ",
    label: "章程约定派出股东代表人数",
    type: "input",
    placeholder: "章程约定派出股东代表人数",
  },
  {
    prop: "shareholder_rep_actual",
    headerGroup: " ",
    label: "实际派出股东代表人数",
    type: "input",
    placeholder: "实际派出股东代表人数",
  },
  {
    prop: "director_selection_type",
    headerGroup: "章程约定选派董事、监事或重要岗位人员情况",
    label: "选派类型",
    type: "input",
    placeholder: "选派类型",
  },
  {
    prop: "director_position_name",
    headerGroup: "章程约定选派董事、监事或重要岗位人员情况",
    label: "重要岗位名称",
    type: "input",
    placeholder: "重要岗位名称",
  },
  {
    prop: "director_total_count",
    headerGroup: "章程约定选派董事、监事或重要岗位人员情况",
    label: "总共人数",
    type: "input",
    placeholder: "总共人数",
  },
  {
    prop: "actual_director_selection_type",
    headerGroup: "实际约定选派董事、监事或重要岗位人员情况",
    label: "选派类型",
    type: "input",
    placeholder: "选派类型",
  },
  {
    prop: "actual_director_position_name",
    headerGroup: "实际约定选派董事、监事或重要岗位人员情况",
    label: "重要岗位名称",
    type: "input",
    placeholder: "重要岗位名称",
  },
  {
    prop: "actual_director_total_count",
    headerGroup: "实际约定选派董事、监事或重要岗位人员情况",
    label: "总共人数",
    type: "input",
    placeholder: "总共人数",
  },
  {
    prop: "has_veto_right",
    headerGroup: "是否有特定事项否决权",
    label: "是否",
    type: "select",
    optionKey: "sf",
    placeholder: "是否",
  },
  {
    prop: "veto_right_content",
    headerGroup: "是否有特定事项否决权",
    label: "是否权内容",
    type: "input",
    placeholder: "是否权内容", // 原label可能有误，保留原样
  },
]);

// 整改及党组织信息
const dgdxxCok9 = ref([
  {
    prop: "personnel_adjust_count",
    label: "2020年自查整改至今新派出和调整参股企业董事监事及重要岗位人员人数",
    type: "input",
    placeholder:
      "2020年自查整改至今新派出和调整参股企业董事监事及重要岗位人员人数",
  },
  {
    prop: "part_time_regulate_count",
    label: "2020年自查整改至今规范领导人员兼职人数",
    type: "input",
    placeholder: "2020年自查整改至今规范领导人员兼职人数",
  },
  {
    prop: "articles_revise_count",
    label: "2020年自查整改至今新增或修订参股企业公司章程条数",
    type: "input",
    placeholder: "2020年自查整改至今新增或修订参股企业公司章程条数",
  },
  {
    prop: "has_party_organization",
    label: "是否简历党的组织",
    type: "select",
    optionKey: "sf",
    placeholder: "是否简历党的组织", // 原错别字保留，如需修正可改为"是否建立党的组织"
  },
]);

// 表单数据

// 地区级联选择数据
let jnwList = reactive([]); // 境内/外 // 级联
let szjList = ref([]); // 省（境内）/洲际（境外） // 级联
let dsgjList = ref([]); // 地市（境内）/国家（境外） // 级联
let qxgjList = ref([]); // 区县（境内）/国家（境外） // 级联

// 境内/外改变事件
const changeJnw = (val) => {
  if (val || val === 0) {
    let selectData = jnwList.filter((item) => item.key == val);
    szjList.value = (selectData[0] && selectData[0].children) || [];
  } else {
    szjList.value = [];
  }
  dsgjList.value = [];
  qxgjList.value = [];
  delete formData.sjnzjjw;
  delete formData.dsjngjjw;
  delete formData.qxjngjjw;
};

// 省/洲改变事件
const changeSzj = (val) => {
  if (val || val === 0) {
    let selectData = szjList.value.filter((item) => item.key == val);
    dsgjList.value = (selectData[0] && selectData[0].children) || [];
  } else {
    dsgjList.value = [];
  }
  qxgjList.value = [];
  delete formData.dsjngjjw;
  delete formData.qxjngjjw;
};

// 地市/国家改变事件
const changeDsgj = (val) => {
  if (val || val === 0) {
    let selectData = dsgjList.value.filter((item) => item.key == val);
    qxgjList.value = (selectData[0] && selectData[0].children) || [];
  } else {
    qxgjList.value = [];
  }
  delete formData.qxjngjjw;
};

const formData = reactive({
  gmzbjed: [{}],
  gd1: [{}],
  gdxx: [{}],
  gd2: [{}],
  gd3: [{}],
  frzl: [{}],
  frzl2: [{}],
  qtxx: [{}],
  qtxx2: [{}],
  zxnfcwjyxx: [{}],
  zxnfcwjyxx2: [{}],
});

// 加载状态
const loading = ref(false);
// 是否预览模式
const isPreview = ref(!!route.query.isPreview);
// 项目列表数据
const projectList = ref([]);
// 当前编辑的记录ID
const rcCgqyglId = ref(route.query.id || "");

// 获取项目列表
const getProjectData = (params = {}) => {
  proxy.$post({
    url: "/api/project/listProject",
    data: {
      page: 1,
      pagesize: 1000,
      attributes: [],
      menuType: "xmjc",
      ...params,
    },
    callback: (data) => {
      projectList.value = data.rows || [];
    },
  });
};

// 选择项目后同步项目名称
const changeProject = (val) => {
  const selectItem = projectList.value.find((item) => item.id === val);
  if (selectItem) {
    formData.projectName = selectItem.projectName;
  }
};

// 获取单条记录详情（编辑/预览）
const getRcCgqyglDetail = () => {
  if (!rcCgqyglId.value) return;

  loading.value = true;
  proxy.$post({
    url: "/api/project/getCgqygl",
    data: { id: rcCgqyglId.value },
    callback: (data) => {
      loading.value = false;
      Object.assign(formData, data);

      // 处理财务信息列表

      // 处理地区级联回显
      if (data.jnw || data.jnw === 0) {
        let selectData = jnwList.filter((item) => item.key == data.jnw);
        szjList.value = (selectData[0] && selectData[0].children) || [];
      }
      if (data.sjnzjjw || data.sjnzjjw === 0) {
        let selectData = szjList.value.filter(
          (item) => item.key == data.sjnzjjw
        );
        dsgjList.value = (selectData[0] && selectData[0].children) || [];
      }
      if (data.dsjngjjw || data.dsjngjjw === 0) {
        let selectData = dsgjList.value.filter(
          (item) => item.key == data.dsjngjjw
        );
        qxgjList.value = (selectData[0] && selectData[0].children) || [];
      }
    },
  });
};

// 返回按钮
const backClick = () => {
  router.back(-1);
};

// 保存/提交表单
const saveClick = () => {
  // 基础校验
  if (!formData.projectId) {
    ElMessage.warning("请选择项目信息");
    return;
  }

  loading.value = true;
  // 区分新增/编辑
  const url = rcCgqyglId.value
    ? "/api/project/updateCgqygl"
    : "/api/project/createCgqygl";

  // 组装提交数据
  const submitData = {
    ...formData,
    projectId: formData.projectId + "",
  };

  proxy.$post({
    url: url,
    data: submitData,
    callback: (res) => {
      loading.value = false;
      ElMessage.success(rcCgqyglId.value ? "编辑成功" : "新增成功");
      router.back(-1);
    },
  });
};

// 页面初始化
onMounted(() => {
  // 加载地区数据
  const resourceData = JSON.parse(
    sessionStorage.getItem("resourceData") || "{}"
  );
  if (resourceData && resourceData.dqlx) {
    jnwList = resourceData.dqlx;
  }

  // 获取项目列表
  getProjectData();
  // 如果有ID则加载详情
  if (rcCgqyglId.value) {
    getRcCgqyglDetail();
  }
});
</script>

<style scoped lang="less">
.tab-handle {
  margin-bottom: 10px;
}
</style>
