const handleExport = () => {
setExportLoading(true)
const { isPackage, paymentDays } = form.getFieldsValue();
fetch(`/orderdriverpc/api/report/exportExcel`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
redirect: 'follow',
body: JSON.stringify({
packageId: taskId?.split('-')[0],
orgId: gridInfo !== '' ? gridInfo : (cityInfo !== '' ? cityInfo : (areaInfo !== '' ? areaInfo : (provInfo !== '' ? provInfo : ''))),
orgLevel: tabValue,
isPackage: isPackage,
provinceCode: currentUser?.provinceCode,
paymentDays: paymentDays.format('YYYY-MM-DD'),
}),
})
.then((res) => res.blob())
.then((e) => {
setExportLoading(false)
let objectUrl = URL.createObjectURL(e);
const a = document.createElement('a');
a.style.display = 'none';
a.download = paymentDays.format('YYYY-MM-DD') + '组织维度报表.xlsx';
a.href = objectUrl;
a.click();
});
};
导出为excel文件的方法
const downloadFileToExcel = () => {
let option = {};
let dataTable = [];
let theadArr = [];
let theadArrDataIndex = [];
dataForDownLoad?.tHead &&
dataForDownLoad.tHead.length > 0 &&
dataForDownLoad?.tHead.map((item) => {
theadArr.push(item.title);
theadArrDataIndex.push(item.dataIndex);
});
dataForDownLoad?.tBody &&
dataForDownLoad.tBody.length > 0 &&
dataForDownLoad?.tBody.map((item, index) => {
if (!item.key) {
item.key = index;
}
let obj = {};
theadArr.map((i, x) => {
obj[i] = item[theadArrDataIndex[x]];
});
dataTable.push(obj);
});
option.fileName = dataForDownLoad?.title;
option.datas = [
{
sheetData: dataTable,
sheetName: dataForDownLoad?.title,
sheetFilter: theadArr,
sheetHeader: theadArr,
},
];
let toExcel = new ExportJsonExcel(option);
toExcel.saveExcel();
};