handleExport = () => {
const { dispatch, form } = this.props;
const { paginationProps } = this.state;
let forPage = {
curPage: 1,
pageSize: 999999,
};
let options = {};
form.validateFields((err, fieldsValue) => {
if (err) return;
options = {
forPage,
...fieldsValue,
issueBeginDate: fieldsValue.issueDate[0].format('YYYY-MM-DD'),
issueEndDate: fieldsValue.issueDate[1].format('YYYY-MM-DD'),
};
const myRequest = new Request(`${BASE_URL}order/finance/billing/exportBillingListReport`, {
headers: {
Authorization: localStorage.getItem('Authorization').replace(/^"|"$/g, ''),
'Content-Type': 'application/json',
Accept: 'application/json',
},
method: 'POST',
body: JSON.stringify(options),
});
fetch(myRequest)
.then(response => response.blob())
.then(blob => {
madeExcel(blob, '账单');
});
});
function madeExcel(res, excelName) {
// 这里res是返回的blob对象
var blob = new Blob([res], {
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8',
}); // application/vnd.openxmlformats-officedocument.spreadsheetml.sheet这里表示xlsx类型
var downloadElement = document.createElement('a');
var href = window.URL.createObjectURL(blob); // 创建下载的链接
downloadElement.href = href;
downloadElement.download = moment().format('YYYY-MM-DD') + '附件报告' + '.xlsx'; // 下载后文件名
document.body.appendChild(downloadElement);
downloadElement.click(); // 点击下载
document.body.removeChild(downloadElement); // 下载完成移除元素
window.URL.revokeObjectURL(href); // 释放掉blob对象
}
};