<template>
  <div class="ele-body">
    <el-card shadow="never">
      <doc-search @search="reload" />
      <ele-pro-table
        ref="table"
        :columns="columns"
        :datasource="datasource"
        height="calc(100vh - 350px)"
        class="dict-table"
        tool-class="ele-toolbar-actions"
      >
        <!-- 工具栏 -->
        <template v-slot:toolbar>
          <el-button type="primary" @click="handleUpload">上传</el-button>
        </template>
        <template v-slot:action="{ row }">
          <el-link type="primary" @click="handleDownload(row)">下载</el-link>
        </template>
      </ele-pro-table>
    </el-card>
    <uploadDialog ref="uploadDialogRef" />
  </div>
</template>

<script>
  import { getFile, getFileList } from '@/api/system/file/index.js';

  import docSearch from './components/doc-search';
  import uploadDialog from './components/upload-dialog.vue';
  export default {
    components: { docSearch, uploadDialog },
    data () {
      return {
        columns: [
          {
            label: '序号',
            type: 'index',
            width: 55,
            align: 'center'
          },
          {
            label: '文档名称',
            prop: 'name',
            minWidth: '180',
            showOverflowTooltip: true
          },
          {
            label: '文档类型',
            prop: 'type'
          },
          {
            label: '系统'
          },
          {
            label: '储存路径',
            prop: 'storePath',
            minWidth: '180',
            showOverflowTooltip: true
          },
          {
            label: '模块名',
            prop: 'module'
          },
          {
            label: '上传时间',
            prop: 'createTime'
          },
          {
            label: '操作',
            slot: 'action',
            action: 'action'
          }
        ]
      };
    },
    methods: {
      datasource ({ page, where, limit }) {
        return getFileList({
          ...where,
          pageNum: page,
          size: limit
        });
      },
      reload (where) {
        this.$refs.table.reload({ where });
      },
      handleUpload () {
        this.$refs.uploadDialogRef.open();
      },
      handleDownload (row) {
        getFile({ objectName: row.storePath });
      }
    }
  };
</script>
