<script name="basicInfo" setup>
import store from '@/store'
import { reactive, ref, watch } from 'vue'
import Accessory from '@/components/accessory/index.vue'
import { templateTypeList } from '@/http/apis/performanceEvaluation/indicatorTemplate'

const props = defineProps({
  detailData: Object,
  isDownLoadFile: {
    type: Boolean,
    default: true
  },
  dictionaryList: {
    type: Array,
    default: () => []
  }
})
const { statusOptions, cloudTypeOptions, fourSystem, businessTerritory, projectTypeOptions } = store.dictStore.globalDicts || {},
  column = reactive([
    {
      label: '序号',
      type: 'index',
      width: '80'
    },
    {
      label: '依据项',
      slot: 'title'
    },
    {
      label: '依据文件名',
      slot: 'fileName'
    },
    {
      label: '附件',
      slot: 'file'
    }
  ]),
  column1 = reactive([
    {
      label: '序号',
      type: 'index',
      width: 60
    },
    {
      label: '项目名称',
      prop: 'baseProjName',
      key: 'baseProjName'
    },
    {
      label: '预算年度',
      prop: 'baseProjSetYear',
      key: 'baseProjSetYear'
    }
  ]),
  column2 = [
    {
      label: '项目主要内容',
      prop: 'mainContent',
      key: 'mainContent'
    },
    {
      label: '业务对象',
      prop: 'businessObject',
      key: 'businessObject'
    }
  ],
  buildBasisTableData = ref([]),
  tableListRef = ref(),
  templateTypeListData = ref(),
  getTemplateTypeList = async () => {
    const res = await templateTypeList()
    templateTypeListData.value = res.data
  }
watch(() => props.detailData, val => {
  if (val) {
    getTemplateTypeList()
    buildBasisTableData.value = props.detailData?.baseProjBasis?.split('；')?.map((i, index) => {
      const file = `[${props.detailData?.baseProjBasisFile.replace(/}]；/g, '}],')}]`
      return {
        title: props.dictionaryList?.filter(k => k.type === 'PROJECT_BASIS')?.find(j => j.value === i)?.label,
        fileList: props.detailData?.baseProjBasisFile ? JSON.parse(file)[index] : [],
        value: i
      }
    })
  }
})
</script>

