<template>
<!--  <special-fund-detail :formData="fundData.formData" :data="fundData" :showTable="showTable" :processViewer="fundProcessViewer"-->
<!--                       :loading="loading"/>-->

  <div v-loading="loading" style="padding: 0 10px;">
    <baseTitle title="专项资金详情"></baseTitle>
    <el-form :model="formData" ref="form" label-width="auto">
      <el-row>
        <el-col :span="24">
          <el-form-item label="专项名称">
            <span>{{ formData.name }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="金额(元)">
            <span>{{ toThousands(formData.fundAmount) }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="剩余金额(元)">
            <span>{{ toThousands(formData.residualAmount) }}</span>
          </el-form-item>
        </el-col>
        <baseTitle title="介绍"></baseTitle>
        <el-col :span="24">
          <el-form-item>
            <el-card style="width: 100%">
              <div v-html="formData.introduce">
              </div>
            </el-card>
          </el-form-item>
        </el-col>
        <baseTitle title="关联项目"></baseTitle>
        <el-col :span="24">
          <el-form-item>
            <fvTable style="width: 100%;max-height:300px" v-if="showTable" :tableConfig="projectTable"
                     :data="formData.projects" :isSettingCol="false" :pagination="false">
              <template #empty>
                <el-empty :image-size="90" description="暂无数据" style="padding: 0"/>
              </template>
            </fvTable>
          </el-form-item>
        </el-col>
        <baseTitle title="附件列表"></baseTitle>
        <el-col :span="24">
          <el-form-item>
            <fvTable style="width: 100%;max-height: 300px;" v-if="showTable" :tableConfig="fileTable"
                     :data="formData.files" :isSettingCol="false" :pagination="false">
              <template #empty>
                <el-empty :image-size="90" description="暂无数据" style="padding: 0"/>
              </template>
            </fvTable>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <div v-if="fundData.taskId">
            <baseTitle title="审核意见"></baseTitle>
            <el-form-item prop="auditOpinion">
              <el-input
                  v-model="formData.auditOpinion"
                  :rows="3"
                  type="textarea"
                  placeholder="请输入审核意见"
              />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <div class="approval-record">
        <div class="approval-title">
          <baseTitle title="审批记录"></baseTitle>
          <div class="diagram">
            <div class="base-title">流程图</div>
            <el-switch
                v-model="changeDiagram"
                style="--el-switch-on-color:#BEA266; --el-switch-off-color:#cecdcd"
            />
          </div>
        </div>
        <div class="process">
          <operation-render v-if="fundProcessViewer && fundData.operationList && fundData.operationList.length > 0&&!changeDiagram" :isColumn="true"
                            :operation-list="fundData.operationList"
                            :state="fundData.state"/>
          <process-diagram-viewer v-if="fundProcessViewer&&changeDiagram" id-name="fundProcess"/>
        </div>
      </div>
    </el-form>
    <opinion-moblie v-if="fundData.taskId" :formData="formData" :taskId="fundData.taskId"
             v-model:value="formData.auditOpinion"></opinion-moblie>
  </div>
</template>

<script setup lang="jsx">
import {toThousands} from '@/utils/changePrice.js'
import OperationRender from '@/views/workflow/common/OperationRender.vue'
import ProcessDiagramViewer from '@/views/workflow/common/ProcessDiagramViewer.vue'
import {downloadFile} from "@/api/project-demand";
import {ElNotification} from "element-plus";
import {useProcessStore} from '@/stores/processStore.js';
import {getFundDetailProcess} from "@/api/special-fund";
import OpinionMoblie from "./OpinionMoblie.vue";
const processStore = useProcessStore()
const route = useRoute()
const changeDiagram = ref(false)
const fundData = ref({})
const formData = ref({})
const fundProcessViewer = ref(true)
const showTable = ref(true)
const loading = ref(false)
const projectTable = reactive({
  columns: [
    {
      prop: 'index',
      type: 'index',
      label: '序号',
      align: 'center',
      width: '80',
    },
    {
      prop: 'projectName',
      label: '项目名称',
      align: 'center',
    },
    {
      prop: 'specialFundAmount',
      label: '项目金额',
      align: 'center',
      currentRender:({row})=>{
        return <span>{toThousands(row.specialFundAmount)}</span>
      }
    },
    {
      prop: 'startTime',
      label: '项目时间',
      align: 'center'
    },
    {
      prop: 'oper',
      label: '操作',
      align: 'center',
      currentRender: ({row, index}) => {
        return (
            <el-button type="primary" link onClick={() => handleView(row)}>查看</el-button>
        )
      }
    }
  ]
})
const fileTable = reactive({
  columns: [
    {
      prop: 'index',
      type: 'index',
      label: '序号',
      align: 'center',
      width: '80',
    },
    {
      prop: 'originalFileName',
      label: '文件名',
      align: 'center',
    },
    {
      prop: 'tag',
      label: '标签',
      align: 'center'
    },
    {
      prop: 'size',
      label: '文件大小',
      align: 'center',
      currentRender: ({row, index}) => (parseInt(row.size / 1024) + 'KB')
    },
    {
      prop: 'oper',
      label: '操作',
      align: 'center',
      currentRender: ({row, index}) => {
        return (
            <el-button type="primary" link onClick={() => handleDownload(row)}>下载</el-button>
        )
      }
    }
  ]
})
const handleView=(row)=>{
  router.push({
    name: 'Implementation/detail',
    query: {
      id: row.requirementId,
      projectId: row.projectId,
      // step: '40'
    }
  })
}
const handleDownload = (row) => {
  downloadFile(row.fileId).then(res => {
    const blob = new Blob([res])
    let a = document.createElement('a')
    a.href = URL.createObjectURL(blob)
    a.download = row.originalFileName
    a.click()
  })
}
const getDetail = async () => {
  const specialFundId = route.query.id
  showTable.value = false
  loading.value = true
  fundProcessViewer.value = false
  const {code, data, msg} = await getFundDetailProcess(specialFundId)

  if (code === 1000) {
    fundData.value = data
    formData.value = data.formData
    loading.value = false
    if(data.operationList==null)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(() => {
      fundProcessViewer.value = true
      showTable.value = true
    })
  }else {
    ElNotification({
      title: '提示',
      message: msg,
      type: 'error'
    })
    loading.value = false
  }
}
getDetail()
</script>
<style scoped>
:deep(.el-table--fit ) {
  height: 300px !important;
}
</style>
