<template>
  <fvSearchForm :searchConfig="searchConfig" @search="search"></fvSearchForm>
  <el-card style="width: 100%">
    <file-upload @getFile="getOtherFile" :showFileList="true"/>
    <fvTable style="width: 100%;max-height: 250px" v-if="showTable" :tableConfig="tableConfig"
             :data="otherFileList" :isSettingCol="false" :pagination="false">
      <template #empty>
        <el-empty :image-size="90" description="暂无数据" style="padding: 0"/>
      </template>
    </fvTable>
  </el-card>
</template>

<script setup lang="jsx">
import {downloadFile} from "@/api/project-demand";

const searchConfig = reactive([
  {
    label: '关键词',
    prop: 'collectType',
    component: 'el-input',
    props: {
      placeholder: '请输入',
      clearable: true,
      filterable: true,
    }
  }
])
const tableConfig = reactive({
  columns: [
    {
      prop: 'originalFileName',
      label: '附件名称',
      align: 'center',
    },
    {
      prop: 'tag',
      label: '自定义标签',
      align: 'center'
    },
    {
      prop: 'tag',
      label: '内置标签',
      align: 'center'
    },
    {
      prop: 'tag',
      label: '上传时间',
      align: 'center'
    },
    {
      prop: 'oper',
      label: '操作',
      align: 'center',
      currentRender: ({row, index}) => {
        return (
            <div>
              <el-button type="primary" link onClick={() => handleDownload(row)}>下载</el-button>
            </div>
        )
      }
    }
  ]
})
const showTable=ref(true)
const otherFileList = ref([])
const getOtherFile = () => {

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

<style scoped>

</style>
