md
This commit is contained in:
parent
cbf9d77b88
commit
ffaad4f768
48
src/vendor/Export2Excel.js
vendored
48
src/vendor/Export2Excel.js
vendored
@ -158,3 +158,51 @@ export function export_json_to_excel({header, data, filename='excel-list', autoW
|
||||
var wbout = XLSX.write(wb, {bookType: 'xlsx', bookSST: false, type: 'binary'});
|
||||
saveAs(new Blob([s2ab(wbout)], {type: "application/octet-stream"}), filename + ".xlsx");
|
||||
}
|
||||
|
||||
|
||||
|
||||
export function export_json_to_excel_by_tpl({tplData,header, data, filename='excel-list', autoWidth=true}={}) {
|
||||
/* original data */
|
||||
data=[...data]
|
||||
data.unshift(header);
|
||||
// var ws_name = "Sheet1";
|
||||
var ws_name = "Sheet1";
|
||||
var wb = XLSX.read(tplData,{type: 'buffer'});
|
||||
console.log("==wb=>",wb);
|
||||
|
||||
|
||||
var ws = sheet_from_array_of_arrays(data);
|
||||
|
||||
if(autoWidth){
|
||||
/*设置worksheet每列的最大宽度*/
|
||||
const colWidth = data.map(row => row.map(val => {
|
||||
/*先判断是否为null/undefined*/
|
||||
if (val == null) {
|
||||
return {'wch': 10};
|
||||
}
|
||||
/*再判断是否为中文*/
|
||||
else if (val.toString().charCodeAt(0) > 255) {
|
||||
return {'wch': val.toString().length * 2};
|
||||
} else {
|
||||
return {'wch': val.toString().length};
|
||||
}
|
||||
}))
|
||||
/*以第一行为初始值*/
|
||||
let result = colWidth[0];
|
||||
for (let i = 1; i < colWidth.length; i++) {
|
||||
for (let j = 0; j < colWidth[i].length; j++) {
|
||||
if (result[j]['wch'] < colWidth[i][j]['wch']) {
|
||||
result[j]['wch'] = colWidth[i][j]['wch'];
|
||||
}
|
||||
}
|
||||
}
|
||||
ws['!cols'] = result;
|
||||
}
|
||||
|
||||
/* add worksheet to workbook */
|
||||
wb.SheetNames.push(ws_name);
|
||||
wb.Sheets[ws_name] = ws;
|
||||
|
||||
var wbout = XLSX.write(wb, {bookType: 'xlsx', bookSST: false, type: 'binary'});
|
||||
saveAs(new Blob([s2ab(wbout)], {type: "application/octet-stream"}), filename + ".xlsx");
|
||||
}
|
||||
|
||||
@ -406,6 +406,7 @@ import MergeBillForm from '@/views/emis/emisSettleBill/MergeBillForm.vue';
|
||||
import { parseTime,genJsSeqNo } from "@/utils/custom";
|
||||
|
||||
import { listEmisSettleSubBill} from "@/api/emis/emisSettleSubBill";
|
||||
import axios from 'axios';
|
||||
|
||||
|
||||
export default {
|
||||
@ -521,6 +522,7 @@ export default {
|
||||
remark: null,
|
||||
delFlag: null,
|
||||
},
|
||||
templateFile: '/static/tpl/billExportTpl.xls',
|
||||
};
|
||||
},
|
||||
created() {
|
||||
@ -636,6 +638,8 @@ export default {
|
||||
const loadingInstance = this.$loading({
|
||||
text: '正在导出...'
|
||||
})
|
||||
|
||||
|
||||
var qParam = {...this.queryParams};
|
||||
qParam.pageNum=1;
|
||||
qParam.pageSize=5000;
|
||||
@ -643,19 +647,69 @@ export default {
|
||||
listEmisSettleBill(this.addDateRange(qParam, this.dateTimeRange)).then(response => {
|
||||
this.downloadLoading = false
|
||||
if (response.code === 200) {
|
||||
const curList = response.rows
|
||||
import('@/vendor/Export2Excel').then(excel => {
|
||||
const tHeader = ['id','总结算账单编号','结算账单名称','结算账单类型','结算开始时间','结算结束时间','账单月份','应收款金额','已收款金额','月结编号','客户编码','客户名称','结算站点代码','结算站点名称','安全金额','允许金额','抵扣金额','其他金额','安全原因','允许原因','抵扣原因','其他原因','开票状态','付款状态','总票数','总件数','总重量','未结数量','合计金额','退款数量','退款金额','财务确认状态','财务确认日期','财务确认站点','财务确认人','站点确认状态','财务确认备注','站点确认日期','站点确认人','网点确认备注','备注','删除标志(0代表存在','创建者','创建时间','更新者','更新时间','创建站点','更新站点',];
|
||||
const filterVal = ['id','settleBillNo','settleBillName','settleType','settleStartDate','settleEndDate','billMonth','recMoney','recedMoney','custNo','customerCode','customerName','siteCode','siteName','satisfyMoney','allowanceMoney','deductionMoney','otherMoney','satisfyReason','allowanceReason','deductionReason','otherReason','openBillStatus','paymentStatus','sendPieceSum','pieceNumber','feeWeight','uncollectedAmount','sendMoneySum','refundAmount','refundMoney','blConfirm','confirmDate','confirmSite','confirmManCode','blSiteConfirm','confirmNote','siteConfirmDate','siteConfirmManCode','siteConfirmNote','remark','delFlag','createBy','createTime','updateBy','updateTime','createSite','updateSite',];
|
||||
const data = this.formatJson(filterVal, curList, response.rows)
|
||||
excel.export_json_to_excel({
|
||||
header: tHeader,
|
||||
data,
|
||||
filename: '结算总账单',
|
||||
autoWidth: true
|
||||
})
|
||||
loadingInstance.close()
|
||||
|
||||
const curList = response.rows
|
||||
import('@/vendor/Export2Excel').then(excel => {
|
||||
|
||||
const tHeader = ['id','总结算账单编号','结算账单名称','结算账单类型','结算开始时间','结算结束时间','账单月份','应收款金额','已收款金额','月结编号','客户编码','客户名称','结算站点代码','结算站点名称','安全金额','允许金额','抵扣金额','其他金额','安全原因','允许原因','抵扣原因','其他原因','开票状态','付款状态','总票数','总件数','总重量','未结数量','合计金额','退款数量','退款金额','财务确认状态','财务确认日期','财务确认站点','财务确认人','站点确认状态','财务确认备注','站点确认日期','站点确认人','网点确认备注','备注','删除标志(0代表存在','创建者','创建时间','更新者','更新时间','创建站点','更新站点',];
|
||||
const filterVal = ['id','settleBillNo','settleBillName','settleType','settleStartDate','settleEndDate','billMonth','recMoney','recedMoney','custNo','customerCode','customerName','siteCode','siteName','satisfyMoney','allowanceMoney','deductionMoney','otherMoney','satisfyReason','allowanceReason','deductionReason','otherReason','openBillStatus','paymentStatus','sendPieceSum','pieceNumber','feeWeight','uncollectedAmount','sendMoneySum','refundAmount','refundMoney','blConfirm','confirmDate','confirmSite','confirmManCode','blSiteConfirm','confirmNote','siteConfirmDate','siteConfirmManCode','siteConfirmNote','remark','delFlag','createBy','createTime','updateBy','updateTime','createSite','updateSite',];
|
||||
const data = this.formatJson(filterVal, curList, response.rows)
|
||||
axios({
|
||||
method: "get",
|
||||
url: this.templateFile,
|
||||
responseType: "arraybuffer",
|
||||
}).then(response =>{
|
||||
|
||||
|
||||
console.log("==this.templateFile=>",this.templateFile);
|
||||
console.log("==xxxx=>",response);
|
||||
|
||||
excel.export_json_to_excel_by_tpl({
|
||||
tplData:response,
|
||||
header: tHeader,
|
||||
data,
|
||||
filename: '账单',
|
||||
autoWidth: true
|
||||
})
|
||||
|
||||
|
||||
}).catch(error => console.log(error))
|
||||
|
||||
|
||||
loadingInstance.close()
|
||||
})
|
||||
}
|
||||
});
|
||||
},
|
||||
/** 导出按钮操作 */
|
||||
handleExport_old() {
|
||||
// this.download('emis/emisSettleBill/export', {
|
||||
// ...this.queryParams
|
||||
// }, `emisSettleBill_${new Date().getTime()}.xlsx`)
|
||||
const loadingInstance = this.$loading({
|
||||
text: '正在导出...'
|
||||
})
|
||||
var qParam = {...this.queryParams};
|
||||
qParam.pageNum=1;
|
||||
qParam.pageSize=5000;
|
||||
|
||||
listEmisSettleBill(this.addDateRange(qParam, this.dateTimeRange)).then(response => {
|
||||
this.downloadLoading = false
|
||||
if (response.code === 200) {
|
||||
|
||||
// const curList = response.rows
|
||||
// import('@/vendor/Export2Excel').then(excel => {
|
||||
// const tHeader = ['id','总结算账单编号','结算账单名称','结算账单类型','结算开始时间','结算结束时间','账单月份','应收款金额','已收款金额','月结编号','客户编码','客户名称','结算站点代码','结算站点名称','安全金额','允许金额','抵扣金额','其他金额','安全原因','允许原因','抵扣原因','其他原因','开票状态','付款状态','总票数','总件数','总重量','未结数量','合计金额','退款数量','退款金额','财务确认状态','财务确认日期','财务确认站点','财务确认人','站点确认状态','财务确认备注','站点确认日期','站点确认人','网点确认备注','备注','删除标志(0代表存在','创建者','创建时间','更新者','更新时间','创建站点','更新站点',];
|
||||
// const filterVal = ['id','settleBillNo','settleBillName','settleType','settleStartDate','settleEndDate','billMonth','recMoney','recedMoney','custNo','customerCode','customerName','siteCode','siteName','satisfyMoney','allowanceMoney','deductionMoney','otherMoney','satisfyReason','allowanceReason','deductionReason','otherReason','openBillStatus','paymentStatus','sendPieceSum','pieceNumber','feeWeight','uncollectedAmount','sendMoneySum','refundAmount','refundMoney','blConfirm','confirmDate','confirmSite','confirmManCode','blSiteConfirm','confirmNote','siteConfirmDate','siteConfirmManCode','siteConfirmNote','remark','delFlag','createBy','createTime','updateBy','updateTime','createSite','updateSite',];
|
||||
// const data = this.formatJson(filterVal, curList, response.rows)
|
||||
// excel.export_json_to_excel({
|
||||
// header: tHeader,
|
||||
// data,
|
||||
// filename: '结算总账单',
|
||||
// autoWidth: true
|
||||
// })
|
||||
// loadingInstance.close()
|
||||
// })
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user