<el-form-item>
<el-button size="small" type="success" @click="outExe()"><i class="el-icon-search"/>导出</el-button>
</el-form-item>
outExe() {
this.$confirm('此操作将导出excel文件, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.listLoading = true
getList({ actiontype: 'order_count_exp',ctype:this.search.ctype,counttime:this.search.counttime}, this.listQuery).then(response => {
if (response.resultCode == 200) {
import('@/vendor/Export2ExcelStyle').then(excel => {
const multiHeader = response.data.multiHeader
const tHeader = response.data.headArr
const filterVal = response.data.filterVal
const list = response.data.list
if (list.length == 0) {
this.$message.error('没有数据,不能导出');
return;
}
const merges = ['A1:A2', 'B1:B2', 'C1:C2', 'D1:D2', 'E1:E2', 'F1:F2', 'G1:G2', 'H1:K1', 'L1:P1']
// const title = 'titile'
// console.log(filterVal, list);
const data = this.formatJson(filterVal, list)
excel.export_json_to_excel({
// title,
multiHeader,
header: tHeader,
data: data,
filename: response.data.fileName,
merges,
autoWidth: false,
bookType: 'xlsx',
})
})
}else{
this.$message({
message: response.data,
type: 'error'
})
}
this.listLoading = false
}).catch(error => {
console.log(error)
})
}).catch(() => {
});
},
formatJson(filterVal, jsonData) {
return jsonData.map(v => filterVal.map(j => {
if (j === 'timestamp') {
return parseTime(v[j])
} else {
return v[j]
}
}))
},
$data['fileName'] = 'love_order_count_exp_' . date("Y-m-d");
$data['filterVal'] = ['id', 'ctype_name', 'counttime', 'orderfee', 'payfee', 'refundfee', 'truefee', 'otype_1', 'otype_2', 'otype_3', 'otype_4', 'ptype_1', 'ptype_2', 'ptype_3', 'ptype_4', 'ptype_5'];
$data['multiHeader'] = [['序号', '类型', '日期', '订单总额', '实收', '退款', '净收入', '类型', '', '', '', '来源']];
$data['headArr'] = ['', '', '', '', '', '', '', '活动', '会员', '认证', '一周CP', '微信', '小程序', '后台', '触屏', 'APP'];
这里要注意multiHeader数组中,类型后面空了3个,是因为类型这栏合并了4列,下面子类有4列,如果不空的话,会吧来源覆盖
headArr前面空了7列,是因为前7个不需要多级表头
参考网址
https://blog.csdn.net/weixin_43965143/article/details/106572755
https://www.jianshu.com/p/06521a9c75d8
js附件
声明:此文系舞林cuzn(www.wulinlw.org)原创稿件,转载请保留版权