<template>
<div style="padding: 0 30px">
  <baseTitle title="项目基本信息"></baseTitle>
  <fvForm :schema="schema" @getInstance="(e)=>baseForm = e" label-position="left" label-width="left" style="margin-left: 15px"></fvForm>
  <baseTitle title="阶段变更详情" style="margin-top: -10px"></baseTitle>
  <div style="color: #606266;font-size: 14px;height:32px;line-height: 32px"><span style="display:inline-block;text-align: right;margin-right: 14px;margin-left: 15px">抄送人</span>{{copyName?copyName:'--'}}</div>
  <div style="color: #606266;font-size: 14px;display: flex;height:40px;line-height: 32px">
    <span style="display:inline-block;text-align: right;margin-right: 14px;margin-left: 15px">变更状态</span>
<!--    {{changeState=='1'?'开发阶段':'研究阶段'}}-->
    <tag dict-type="fee_stage" :value="changeState"/>
  </div>
  <ApprovalDetail :formData="summaryData.formData" :data="summaryData" type="phase"
                  :processViewer="summaryProcessViewer" :loading="loading" :fileListShow="fileListShow"  v-model:value="auditOpinion"/>
  <opinion v-if="summaryData.taskId" :formData="summaryData.formData" :taskId="summaryData.taskId"  :taskUserOptionList="summaryData.taskUserOptionList"  v-model:value="auditOpinion"></opinion>

</div>
</template>

<script setup lang="jsx">
import {ElNotification} from "element-plus";
import {useProcessStore} from '@/stores/processStore.js';
import {getPhaseDetail} from "@/api/project-manage";
import {computed, ref} from "vue";
import {getBaseInfoApi} from "@/components/steps/api";
import {useCacheStore} from '@/stores/cache.js'

import {toThousands} from '@/utils/changePrice.js'
const cacheStore = useCacheStore()
const route = useRoute()
const summaryData = ref({})
const summaryProcessViewer = ref(true)
const processStore = useProcessStore()
const loading = ref(false)
const auditOpinion = ref('')
const copyName = ref('')
const changeState = ref('')
const fileListShow = ref('READ')
const baseFormData = ref([])
const schema = computed(() => {
  return [
    {
      label: '承办单位',
      prop: 'affiliatedCompany',
      colProps: {
        span: 6
      }
    },
    {
      label: '项目名称',
      prop: 'projectName',
      colProps: {
        span: 6
      }
    },

    {
      label: '开始时间',
      prop: 'startTime',
      colProps: {
        span: 6
      }
    },
    {
      label: '结束时间',
      prop: 'endTime',
      colProps: {
        span: 6
      }
    },
    {
      label: '项目类型',
      prop: 'projectType',
      colProps: {
        span: 6
      },
      component: () => (
          <div>
            {
              baseFormData.value?.projectType ?
                  <span>{filterDict(cacheStore.getDict('project_type'), baseFormData.value?.projectType)}</span>
                  : <span>{'--'}</span>
            }
          </div>
      )
    },
    {
      label: '研发主体',
      prop: 'rdSubject',
      colProps: {
        span: 6
      },
      component: () => (
          <div>
            {
              baseFormData.value?.rdSubject ?
                  <span>{filterDict(cacheStore.getDict('rd_subject'), baseFormData.value?.rdSubject)}</span>
                  : <span>{'--'}</span>
            }
          </div>
      )
    },
    {
      label: '出资类型',
      prop: 'investmentType',
      colProps: {
        span: 6
      },
      component: () => (
          <div>
            {
              baseFormData.value?.investmentType ?
                  <span>{filterDict(cacheStore.getDict('invest_type'), baseFormData.value?.investmentType)}</span>
                  : <span>{'--'}</span>
            }
          </div>
      )
    },
    {
      label: '所属业务板块',
      prop: 'businessSegment',
      colProps: {
        span: 6
      },
      component: () => (
          <div>
            {
              baseFormData.value?.businessSegment ?
                  <span>{filterDict(cacheStore.getDict('business_segment'), baseFormData.value?.businessSegment)}</span>
                  : <span>{'--'}</span>
            }
          </div>
      )
    },
    {
      label: '标准制定',
      prop: 'technicalStandard',
      colProps: {
        span: 6
      },
      component: () => (
          <div>
            {
              baseFormData.value?.technicalStandard ?
                  <span>{filterDict(cacheStore.getDict('technical_standard'), baseFormData.value?.technicalStandard)}</span>
                  : <span>{'--'}</span>
            }
          </div>
      )
    },
    {
      label: '项目影响',
      prop: 'projectImpact',
      colProps: {
        span: 6
      },
      component: () => (
          <div>
            {
              baseFormData.value?.projectImpact ?
                  <span>{filterDict(cacheStore.getDict('project_impact'), baseFormData.value?.projectImpact)}</span>
                  : <span>{'--'}</span>
            }
          </div>
      )
    },
    {
      label: '经费预算(元)',
      prop: 'economicEstimate',
      colProps: {
        span: 6
      },
      component: () => (
          <div>
            {
              baseFormData.value?.economicEstimate ?
                  <span>{ toThousands(baseFormData.value?.economicEstimate )}</span>
                  : <span>{'--'}</span>
            }
          </div>
      )
    },
    {
      label: '产学研联合',
      prop: 'industryUniversityResearch',
      colProps: {
        span: 6
      },
      component: () => (
          <div>
            {
              baseFormData.value?.industryUniversityResearch ?
                  <span>{filterDict(cacheStore.getDict('industry_university'), baseFormData.value?.industryUniversityResearch)}</span>
                  : <span>{'--'}</span>
            }
          </div>
      )
    },
    {
      label: '开展政府申报',
      prop: 'governmentDeclaration',
      colProps: {
        span: 6
      },
      component: () => (
          <div>
            {
              baseFormData.value?.governmentDeclaration ?
                  <span>{filterDict(cacheStore.getDict('government_declaration'), baseFormData.value?.governmentDeclaration)}</span>
                  : <span>{'--'}</span>
            }
          </div>
      )
    },
    {
      label: '所属专项资金项目',
      prop: 'specialFund',
      colProps: {
        span: 6
      }
    },
    {
      label: '申请总部专项资金(元)',
      prop: 'specialFundAmount',
      colProps: {
        span: 6
      },
      component: () => (
          <div>
            {
              baseFormData.value?.specialFundAmount ?
                  <span>{toThousands(baseFormData.value?.specialFundAmount)}</span>
                  : <span>{'--'}</span>
            }
          </div>
      )
    },
    {
      label: '是否在预算内',
      prop: 'isWithinBudget',
      colProps: {
        span: 6
      },
      component: () => (
          <div>
            {
              baseFormData.value?.isWithinBudget!=null ? baseFormData.value?.isWithinBudget?
                  <span>{'预算内'}</span>
                  : <span>{'预算外'}</span>:'--'
            }
          </div>
      )
    },
    {
      label: '部门分管领导',
      prop: 'optionalChargeLeadership',
      colProps: {
        span: 6
      }
    }
  ]
})

