<template>
  <div class="tab-content">
    <div class="tab-content">
      <el-form ref="jcApprovalFormRef" :model="jcFormData" :rules="formRules" :validate-on-rule-change="false" :label-width="150" :disabled="isPreview">
        <el-collapse v-model="activeCollapse">
          <el-collapse-item
            title="项目投资总额（全口径）"
            name="项目投资总额（全口径）"
          >
            <el-table
              :data="jcTzzeqkjData"
              style="width: 100%"
              empty-text="暂无数据"
              default-expand-all
              row-key="xh"
              border
            >
              <el-table-column prop="xh" label="序号" />
              <el-table-column prop="zb" label="项目" />
              <el-table-column prop="dw" label="" width="70" />
              <el-table-column prop="rmbjj" label="人民币计价">
                <template #default="scope">
                  <el-input
                    v-if="!['一', '二'].includes(scope.row.xh)"
                    v-model="scope.row.rmbjj"
                    :min="0"
                    :max="99999999999.99999999"
                    controls-position="right"
                  />
                </template>
              </el-table-column>
            </el-table>
          </el-collapse-item>
          <el-collapse-item title="财务评价指标" name="财务评价指标">
            <el-table
              :data="jcCwpjzbData"
              style="width: 100%"
              empty-text="暂无数据"
              border
            >
              <el-table-column prop="name" label="指标" />
              <el-table-column prop="unit" label="" width="70" />
              <el-table-column prop="num" label="投资评估阶段批复值">
                <template #default="scope">
                  <el-input
                    v-model="scope.row.num"
                    v-if="scope.row.type === 'year'"
                  />
                  <el-input
                    v-else
                    v-model="scope.row.num"
                    :min="0"
                    :max="99999999999.99999999"
                    controls-position="right"
                  />
                </template>
              </el-table-column>
            </el-table>
          </el-collapse-item>
          <el-collapse-item title="核心边界条件" name="核心边界条件">
            <div class="tab-handle">
              <el-button type="primary" size="small" @click="addJchxbjtj"
                >新增</el-button
              >
            </div>
            <el-table
              :data="jcHxbjtjData"
              style="width: 100%"
              empty-text="暂无数据"
              border
            >
              <el-table-column type="index" width="50" />
              <el-table-column prop="type" label="业务类型" width="130">
                <template #default="scope">
                  <CommonSelector
                    v-model="scope.row.type"
                    dictName="hxbjtjywlx"
                  />
                </template>
              </el-table-column>
              <el-table-column label="单位工程造价(动态)">
                <el-table-column prop="dwgczjDtSz" label="数值" width="180">
                  <template #default="scope">
                    <el-input
                      v-model="scope.row.dwgczjDtSz"
                      :min="0"
                      :max="99999999999.99999999"
                      controls-position="right"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="dwgczjDtDw" label="单位" width="130">
                  <template #default="scope">
                    <CommonSelector
                      v-model="scope.row.dwgczjDtDw"
                      dictName="gczjdw"
                    />
                  </template>
                </el-table-column>
              </el-table-column>
              <el-table-column label="单位工程造价(静态)">
                <el-table-column prop="dwgczjJtSz" label="数值" width="180">
                  <template #default="scope">
                    <el-input
                      v-model="scope.row.dwgczjJtSz"
                      :min="0"
                      :max="99999999999.99999999"
                      controls-position="right"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="dwgczjJtDw" label="单位" width="130">
                  <template #default="scope">
                    <CommonSelector
                      v-model="scope.row.dwgczjJtDw"
                      dictName="gczjdw"
                    />
                  </template>
                </el-table-column>
              </el-table-column>
              <el-table-column label="销售/服务能力">
                <el-table-column prop="xsfwnlSz" label="数值" width="180">
                  <template #default="scope">
                    <el-input
                      v-model="scope.row.xsfwnlSz"
                      :min="0"
                      :max="99999999999.99999999"
                      controls-position="right"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="xsfwnlDw" label="单位" width="60" />
              </el-table-column>
              <el-table-column label="年均负荷率">
                <el-table-column prop="njfhlSz" label="数值" width="180">
                  <template #default="scope">
                    <el-input
                      v-model="scope.row.njfhlSz"
                      :min="0"
                      :max="99999.99"
                      controls-position="right"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="njfhlDw" label="单位" width="60" />
              </el-table-column>
              <el-table-column label="单位生产/服务总成本">
                <el-table-column prop="dwscfwzcbSz" label="数值" width="180">
                  <template #default="scope">
                    <el-input
                      v-model="scope.row.dwscfwzcbSz"
                      :min="0"
                      :max="99999999999.99999999"
                      controls-position="right"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="dwscfwzcbDw" label="单位" width="60" />
              </el-table-column>
              <el-table-column label="单位售价（含税）">
                <el-table-column prop="dwsjSz" label="数值" width="180">
                  <template #default="scope">
                    <el-input
                      v-model="scope.row.dwsjSz"
                      :min="0"
                      :max="99999999999.99999999"
                      controls-position="right"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="dwsjDw" label="单位" width="90">
                  <template #default="scope">
                    <el-input v-model="scope.row.dwsjDw" />
                  </template>
                </el-table-column>
                <el-table-column label="其中：机制电量部分">
                  <el-table-column
                    prop="dwsjJzdlJqpjdj"
                    label="加权平均电价"
                    width="150"
                  >
                    <template #default="scope">
                      <el-input v-model="scope.row.dwsjJzdlJqpjdj" />
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="dwsjJzdlDlzb"
                    label="电量占比"
                    width="120"
                  >
                    <template #default="scope">
                      <el-input v-model="scope.row.dwsjJzdlDlzb" />
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="dwsjJzdlZxqx"
                    label="执行期限"
                    width="120"
                  >
                    <template #default="scope">
                      <el-input v-model="scope.row.dwsjJzdlZxqx" />
                    </template>
                  </el-table-column>
                </el-table-column>
                <el-table-column label="其中：中长期交易电量部分">
                  <el-table-column
                    prop="dwsjZcqjyJqpjdj"
                    label="加权平均电价"
                    width="150"
                  >
                    <template #default="scope">
                      <el-input v-model="scope.row.dwsjZcqjyJqpjdj" />
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="dwsjZcqjyDlzb"
                    label="电量占比"
                    width="120"
                  >
                    <template #default="scope">
                      <el-input v-model="scope.row.dwsjZcqjyDlzb" />
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="dwsjZcqjyZxqx"
                    label="执行期限"
                    width="120"
                  >
                    <template #default="scope">
                      <el-input v-model="scope.row.dwsjZcqjyZxqx" />
                    </template>
                  </el-table-column>
                </el-table-column>
                <el-table-column label="其中：现货交易电量部分">
                  <el-table-column
                    prop="dwsjXhjyJqpjdj"
                    label="加权平均电价"
                    width="150"
                  >
                    <template #default="scope">
                      <el-input v-model="scope.row.dwsjXhjyJqpjdj" />
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="dwsjXhjyDlzb"
                    label="电量占比"
                    width="120"
                  >
                    <template #default="scope">
                      <el-input v-model="scope.row.dwsjXhjyDlzb" />
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="dwsjXhjyZxqx"
                    label="执行期限"
                    width="120"
                  >
                    <template #default="scope">
                      <el-input v-model="scope.row.dwsjXhjyZxqx" />
                    </template>
                  </el-table-column>
                </el-table-column>
                <el-table-column label="其中：绿色价值部分">
                  <el-table-column
                    prop="dwsjLsjzJqpjdj"
                    label="加权平均电价"
                    width="150"
                  >
                    <template #default="scope">
                      <el-input v-model="scope.row.dwsjLsjzJqpjdj" />
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="dwsjLsjzDlzb"
                    label="电量占比"
                    width="120"
                  >
                    <template #default="scope">
                      <el-input v-model="scope.row.dwsjLsjzDlzb" />
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="dwsjLsjzZxqx"
                    label="执行期限"
                    width="120"
                  >
                    <template #default="scope">
                      <el-input v-model="scope.row.dwsjLsjzZxqx" />
                    </template>
                  </el-table-column>
                </el-table-column>
                <el-table-column label="其中：市场运营费用（分摊费）">
                  <el-table-column
                    prop="dwsjScyyJqpjdj"
                    label="加权平均电价"
                    width="150"
                  >
                    <template #default="scope">
                      <el-input v-model="scope.row.dwsjScyyJqpjdj" />
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="dwsjScyyDlzb"
                    label="电量占比"
                    width="120"
                  >
                    <template #default="scope">
                      <el-input v-model="scope.row.dwsjScyyDlzb" />
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="dwsjScyyZxqx"
                    label="执行期限"
                    width="120"
                  >
                    <template #default="scope">
                      <el-input v-model="scope.row.dwsjScyyZxqx" />
                    </template>
                  </el-table-column>
                </el-table-column>
              </el-table-column>
              <el-table-column label="盈亏平衡点">
                <el-table-column prop="ykphdlx" label="类型" width="130">
                  <template #default="scope">
                    <CommonSelector
                      v-model="scope.row.ykphdlx"
                      dictName="ykphdlx"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="ykphdsz" label="数值" width="180">
                  <template #default="scope">
                    <el-input
                      v-model="scope.row.ykphdsz"
                      :min="0"
                      :max="99999999999.99999999"
                      controls-position="right"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="ykphddw" label="单位" width="60" />
              </el-table-column>
              <el-table-column
                prop="bcsm"
                label="核心边界条件补充说明"
                width="180"
              >
                <template #default="scope">
                  <el-input v-model="scope.row.bcsm" type="textarea" />
                </template>
              </el-table-column>
              <el-table-column label="操作" width="60" fixed="right">
                <template #default="scope">
                  <el-button
                    link
                    type="danger"
                    size="small"
                    @click="deleteJchxbjtj(scope.$index)"
                    >删除</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
          </el-collapse-item>
          <el-collapse-item title="决策主体审核情况" name="决策主体审核情况">
            <div class="tab-handle">
              <el-button type="primary" size="small" @click="addJcztshqk"
                >新增</el-button
              >
            </div>
            <el-table
              :data="jcztshqkData"
              style="width: 100%"
              empty-text="暂无数据"
              border
            >
              <el-table-column type="index" width="50" />
              <el-table-column prop="hylx" label="会议类型">
                <template #default="scope">
                  <CommonSelector v-model="scope.row.hylx" dictName="hylx" />
                </template>
              </el-table-column>
              <el-table-column prop="hymc" label="会议届次">
                <template #default="scope">
                  <el-input v-model="scope.row.hymc" />
                </template>
              </el-table-column>
              <el-table-column prop="jcsj" label="决策时间" width="260">
                <template #default="scope">
                  <el-date-picker
                    v-model="scope.row.jcsj"
                    type="date"
                    placeholder="请选择"
                  />
                </template>
              </el-table-column>
              <el-table-column prop="jcjl" label="决策结论">
                <template #default="scope">
                  <el-input v-model="scope.row.jcjl" type="textarea" />
                </template>
              </el-table-column>
              <el-table-column label="会议纪要" prop="hyjy" width="170">
                <template #default="scope">
                  <el-upload
                    v-if="!scope.row.hyjy"
                    :action="windowConfig.baseUrl + '/api/file/upload'"
                    :headers="{ Authorization: token }"
                    :show-file-list="false"
                    :on-success="
                      (res, file) => addJcztshqkFile(res, file, scope.row)
                    "
                  >
                    <el-button link type="primary">上传</el-button>
                  </el-upload>
                  <div class="upload-file-wrap" v-else>
                    <span
                      class="file-name"
                      @click="downloadFile(scope.row.hyjy)"
                      >{{ scope.row.hyjy.originalname }}</span
                    >
                    <span
                      class="delete-btn"
                      @click="deleteJcztshqkFile(scope.row, scope.$index)"
                    >
                      <el-icon><CloseBold /></el-icon>
                    </span>
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="qtsm" label="其他说明">
                <template #default="scope">
                  <el-input v-model="scope.row.qtsm" type="textarea" />
                </template>
              </el-table-column>
              <el-table-column label="操作" width="60" fixed="right">
                <template #default="scope">
                  <el-button
                    link
                    type="danger"
                    size="small"
                    @click="deleteJcztshqk(scope.$index)"
                    >删除</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
          </el-collapse-item>
          <el-collapse-item title="投资主体审核情况" name="投资主体审核情况">
            <div class="tab-handle">
              <el-button type="primary" size="small" @click="addTzztshqk"
                >新增</el-button
              >
            </div>
            <el-table
              :data="tzztshqkData"
              style="width: 100%"
              empty-text="暂无数据"
              border
            >
              <el-table-column type="index" width="50" />
              <el-table-column prop="hylx" label="会议类型">
                <template #default="scope">
                  <CommonSelector v-model="scope.row.hylx" dictName="hylx" />
                </template>
              </el-table-column>
              <el-table-column prop="hymc" label="会议届次">
                <template #default="scope">
                  <el-input v-model="scope.row.hymc" />
                </template>
              </el-table-column>
              <el-table-column prop="shsj" label="审核时间" width="260">
                <template #default="scope">
                  <el-date-picker
                    v-model="scope.row.shsj"
                    type="date"
                    placeholder="请选择"
                  />
                </template>
              </el-table-column>
              <el-table-column prop="jl" label="结论">
                <template #default="scope">
                  <el-input v-model="scope.row.jl" type="textarea" />
                </template>
              </el-table-column>
              <el-table-column label="附件" prop="fj">
                <template #default="scope">
                  <el-upload
                    v-if="!scope.row.fj"
                    :action="windowConfig.baseUrl + '/api/file/upload'"
                    :headers="{ Authorization: token }"
                    :show-file-list="false"
                    :on-success="
                      (res, file) => addTzztshqkFile(res, file, scope.row)
                    "
                  >
                    <el-button link type="primary">上传</el-button>
                  </el-upload>
                  <div class="upload-file-wrap" v-else>
                    <span
                      class="file-name"
                      @click="downloadFile(scope.row.fj)"
                      >{{ scope.row.fj.originalname }}</span
                    >
                    <span
                      class="delete-btn"
                      @click="deleteTzztshqkFile(scope.row, scope.$index)"
                    >
                      <el-icon><CloseBold /></el-icon>
                    </span>
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="qtsm" label="其他说明">
                <template #default="scope">
                  <el-input v-model="scope.row.qtsm" type="textarea" />
                </template>
              </el-table-column>
              <el-table-column label="操作" width="60" fixed="right">
                <template #default="scope">
                  <el-button
                    link
                    type="danger"
                    size="small"
                    @click="deleteTzztshqk(scope.$index)"
                    >删除</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
            <el-row :gutter="20">
              <el-col :span="24">
                <el-form-item label="其他会议审议情况" prop="jcqthysyqk">
                  <el-input
                    v-model="jcFormData.jcqthysyqk"
                    type="textarea"
                    :autosize="{ minRows: 2, maxRows: 5 }"
                  />
                </el-form-item>
              </el-col>
            </el-row>
          </el-collapse-item>
          <el-collapse-item title="项目批复信息" name="项目批复信息">
            <el-row :gutter="20">
              <el-col :span="6">
                <el-form-item label="最终审批意见" label-width="160" prop="jczzpfyj">
                  <CommonSelector
                    v-model="jcFormData.jczzpfyj"
                    dictName="spyj"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="项目批复时间" prop="jcxmpfsj">
                  <el-date-picker
                    v-model="jcFormData.jcxmpfsj"
                    type="date"
                    placeholder="请选择"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="项目批复文号" prop="jcxmpfwh">
                  <el-input v-model="jcFormData.jcxmpfwh" />
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="审核处室" label-width="160" prop="jcpfshcs">
                  <el-input v-model="jcFormData.jcpfshcs" />
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="未通过主要原因与要求" label-width="160" prop="jcwtgzyyyyyq">
                  <el-input
                    v-model="jcFormData.jcwtgzyyyyyq"
                    type="textarea"
                    :autosize="{ minRows: 2, maxRows: 5 }"
                  />
                </el-form-item>
              </el-col>

              <el-col :span="24">
                <el-form-item label="批复文件" :label-width="130">
                  <FileUploader v-model="jcFormData.jcpfwj" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-collapse-item>
          <el-collapse-item title="审批意见" name="审批意见">
            <div class="tab-handle">
              <el-button type="primary" size="small" @click="addJcspyj"
                >新增</el-button
              >
            </div>
            <el-table
              :data="jcspyjData"
              style="width: 100%"
              empty-text="暂无数据"
              border
            >
              <el-table-column type="index" width="50" />
              <el-table-column prop="lx" label="类型">
                <template #default="scope">
                  <CommonSelector v-model="scope.row.lx" dictName="jcspyjlx" />
                </template>
              </el-table-column>
              <el-table-column prop="pfyj" label="批复意见">
                <template #default="scope">
                  <el-input v-model="scope.row.pfyj" type="textarea" />
                </template>
              </el-table-column>
              <el-table-column prop="pfyjsj" label="批复意见时间" width="260">
                <template #default="scope">
                  <el-date-picker
                    v-model="scope.row.pfyjsj"
                    type="date"
                    placeholder="请选择"
                  />
                </template>
              </el-table-column>
              <!-- <el-table-column label="执行回复" prop="zxhf">
                <template #default="scope">
                  <el-input v-model="scope.row.zxhf" type="textarea" />
                </template>
              </el-table-column>
              <el-table-column label="执行回复时间" prop="zxhfsj" width="260">
                <template #default="scope">
                  <el-date-picker
                    v-model="scope.row.zxhfsj"
                    type="date"
                    placeholder="请选择"
                  />
                </template>
              </el-table-column>
              <el-table-column label="执行回复附件" prop="zxhffj">
                <template #default="scope">
                  <el-upload
                    v-if="!scope.row.zxhffj"
                    :action="windowConfig.baseUrl + '/api/file/upload'"
                    :headers="{ Authorization: token }"
                    :show-file-list="false"
                    :on-success="
                      (res, file) => addJcspyjFile(res, file, scope.row)
                    "
                  >
                    <el-button link type="primary">上传</el-button>
                  </el-upload>
                  <div class="upload-file-wrap" v-else>
                    <span
                      class="file-name"
                      @click="downloadFile(scope.row.zxhffj)"
                      >{{ scope.row.zxhffj.originalname }}</span
                    >
                    <span
                      class="delete-btn"
                      @click="deleteRowFile(scope.row, scope.$index)"
                    >
                      <el-icon><CloseBold /></el-icon>
                    </span>
                  </div>
                </template>
              </el-table-column> -->
              <el-table-column label="操作" width="60" fixed="right">
                <template #default="scope">
                  <el-button
                    link
                    type="danger"
                    size="small"
                    @click="deleteJcspyj(scope.$index)"
                    >删除</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
          </el-collapse-item>
          <el-collapse-item title="其他" name="其他">
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label-width="160" label="投资主体首次申报时间" prop="tzztscsbsj">
                  <el-date-picker
                    v-model="jcFormData.tzztscsbsj"
                    type="date"
                    placeholder="请选择"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label-width="160" label="审核人" prop="shr">
                  <el-input v-model="jcFormData.shr" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label-width="160" label="会签完成时间" prop="hqwcsj">
                  <el-date-picker
                    v-model="jcFormData.hqwcsj"
                    type="date"
                    placeholder="请选择"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label-width="160" label="首次发函时间" prop="scfhsj">
                  <el-date-picker
                    v-model="jcFormData.scfhsj"
                    type="date"
                    placeholder="请选择"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label-width="160" label="补充资料时间" prop="bczlsj">
                  <el-date-picker
                    v-model="jcFormData.bczlsj"
                    type="date"
                    placeholder="请选择"
                  />
                </el-form-item>
              </el-col>
            </el-row>
          </el-collapse-item>
        </el-collapse>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import { inject, ref } from "vue";
