<script setup name="projectProgress">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import SjFlowRecord from '@/pages/projectStoreManage/projectStore/projectDetail/components/sjFlowRecord.vue'
const props = defineProps({
  detailData: Object,
  stepData: {
    type: Array,
    default: undefined
  }
})
const router = useRouter()
const
  stepList = ref([
    {
      title: '项目申报',
      stage: 10000,
      instName: '项目申报',
      status: [10000]
    },
    {
      title: '单位内部审核',
      stage: 10000,
      finishLinkText: '查看审核记录',
      instName: '单位内部审批流程',
      status: [10001, 10002]
    },
    {
      title: '项目预审',
      stage: 10000,
      finishLinkText: '查看审核记录',
      instName: '项目预审审批流程',
      status: [10003, 10006, 10007]
    },
    {
      title: '部门联审',
      stage: 10000,
      finishLinkText: '查看审核记录',
      instName: '部门联合审批流程',
      status: [10004, 10005, 10008, 10009]
    },
    {
      title: '年度计划',
      stage: 10000,
      // finishLinkText: '查看审核记录'
      status: [10010, 10011]
    },
    {
      title: '建设方案评审',
      stage: 10000,
      finishLinkText: '查看审核记录',
      instName: '建设方案评审流程',
      status: [10012, 10013, 10016]
    },
    {
      title: '立项批复',
      stage: 10000,
      status: [10014]
    },
    {
      title: '招标采购',
      stage: 20000,
      status: [20001]
    },
    {
      title: '项目初验',
      stage: 20000,
      status: [20002]
    },
    {
      title: '项目终验',
      stage: 20000,
      status: [20003, 20004, 20005]
    },
    {
      title: '归档',
      stage: 30000,
      status: [30000, 30001]
    }
  ]),
  processStatusOptions = {
    'NOT_START': 'wait', // 未开始
    'ON_GOING': 'process', // 进行中
    'REJECTED': 'error', // 被驳回
    'COMPLETED': 'success' // 已完成
  },
  emits = defineEmits(['showFlowRecordDialog']),
  getStepActive = () => {
    if (props.stepData && props.stepData.find(i => i.stepStatus !== 'COMPLETED')) {
      return props.stepData.findIndex(i => i.stepStatus !== 'COMPLETED')
    } else if (props.stepData?.length) {
      return props.stepData.length - 1
    }
  },
  getProcessStatus = () => {
    if (props.stepData && props.stepData.find(i => i.stepStatus !== 'COMPLETED')) {
      return processStatusOptions[props.stepData.find(i => i.stepStatus !== 'COMPLETED').stepStatus]
    } else if (props.stepData?.length) {
      return processStatusOptions[props.stepData[props?.stepData?.length - 1]?.stepStatus]
    }
  },
  // 重新申报
  toRe = () => {
    if (props.detailData.status === 20005) {
      router.push({ name: 'declarationFinal', query: { id: props.detailData.id }})
    } else {
      router.push({ name: 'declarePage', query: { id: props.detailData.id }})
    }
  },
  // 省级联审意见
  visible = ref(false),
  sjLsData = ref(),
  showSjlsDiaolig = (data) => {
    visible.value = true
    sjLsData.value = JSON.parse(data)
    console.log(sjLsData.value)
  }
</script>

<template>
  <el-card shadow="never">
    <template #header>当前进度</template>
    <el-steps :active="getStepActive()" finish-status="success" :process-status="getProcessStatus()">
      <el-step v-for="(item,index) in stepData" :key="index" :title="item.processName">
        <template #description>
          <div :class="`${item.stepStatus==='COMPLETED'?'text-success':item.stepStatus==='ON_GOING'?'text-warning':item.stepStatus==='REJECTED'?'text-danger':''}`">
            <p class="mt-6">{{ item.stepStatus==='COMPLETED'?'已完成':item.stepStatus==='NOT_START'?'未开始':item.stepStatus==='ON_GOING'?'进行中':item.stepStatus==='REJECTED'&&detailData.status!==10011?'被驳回':item.stepStatus==='REJECTED'&&detailData.status===10011?'被暂缓':'' }}</p>
            <p v-if="item.finishTime">{{ item.finishTime }}</p>
          </div>
          <p v-if="item.processProgressVo||item.content">
            <a v-if="item.processProgressVo||item.content" @click="emits('showFlowRecordDialog',item?.processProgressVo?.progressInfo,item?.content)">查看审核记录</a>
          </p>
          <p v-if="false&&item.processName==='省级部门联审'&&item.stepStatus==='COMPLETED'">
            <a @click="showSjlsDiaolig(item.content)">查看审核记录</a>
          </p>
          <p>
            <a v-if="stepList.find(i=>i.status.includes(detailData.status))?.title===item.processName&&processStatusOptions[item.stepStatus]==='error'&&detailData.status!==10009&&detailData.status!=10011" class="ml-0" @click="toRe">重新申报</a>
          </p>
        </template>
      </el-step>
    </el-steps>
  </el-card>
  <el-dialog
    :model-value="visible"
    title="省级联审意见"
    width="70%"
    destroy-on-close
    @closs="visible=false"
  >
    <sj-flow-record :flow-data="sjLsData" />
  </el-dialog>
</template>
