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

<script>
export default {
  props:['tablecols','param','excelTitle','total'],
  data () {
    return {}
  },
  methods:{
    async submit () {
      let data = {}
      // 如果传入了total,需要赋值保证数量准确性
      if (this.total) {
        this.param.content.pageSize = this.total
      }
      data = JSON.parse(JSON.stringify(this.param))

      data.content.isAll = true
      const res = await this.$api.requested(data)
      res.data.forEach(item => {
        item.amount = this.tool.formatAmount(item.gradeprice * item.qty,2)
      })
      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>