<template>
  <steps :active="route.query.id==='-1'?0:1" @setDetail="setDetail" @stepChange="stepChange"
         :reportType="route.query.id==='-1'?'direct':''" :taskId="summaryData.taskId" >
    <template #content>
      <collection-detail v-show="showActive == '00'" :formData="summaryData.formData" :data="summaryData"
                         :processViewer="summaryProcessViewer" :loading="loading" :fileListShow="fileListShow"
                         v-model:value="auditOpinion"/>
      <summary-detail v-show="showActive == '10'" :formData="summaryData.formData" :data="summaryData"
                      :processViewer="summaryProcessViewer" :loading="loading" :fileListShow="fileListShow"
                      v-model:value="auditOpinion"/>
      <ApprovalDetail v-show="showActive == '20'" :formData="summaryData.formData" :data="summaryData"
                      :processViewer="summaryProcessViewer" :loading="loading" :fileListShow="fileListShow"
                      v-model:value="auditOpinion"/>
      <ApprovalDetail type="execute" v-show="showActive == '40'" :formData="summaryData.formData" :data="summaryData"
                      :processViewer="summaryProcessViewer" :loading="loading" :fileListShow="fileListShow"
                      v-model:value="auditOpinion"/>
      <ApprovalDetail type="archivist" v-show="showActive == '50'" :formData="summaryData.formData" :data="summaryData"
                      :processViewer="summaryProcessViewer" :loading="loading" :fileListShow="fileListShow"
                      v-model:value="auditOpinion"/>
    </template>
  </steps>
  <opinion v-if="summaryData.taskId" :formData="summaryData.formData" :taskId="summaryData.taskId"  :taskUserOptionList="summaryData.taskUserOptionList"
           v-model:value="auditOpinion"></opinion>
</template>

<script setup lang="jsx">
import SummaryDetail from '@/components/DetailComponent/SummaryDetail.vue';
import {useProcessStore} from '@/stores/processStore.js';
import {getMapProjectStateInfo} from '@/components/steps/api';
import CollectionDetail from "@/components/DetailComponent/CollectionDetail.vue";
import {ElLoading, ElNotification} from "element-plus";

const route = useRoute()
const summaryData = ref({})
const summaryProcessViewer = ref(true)
const loading = ref(false)
const fileListShow = ref('READ')
const processStore = useProcessStore()
const active = ref(route.query.state)
const auditOpinion = ref('')
const showActive = ref()
const getInfo = async (state) => {
  const loading = ElLoading.service({fullscreen: true})
  try {
    fileListShow.value = 'READ'
    const projectId = route.query.projectId
    summaryProcessViewer.value = false
    loading.value = true
    const {code, data, msg} = await getMapProjectStateInfo(projectId, state)
    if (code === 1000) {
      data.formData.preProcess = data.formData.preProcess ? JSON.parse(data.formData.preProcess) : undefined

      summaryData.value = data;
      loading.value = false
      if(data.runningList===null) {
        loading.close()
        return;
      }
      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!=null){
          if (data.formPermMap["fileList"]) {
            fileListShow.value = data.formPermMap["fileList"].perm
          }
        }
      })
      loading.close()
    } else {
      ElNotification({
        title: '提示',
        message: msg,
        type: 'error'
      })
      if (msg === '查询结果为空') {
        summaryData.value = []
      }
      loading.close()
    }
  } catch {
    loading.close()
  }
}

const setDetail = (active) => {
  showActive.value = active
  getInfo(active)
}

const stepChange = (data) => {
  auditOpinion.value = ''
  showActive.value = data.active
  getInfo(data.active)
}
</script>
