<script name="projectInfo" setup>
import { onMounted, ref, watch, computed } from 'vue'
import BasicInfo from './basicInfo.vue'
import FundsInfo from './fundsInfo.vue'
import InvestmentInfo from './investmentInfo.vue'
import EngineeringInfo from './engineeringInfo.vue'
import SafeInfo from './safeInfo.vue'
import BusinessInfo from './businessInfo.vue'
import YearPayPlanInfo from './yearPayPlanInfo.vue'
// import ConstructionPlan from './constructionPlan.vue'
import FilesInfo from './filesInfo.vue'
import RemarkInfo from './remarkInfo.vue'
import Applications from './applications.vue'
import CustomModule from './customModule.vue'
import ProvincialInfo from '@/pages/projectStoreManage/projectStore/projectDetail/components/provincialInfo.vue'
const props = defineProps({
    detailData: Object,
    isDownLoadFile: {
      type: Boolean,
      default: true
    },
    dictionaryList: {
      type: Array,
      default: () => []
    }
  }),
  activeName = ref('基本信息'),
  tabList = ref([
    '基本信息',
    '资金申报情况',
    '投资分配情况',
    '年度支付计划'
    // '核心业务',
    // '安全投入',
    // '工程形象进度',
    // '附件',
    //   '建设方案',
    // '备注'
  ]),
  customModuletabList = computed(() => {
    const customModule = []
    for (let i = 0; i < tabList.value.length; i++) {
      if (tabList.value[i] !== '基本信息' && tabList.value[i] !== '资金申报情况' && tabList.value[i] !== '投资分配情况' && tabList.value[i] !== '年度支付计划' && tabList.value[i] !== '核心业务' && tabList.value[i] !== '安全投入' && tabList.value[i] !== '工程形象进度' && tabList.value[i] !== '附件' && tabList.value[i] !== '建设方案' && tabList.value[i] !== '备注') {
        customModule.push(tabList.value[i])
      }
    }
    return customModule
  }),
  getTabs = () => {
    if (props.detailData?.baseProjIsConfidentiality === '02') {
      tabList.value = ['基本信息']
    } else {
      props.detailData?.declareAmount >= 1000 && tabList.value.push('重大项目省级联审信息')
      props.detailData?.isOpenCoreBusiness && tabList.value.push('核心业务')
      props.detailData?.isOpenSafetyInput && tabList.value.push('安全投入')
      props.detailData?.isEngineeringSpeed && tabList.value.push('工程形象进度')
      tabList.value.push('附件')
      props.detailData?.isRemarks && tabList.value.push('备注')
      props.detailData?.projectApplications?.length && tabList.value.push('应用信息')
      if (props.detailData?.safetyInputModular && JSON.parse(props.detailData.safetyInputModular)?.length) {
        for (let i = 0; i < JSON.parse(props.detailData.safetyInputModular).length; i++) {
          tabList.value.push(JSON.parse(props.detailData.safetyInputModular)[i].moduleName)
        }
      }
      tabList.value = [...new Set(tabList.value)]
    }
  }
watch(
  () => props.detailData,
  async val => {
    if (val?.id) {
      getTabs()
    }
  },
  { deep: true }
)
onMounted(async () => {
  console.log('customModuletabList', customModuletabList)
})
defineExpose({ getTabs })
</script>

<template>
  <el-card shadow="never" class="tab-card">
    <template #header>
      <el-tabs v-model="activeName">
        <el-tab-pane
          v-for="(item,index) in tabList"
          :key="index"
          :label="item"
          :name="item"
        />
      </el-tabs>
    </template>
    <basic-info
      v-if="activeName==='基本信息'"
      :detail-data="detailData"
      :is-down-load-file="isDownLoadFile"
      :dictionary-list="dictionaryList"
    />
    <funds-info v-if="activeName==='资金申报情况'" :detail-data="detailData" />
    <investment-info v-if="activeName==='投资分配情况'" :detail-data="detailData" />
    <provincial-info v-if="activeName==='重大项目省级联审信息'" :detail-data="detailData" />
    <year-pay-plan-info v-if="activeName==='年度支付计划'" :detail-data="detailData" />
    <business-info v-if="activeName==='核心业务'" :detail-data="detailData" />
    <safe-info v-if="activeName==='安全投入'" :detail-data="detailData" />
    <engineering-info v-if="activeName==='工程形象进度'" :detail-data="detailData" />
    <files-info v-if="activeName==='附件'" :detail-data="detailData" :is-down-load-file="isDownLoadFile" />
    <!--    <construction-plan v-if="activeName==='建设方案'" :detail-data="detailData" :is-down-load-file="isDownLoadFile" />-->
    <remark-info v-if="activeName==='备注'" :detail-data="detailData" />
    <applications v-if="activeName==='应用信息'" :detail-data="detailData" :is-down-load-file="isDownLoadFile" />
    <div v-for="(item , moduleNum) in detailData.safetyInputModular&&JSON.parse(detailData.safetyInputModular)" :key="moduleNum">
      <custom-module
        v-if="activeName=== item.moduleName"
        :data="item"
        :module-num="moduleNum"
        :is-down-load-file="isDownLoadFile"
      />
    </div>

  </el-card>
</template>