import CommonSelector from "@/components/CommonSelector.vue";
import FileUploader from "@/components/FileUploader/index.vue";

const jcApprovalFormRef = ref();

const requiredInput = (msg) => ({
  required: true,
  message: `请输入${msg}`,
  trigger: "blur",
});
const requiredSelect = (msg) => ({
  required: true,
  message: `请选择${msg}`,
  trigger: [],
});

const formRules = {
  jcqthysyqk: [requiredInput("其他会议审议情况")],
  jczzpfyj: [requiredSelect("最终审批意见")],
  jcxmpfsj: [requiredSelect("项目批复时间")],
  jcxmpfwh: [requiredInput("项目批复文号")],
  jcpfshcs: [requiredInput("审核处室")],
  jcwtgzyyyyyq: [requiredInput("未通过主要原因与要求")],
  tzztscsbsj: [requiredSelect("投资主体首次申报时间")],
  shr: [requiredInput("审核人")],
  hqwcsj: [requiredSelect("会签完成时间")],
  scfhsj: [requiredSelect("首次发函时间")],
  bczlsj: [requiredSelect("补充资料时间")],
};

const validate = () => {
  return jcApprovalFormRef.value?.validate();
};

defineExpose({ validate });

const {
  jcFormData,
  isPreview,
  activeCollapse,
  jcTzzeqkjData,
  jcCwpjzbData,
  jcHxbjtjData,
  jcztshqkData,
  tzztshqkData,
  jcspyjData,
  addJchxbjtj,
  deleteJchxbjtj,
  addJcztshqk,
  deleteJcztshqk,
  addJcztshqkFile,
  deleteJcztshqkFile,
  addTzztshqk,
  deleteTzztshqk,
  addTzztshqkFile,
  deleteTzztshqkFile,
  addJcspyj,
  deleteJcspyj,
  addJcspyjFile,
  deleteRowFile,
  downloadFile,
  windowConfig,
  token,
} = inject("jcShared");
</script>

<style scoped>
.tab-content :deep(.el-form-item__error) {
  display: none;
}
</style>
