<template>
  <div>
    <el-button type="success" size="small" icon="el-icon-download" @click="submit()">导 出</el-button>
  </div>
</template>

<script>
export default {
  props:['tablecols','param','excelTitle'],
  data () {
    return {}
  },
  methods:{
    async submit () {
      let data = {}
      data = JSON.parse(JSON.stringify(this.param))

      data.content.isAll = true
      console.log(data,this.param)
      const res = await this.$api.requested(data)
      let table = JSON.parse(JSON.stringify(this.tablecols))
      table.forEach((e,index) => {
        // 由于表格数据结构问题这里需要判断一下
        if (e.title === '省市县') {
          table[index].title = '省'
          table.splice(index + 1,0,{title:'市',columnname:'city'},{title:'县',columnname:'county'})
        }
      });
      let hd = table.map(e=>{
        return e.title
      })
      let ft = table.map(e=>{
        return e.columnname
      })
      this.tool.exportExcel(hd,ft,res.data,this.excelTitle)
    }
  }
}

</script>
<style>
</style>