<template>
  <div v-loading="loading">
    <el-form :model="formData" label-width="auto">
      <el-row>
        <el-col :span="12" v-if="type==='singleDetail'">
          <el-form-item label="征集名称">
            <span>{{ formData.requirementName }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="征集类型">
            <span>{{ formData.collectType }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="12" v-if="type==='singleDetail'">
          <el-form-item label="所属公司">
            <span>{{ formData.companyIds }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="截止时间">
            <span>{{ formData.deadline }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="formData.isSpecialFund">
          <el-form-item label="专项资金">
            <span>{{ formData.specialFund }}</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.collectExplain">
              </div>
            </el-card>
          </el-form-item>
        </el-col>
        <baseTitle v-if="fileListShow === 'READ' || fileListShow === 'EDIT'" title="附件列表"></baseTitle>
        <el-col :span="24">
          <file-component title="" tag="需求征集"
                          v-model:value="formData.fileList" :processViewer="processViewer"
                          :file-list-show="fileListShow"/>
        </el-col>
        <el-col :span="24">
          <div v-if="data.taskId">
            <baseTitle title="审核意见"></baseTitle>
            <el-form-item prop="_value">
              <el-input
                  v-model="_value"
                  :rows="3"
                  type="textarea"
                  placeholder="请输入审核意见"
              />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <div class="approval-record">
        <baseTitle title="审批记录"></baseTitle>
        <div class="process">
          <operation-render v-if="processViewer && data.operationList && data.operationList.length > 0" :operation-list="data.operationList"
                            :state="data.state"/>
          <process-diagram-viewer v-if="processViewer" id-name="collectionProcess"/>
        </div>
      </div>
    </el-form>
  </div>
</template>

<script setup lang="jsx">
import OperationRender from '@/views/workflow/common/OperationRender.vue'
import ProcessDiagramViewer from '@/views/workflow/common/ProcessDiagramViewer.vue'
import {downloadFile} from "@/api/project-demand";

const emit = defineEmits(['update:value'])
const props = defineProps({
  formData: {
    type: Array,
    default: []
  },
  data: {
    type: Array,
    default: []
  },
  processViewer: {
    type: Boolean,
    default: false
  },
  companyOption: {
    type: Array,
    default: []
  },
  loading: {
    type: Boolean,
    default: false
  },
  fileListShow: {
    type: String,
    default: ''
  },
  type: {
    type: String,
    default: ''
  },
  value: {
    type: String,
    default: ''
  }
})

const _value = computed({
  get() {
    return props.value;
  },
  set(val) {
    emit("update:value", val);
  }
})


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()
  })
}

watch(() => props.loading, (newVal) => {
  props.loading = newVal
}, {deep: true})

watch(() => props.processViewer, (newVal) => {
  props.processViewer = newVal
}, {deep: true})
</script>

<style scoped lang="scss">
:deep(.el-empty__description) {
  margin-top: 0;
}

.approval-record {
  padding-bottom: 30px;

  .process {
    position: relative;
  }
}
</style>