const baseForm = ref()
//匹配字典值,返回对应值的字典标签
const filterDict = (data, value) => {
  if (data === undefined || value === undefined) return;
  let label = ''
  let result = []
  if (value instanceof Array) {
    value.forEach(item1 => {
      data.find(item => {
        if (item.value == item1) {
          result.push(item.label)
        }
      })
    })
    label = result.map(item => item).join('，')
  } else {
    if (data instanceof Array) {
      data.find(item => {
        if (item.value == value) {
          label = item.label
        }
      })
    }
  }
  return label
}

const getBaseInfo = async () => {
  try {
    const {code, data} = await getBaseInfoApi(route.query.projectId)
    baseForm.value.setValues(data)
    baseFormData.value = data
  } catch {
  }
}

getBaseInfo()
const getInfo = async () => {
  fileListShow.value = 'READ'
  const projectId = route.query.projectId
  summaryProcessViewer.value = false
  loading.value = true
  const {code, data, msg} = await getPhaseDetail(projectId)
  if (code === 1000) {
    summaryData.value = data;
    copyName.value= data.formData.userInfoList?.map(item=>item.name).join('，')
    changeState.value= data.formData.changeState
    loading.value = false
    processStore.setDesign(data)
    processStore.runningList.value = data.runningList;
    processStore.endList.value = data.endList;
    processStore.noTakeList.value = data.noTakeList;
    processStore.refuseList.value = data.refuseList;
    processStore.passList.value = data.passList;
    nextTick(() => {
      summaryProcessViewer.value = true
      if (data.formPermMap["fileList"]) {
        fileListShow.value = data.formPermMap["fileList"].perm
      }
    })
  } else {
    ElNotification({
      title: '提示',
      message: msg,
      type: 'error'
    })
    if (msg === '查询结果为空') {
      summaryData.value = []
    }
    loading.value = false
  }
}
getInfo()
</script>

<style scoped>

</style>
