<template>
  <div class="tab-content">
    <div class="tab-content">
      <el-form
        :model="formData"
        :label-width="150"
        :disabled="isPreview || Number(formData.projectLzType) >= 5"
      >
        <el-collapse v-model="activeCollapse">
          <el-collapse-item
            title="项目投资总额（全口径）"
            name="项目投资总额（全口径）"
          >
            <el-table
              :data="tzzeqkjData"
              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-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="cwpjzbData"
              style="width: 100%"
              empty-text="暂无数据"
              border
            >
              <el-table-column prop="name" label="指标" />
              <el-table-column prop="unit" label="" width="70" />
              <el-table-column prop="tzpgjdpfz" label="投资评估阶段批复值">
                <template #default="scope">
                  <el-input
                    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="addHxbjtj"
                >新增</el-button
              >
            </div>
            <el-table
              :data="hxbjtjData"
              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="dwgczjSz" label="数值" width="180">
                  <template #default="scope">
                    <el-input
                      v-model="scope.row.dwgczjSz"
                      :min="0"
                      :max="99999999999.99999999"
                      controls-position="right"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="dwgczjDw" label="单位" width="130">
                  <template #default="scope">
                    <CommonSelector
                      v-model="scope.row.dwgczjDw"
                      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>
              <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="deleteHxbjtj(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="24">
                <el-form-item label="其他会议审议情况">
                  <el-input v-model="formData.qthysyqk" type="textarea" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="立项最终审批意见">
                  <CommonSelector v-model="formData.lxzzpfyj" dictName="spyj" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="项目立项批复时间">
                  <el-date-picker
                    v-model="formData.lxxmpfsj"
                    type="date"
                    placeholder="请选择"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="立项项目批复文号">
                  <el-input v-model="formData.lxxmpfwh" />
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="未通过主要原因与要求">
                  <el-input v-model="formData.wtgzyyyyyq" type="textarea" />
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="立项批复文件" :label-width="100">
                  <FileUploader v-model="lxpfwjData" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-collapse-item>
          <el-collapse-item title="审批意见" name="审批意见">
            <FormDynamicTable
              :modelValue="spyjTableData"
              @update:modelValue="updateSpyjTable"
              :columns="spyjColumns"
            />
            <el-form-item label="相关上会材料" :label-width="100">
              <FileUploader v-model="shclData" />
            </el-form-item>
          </el-collapse-item>
        </el-collapse>
      </el-form>
    </div>
  </div>
</template>

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

const {
  formData,
  isPreview,
  formDisabled,
  activeCollapse,
  tzzeqkjData,
  cwpjzbData,
  hxbjtjData,
  lxpfwjData,
  lxpfSelectIds,
  spyjTableData,
  shclData,
  shclSelectIds,
  downloadFile,
  ElMessageBox,
  addHxbjtj,
  deleteHxbjtj,
  addLxpfFile,
  deleteLxpf,
  lxpfSelectionChange,
  multiDeleteLxpf,
  addShclFile,
  deleteShcl,
  shclSelectionChange,
  multiDeleteShcl,
  windowConfig,
  token,
} = inject("lxShared");

// 审批意见表格列配置
const spyjColumns = [
  {
    prop: "lx",
    label: "类型",
    type: "select",
    optionKey: "yjlx",
    minWidth: 130,
  },
  { prop: "pfyj", label: "批复意见", type: "textarea" },
  { prop: "pfyjsj", label: "批复意见时间", type: "date" },
];

// 更新审批意见表格数据（适配 reactive 数组与 FormDynamicTable 的 v-model 机制）
const updateSpyjTable = (val) => {
  spyjTableData.splice(0, spyjTableData.length, ...val);
};
</script>
