<template>
  <el-button :loading="loading" size="small" @click="handleExport">{{options.name||'导出'}}</el-button>
</template>

<script>
// import './export2excel.min.js'
// import exportE from './export2excel.js'
import exportExcel from './exportExcel.js'
export default {
  name: 'Table2Excel',
  props: {
    options: {
      type: Object,
      default: () => ({})
    },
    // // 表格头部格式
    theadMap: {
      type: Array,
      default: () => []
    },
    // 表格每列字段
    theadProps: {
      type: Object,
      default: () => {}
    },
    // 表格底部格式和数据，主要用于填写标注和格式
    tfootData: {
      type: Array,
      default: () => []
    },
    baseApi: {
      type: String,
      default: ''
    },
    dataName: {
      type: String,
      default: 'excel.xlsx'
    }
  },
  data() {
    return {
      loading: false
    }
  },
  methods: {
    handleExport() {
      this.$emit('click')
      this.loading = true
    },
    exportToExcel(obj) {
      this.loading = false
      if (obj) {
        exportExcel({
          theadMap: this.theadMap,
          theadProps: this.theadProps,
          tableData: obj,
          tfootData: this.tfootData,
          baseApi: this.baseApi,
          dataName: this.dataName
        })
      }
    }
  }
}
</script>