<template>
  <el-descriptions :column="2" border>
    <el-descriptions-item label="是否涉密">
      {{ detailData.baseProjIsConfidentiality==='02'?'是':'否' }}
    </el-descriptions-item>
    <el-descriptions-item label="项目ID">
      {{ detailData.projectCode ||'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="项目名称">
      {{ detailData.projectName ||'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="项目类型">
      {{ detailData?.projectType&&projectTypeOptions[detailData?.projectType] }}
    </el-descriptions-item>
    <el-descriptions-item label="内容类别">
      {{ detailData?.baseConstructionType?.split('；').map(i=>dictionaryList?.filter(j => j.type === 'CONTENT_TYPE').find(k=>k.value===i)?.label).join('、') ||'-' }}
    </el-descriptions-item>
    <template v-if="detailData?.baseProjIsConfidentiality !== '02'">
      <el-descriptions-item label="是否首次新建">
        {{ detailData.isFirst?'是':'否' }}
      </el-descriptions-item>
      <el-descriptions-item label="是否一地创新全省共享项目">
        {{ detailData.isInnovateWholeProvinceShare?'是':'否' }}
      </el-descriptions-item>
    </template>
    <el-descriptions-item label="行政区划编码">
      {{ detailData.areaCode ||'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="行政区划名称">
      {{ detailData.area ||'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="项目负责人">
      {{ detailData.responsibleMan||'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="项目负责人手机号码">
      {{ detailData.responsibleManMobile||'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="项目联系人">
      {{ detailData.contactName||'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="项目联系人手机号码">
      {{ detailData.contactPhone||'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="上级业务主管单位">
      {{ detailData.higherSuperOrg||'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="上级业务主管单位浙政钉ID">
      {{ detailData.higherSuperOrgCode||'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="本级主管部门单位">
      {{ detailData.superOrg||'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="本级主管单位浙政钉ID">
      {{ detailData.superOrgCode||'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="本级主管单位统一社会信用代码">
      {{ detailData.superOrgCreditCode||'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="建设单位：">
      {{ detailData.buildOrgName||'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="建设单位浙政钉ID">
      {{ detailData.buildOrgCode||'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="建设单位统一信用代码">
      {{ detailData.orgCreditCode||'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="主管单位">
      {{ detailData.superOrg||'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="上级主管单位类型">
      {{ detailData.baseProvManDeprtType===1?'省级': detailData.baseProvManDeprtType===2?'非省级':'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="上级条线主管单位">
      {{ detailData.higherSuperOrg||'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="项目状态">
      {{ statusOptions[detailData.status]?.name||'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="预算年度">
      {{ detailData.projectYear ||'-' }}
    </el-descriptions-item>
    <template v-if="detailData?.baseProjIsConfidentiality !== '02'">
      <el-descriptions-item label="建设起止年限">
        {{ detailData.beginTime }}~{{ detailData.endTime }}
      </el-descriptions-item>
      <el-descriptions-item label="建设层级">
        {{ dictionaryList?.filter(i => i.type === 'BUILD_LEVEL').find(i=>i.value===detailData?.buildLevel)?.label ||'-' }}
      </el-descriptions-item>
      <el-descriptions-item label="贯通层级">
        {{ dictionaryList?.filter(i => i.type === 'BUILD_LEVEL').find(i=>i.value===detailData?.lowestLevel)?.label ||'-' }}
      </el-descriptions-item>
      <el-descriptions-item label="系统定位" span="2">
        <span style="word-break:break-all">{{ detailData.systemPosition||'-' }}</span>
      </el-descriptions-item>
      <el-descriptions-item label="项目简介" span="2">
        <span style="word-break:break-all">{{ detailData.projectIntroduction||'-' }}</span>
      </el-descriptions-item>
      <el-descriptions-item v-if="detailData.buildBasis&&JSON.parse(detailData.buildBasis)?.length" label="立项依据" span="2">
        <table-list
          :column="column"
          :data="detailData.buildBasis&&JSON.parse(detailData.buildBasis)"
          :pagination="false"
          :empty-temp="false"
          style="width: 98%;"
        >
          <template #title="{scope}">{{ scope.row.title }}</template>
          <template #fileName="{scope}">
            {{ scope.row.fileName }}
          </template>
          <template #file="{scope}">
            <p v-for="(item,fileIndex) in scope.row.fileList" :key="fileIndex" class="mb-4">
              <accessory :file-name="item.originalFileName" :file-id="item.id" :is-down-load="isDownLoadFile" />
            </p>
          </template>
        </table-list>
      </el-descriptions-item>
      <el-descriptions-item v-else label="立项依据" :span="2">
        <table-list
          ref="tableListRef"
          :pagination="false"
          style="width: 100%"
          :column="column"
          :data="buildBasisTableData"
        >
          <template #title="{scope}">{{ scope.row.title }}</template>
          <template #fileName="{scope}">
            {{ scope.row.fileList[0].originalFileName }}
          </template>
          <template #file="{scope}">
            <p v-for="(file,fileIndex) in scope.row.fileList" :key="fileIndex" class="mb-4">
              <accessory :file-name="file.originalFileName" :file-id="file.id" />
            </p>
          </template>
        </table-list>
      </el-descriptions-item>
      <el-descriptions-item label="立项依据说明" span="2">
        <span style="word-break:break-all">{{ detailData.baseBasisEstablish||'-' }}</span>
      </el-descriptions-item>
      <el-descriptions-item label="发改编码">
        {{ detailData.developCode ||'-' }}
      </el-descriptions-item>
      <el-descriptions-item label="财政编码">
        {{ detailData.financialCode ||'-' }}
      </el-descriptions-item>
      <el-descriptions-item label="是否数字化改革项目">
        {{ detailData.isDigitalReform?'是':'否' }}
      </el-descriptions-item>
      <el-descriptions-item label="综合业务领域">
        {{ detailData.bizDomain?.split(',').map(i=>businessTerritory[i]).join('，')||'-' }}
      </el-descriptions-item>
      <el-descriptions-item label="是否上云">
        {{ detailData.isCloud?'是':'否' }}
      </el-descriptions-item>
      <el-descriptions-item v-if="detailData.isCloud" label="云类型">
        {{ detailData.cloudType&&detailData.cloudType.split(',').map(i=>cloudTypeOptions[i]).join('、')|| '-' }}
      </el-descriptions-item>
      <el-descriptions-item
        label="四大体系"
      >{{ fourSystem[detailData.fourSystems] }}</el-descriptions-item>
      <el-descriptions-item label="绩效评价类型">
        {{ templateTypeListData?.find(i=>i.id===detailData.templateType)?.name||"-" }}
      </el-descriptions-item>
      <el-descriptions-item
        label="是否临时增补项目"
        :span="2"
      >{{ detailData.isTemporaryAugment?'是':'否' }}</el-descriptions-item>
      <el-descriptions-item label="历年项目名称" :span="2">
        <table-list
          :column="column1"
          :data="detailData?.baseHistorProjs|| []"
          :pagination="false"
          :empty-temp="false"
          style="width: 98%;"
        />
      </el-descriptions-item>
      <el-descriptions-item label="项目内容与预期成效" :span="2">
        <table-list
          ref="tableList2"
          :pagination="false"
          style="width: 100%"
          :column="column2"
          :data="detailData?.beseExpectedResults&&JSON.parse(detailData?.beseExpectedResults)"
          :empty-temp="false"
        />
      </el-descriptions-item>
      <el-descriptions-item v-if="detailData?.projectApplicationForm&&JSON.parse(detailData.projectApplicationForm)?.length" label="项目申报书">
        <p v-for="(item,index) in detailData.projectApplicationForm&&JSON.parse(detailData.projectApplicationForm)" :key="index" class="mb-4">
          <accessory :file-name="item.originalFileName" :file-id="item.id" :is-down-load="isDownLoadFile" />
        </p>
      </el-descriptions-item>
      <el-descriptions-item
        v-if="detailData.pretrialFileId"
        label="预审申请单"
        span="2"
      >
        <accessory :file-name="detailData.pretrialFileName" :file-id="detailData.pretrialFileId" :is-down-load="isDownLoadFile" />
      </el-descriptions-item>
      <el-descriptions-item
        v-if="false"
        label="上级条线主管单位审核意见"
        span="2"
      >
        <p v-for="(item,index) in detailData.higherLineSuperOrgReviewComments&&JSON.parse(detailData.higherLineSuperOrgReviewComments)" :key="index" class="mb-4">
          <accessory :file-name="item.originalFileName" :file-id="item.id" :is-down-load="isDownLoadFile" />
        </p>
      </el-descriptions-item>
      <el-descriptions-item
        v-if="detailData.constructFileId"
        label="建设方案审查意见文件"
        span="2"
      >
        <accessory :file-name="detailData.constructFileName" :file-id="detailData.constructFileId" :is-down-load="isDownLoadFile" />
      </el-descriptions-item>
    </template>
  </el-descriptions>
</template>
