<script setup name="applyInfo">
import { onMounted, ref } from 'vue'
import Accessory from '@/components/accessory/index.vue'

const props = defineProps({
  detailData: {
    type: Object,
    default: () => {}
  },
  basicInfoData: {
    type: Object,
    default: () => {}
  },
  dictionaryList: Array
})
const column = [
    {
      label: '序号',
      type: 'index',
      width: 60
    },
    {
      label: '项目名称',
      prop: 'baseProjName',
      key: 'baseProjName'
    },
    {
      label: '预算年度',
      prop: 'baseProjSetYear',
      key: 'baseProjSetYear'
    }
  ],
  column1 = [
    {
      label: '项目主要内容',
      prop: 'mainContent',
      key: 'mainContent'
    },
    {
      label: '业务对象',
      prop: 'businessObject',
      key: 'businessObject'
    }
  ],
  // 立项依据
  buildBasisColumn = [
    {
      label: '序号',
      type: 'index',
      width: 60
    },
    {
      label: '依据项',
      key: 'title',
      prop: 'title'
    },
    {
      label: '依据文件名',
      slot: 'fileName'
    },
    {
      label: '文件（支持word、pdf格式）',
      slot: 'action',
      width: 300
    }
  ],
  buildBasisTableData = ref([]),
  tableListRef = ref()
onMounted(() => {
  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?.baseDevelopCode ||'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="财政编码">
      {{ detailData?.setProjCodeFinan ||'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="项目起止时间">
      <span v-if="detailData?.baseProjStartTime&&detailData?.baseProjEndTime">{{ detailData?.baseProjStartTime?.split(' ')[0] }} ~ {{ detailData?.baseProjEndTime?.split(' ')[0] }}</span>
      <span v-else>-</span>
    </el-descriptions-item>
    <el-descriptions-item label="预算年度">
      {{ detailData?.baseProjSetYear ||'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="项目总投资">
      {{ detailData?.baseProjTotalAmount ||'-' }}万元
    </el-descriptions-item>
    <el-descriptions-item label="申报年度预算">
      {{ detailData?.baseProjDeclAmount ||'-' }}万元
    </el-descriptions-item>
    <el-descriptions-item label="建设层级">
      {{ dictionaryList?.filter(i => i.type === 'BUILD_LEVEL').find(i=>i.value===detailData?.baseProjConsClass)?.label ||'-' }}
    </el-descriptions-item>
    <el-descriptions-item v-if="!(basicInfoData?.baseConstructionType?.split('；')?.includes('03')&&!basicInfoData?.baseConstructionType?.split('；')?.includes('01'))" label="贯通层级">
      {{ dictionaryList?.filter(i => i.type === 'LINK_UP_LEVEL').find(i=>i.value===detailData?.baseLowestLevel)?.label ||'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="历年项目名称" :span="2">
      <span v-if="detailData.missing">缺失</span>
      <table-list
        v-else
        :pagination="false"
        style="width: 100%"
        :column="column"
        :data="detailData.baseHistorProjs"
        :empty-temp="false"
      />
    </el-descriptions-item>
    <el-descriptions-item label="预算来源" :span="2">
      {{ detailData?.baseProjAmountOri?.split('；').map(i=>dictionaryList?.filter(j => j.type === 'BUDGET_SOURCE').find(k=>k.value===i)?.label).join('、') ||'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="预算来源说明" :span="2">
      {{ detailData?.baseBasisAmountOri ||'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="立项依据" :span="2">
      <table-list
        ref="tableListRef"
        :pagination="false"
        style="width: 100%"
        :column="buildBasisColumn"
        :data="buildBasisTableData"
      >
        <template #fileName="{scope}">
          {{ scope.row.fileList[0].originalFileName }}
        </template>
        <template #action="{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">
      {{ detailData?.baseBasisEstablish ||'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="项目概述" :span="2">
      {{ detailData?.baseProjIntro ||'-' }}
    </el-descriptions-item>
    <el-descriptions-item label="项目内容与预期成效" :span="2">
      <table-list
        :pagination="false"
        style="width: 100%"
        :column="column1"
        :data="detailData?.beseExpectedResults&&JSON.parse(detailData?.beseExpectedResults)"
        :empty-temp="false"
      />
    </el-descriptions-item>
    <el-descriptions-item label="项目申报书" :span="2">
      <template v-if="detailData?.baseProjApplyFile&&JSON.parse(detailData?.baseProjApplyFile)?.length">
        <p v-for="(file,fileIndex) in detailData?.baseProjApplyFile&&JSON.parse(detailData?.baseProjApplyFile)" :key="fileIndex" class="mb-4">
          <accessory :file-name="file.originalFileName" :file-id="file.id" />
        </p>
      </template>
      <span v-else>-</span>
    </el-descriptions-item>
    <el-descriptions-item v-if="basicInfoData?.baseProjType==='01'||basicInfoData?.baseProjType==='02'" label="可行性研究报告" :span="2">
      <template v-if="detailData?.baseResearchReportFile&&JSON.parse(detailData?.baseResearchReportFile)?.length">
        <p v-for="(file,fileIndex) in detailData?.baseResearchReportFile&&JSON.parse(detailData?.baseResearchReportFile)" :key="fileIndex" class="mb-4">
          <accessory :file-name="file.originalFileName" :file-id="file.id" />
        </p>
      </template>
      <span v-else>-</span>
    </el-descriptions-item>
    <el-descriptions-item label="其他附件" :span="2">
      <template v-if="detailData?.baseProjOtherFile&&JSON.parse(detailData?.baseProjOtherFile)?.length">
        <p v-for="(file,fileIndex) in detailData?.baseProjOtherFile&&JSON.parse(detailData?.baseProjOtherFile)" :key="fileIndex" class="mb-4">
          <accessory :file-name="file.originalFileName" :file-id="file.id" />
        </p>
      </template>
      <span v-else>-</span>
    </el-descriptions-item>
    <el-descriptions-item label="备注" :span="2">
      {{ detailData?.baseProjRemark ||'-' }}
    </el-descriptions-item>
  </el-descriptions>
</template>
