<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="left">
      <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>-->
        <el-col :span="24">
          <el-form-item label="专项资金情况说明" >
            <div style="white-space: pre-wrap">{{formData.introduce}}
            </div>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row style="margin-top: -18px;" class="projects">
        <baseTitle title="关联项目"></baseTitle>
        <el-col :span="24">
          <el-form-item>
            <fvTable style="width: 100%;max-height:160px" height="160" v-if="showTable" :tableConfig="projectTable"
                     :data="formData.projects" :isSettingCol="false" :pagination="false">
              <template #empty>
                <el-empty :image-size="55" description="暂无数据" style="padding: 0"/>
              </template>
            </fvTable>
          </el-form-item>
        </el-col>
      </el-row>
        <el-row style="margin-top: -18px;" class="projects">
        <baseTitle title="附件文件"></baseTitle>
        <el-col :span="24">
          <el-form-item>
            <fvTable style="width: 100%;max-height: 160px;" height="160"  v-if="showTable" :tableConfig="fileTable"
                     :data="formData.files" :isSettingCol="false" :pagination="false">
              <template #empty>
                <el-empty :image-size="55" 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" :taskUserOptionList="fundData.taskUserOptionList"
             v-model:value="formData.auditOpinion"></opinion-moblie>
    <file-preview ref="filePreviewRef" :fullscreen="true"  v-if="filePreviewShow" :fileName="filePreviewParam.fileName" :fileUrl="filePreviewParam.fileUrl"
                  :fileType="filePreviewParam.fileType"/>
  </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 router = useRouter()
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: 85
    },
    {
      prop: 'projectName',
      label: '项目名称',
      align: 'center',
      width: 200,
    },
    {
      prop: 'specialFundAmount',
      label: '项目金额',
      align: 'center',
      currentRender:({row})=>{
        return <span>{toThousands(row.specialFundAmount)}</span>
      }
    },
    {
      prop: 'startTime',
      label: '项目时间',
      align: 'center',
      width: 180,
    },
    // {
    //   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: 85,
    },
    {
      prop: 'originalFileName',
      label: '文件名',
      align: 'center',
      width: 200,
      showOverflowTooltip: false,
      currentRender: ({row, index}) => (<div style="color: #2a99ff;cursor: pointer;" onClick={()=>clickToPreview(row)}>{row.originalFileName}</div>)
    },
    {
      prop: 'tag',
      label: '标签',
      align: 'center'
    },
    {
      prop: 'size',
      label: '文件大小',
      align: 'center',
      width: 150,
      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 filePreviewParam = ref({
  fileUrl: '',
  fileName: '',
  fileType: 'pdf'
})
const filePreviewShow = ref(false)
const clickToPreview=(row)=>{
  filePreviewShow.value = false
  filePreviewParam.value = {
    fileUrl: row.url,
    fileName: row.originalFileName,
    fileType: row.fileType
  }
  nextTick(()=>{
    filePreviewShow.value = true
  })
}
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>
