<template>
  <!-- 导出报表 -->
  <div>
    <!-- 表格 -->
    <elm-table
      :table-data="dataList"
      :colum-obj="columObj"
      :loading="loading"
      v-bind="$attrs"
      :tree-props="{ children: 'child' }"
      v-on="$listeners"
      @rowOperation="rowOperation"
      @getList="getList()"
    />
    <el-row v-if="rowCount > 0" class="text-center">
      <el-pagination
        background
        :current-page="queryParams.current"
        :page-sizes="[10, 20, 50, 100, 200]"
        :page-size="queryParams.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="rowCount"
        @pagination="getList"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-row>
  </div>
</template>
<script>
import { getexportlist, getdownload } from '@/apiV2/exportlist'
import ElmTable from '@/components/ElmTable/index.vue'
export default {
  name: 'ListBox1',
  components: { ElmTable },
  data() {
    return {
      columObj: {
        lazy: 'true',
        columnData: [
          { ownDefined: true, prop: 'name', label: '报表名称', ownDefinedReturn: row => { return row.name || '--' } },
          { ownDefined: true, prop: 'fileName', label: '文件名称', ownDefinedReturn: row => { return row.fileName || '--' } },
          { ownDefined: true, prop: 'fileSize', label: '文件大小', ownDefinedReturn: row => { return row.fileSize || '--' } },
          { ownDefined: true, prop: 'createTime', label: '导出时间', ownDefinedReturn: row => { return row.createTime || '--' }, minwidth: '120', sortable: true },
          {
            isOperation: true, prop: 'operation', label: '操作', minwidth: '70', fixed: 'right', tooltip: false,
            operation: [
              { operation: 'download', type: 'text', label: '下载导出数据', isShow: (row) => this.filterButton('exportlist_down1') }
            ]
          }
        ]
      },
      queryParams: {
        current: 1,
        size: 10,
        pages: 1,
        type: 2,
        platform: 1
      },
      loading: false,
      dataList: '',
      rowCount: 0
    }
  },
  created() {
    this.getList()
    this.$bus.on('projectChange', (project) => {
      this.getList()
    })
  },
  methods: {
    rowOperation(row, $index, event) {
      switch (event) {
        case 'download':
          this.handledownload(row)
          break
      }
    },
    getList() {
      this.loading = true
      getexportlist(this.queryParams).then(res => {
        if (res.success) {
          this.dataList = res.data.records
          this.rowCount = res.data.total
          this.loading = false
        }
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },
    // 每页显示多少条
    handleSizeChange(val) {
      this.queryParams.size = val
      this.getList()
    },
    // 点击当前页
    handleCurrentChange(val) {
      this.queryParams.current = val
      this.getList()
    },
    handledownload(row) {
      getdownload(row.id).then(res => {
        this.downloadExcel(res)
      })
    }
  }
}
</script>
<style lang="scss" scoped>

</style>
