export default ({ exportFileName, exportURL, exportColumns, pager, context, exportConfig, vm }) => {
	const config = {
		undefined: 'string',
		string: 'string',
		number: 'number',
		date: 'date',
		datetime: 'date',
		dict: 'string',
		boolean: 'boolean',
		asyncTrans: 'string'
	};
	vm.$http.axios
		.post(
			exportURL,
			{
				exportAllData: exportConfig.state !== "1",
				exportColumns: exportColumns
					.filter(({ colDef: colDef }, index) => {
						return !(['_rowIndex', '_selection'].includes(colDef.field) || (colDef.cellRendererParams && !colDef.cellRendererParams.exportExcel) || colDef.type === 'button');
					})
					.map(({ colDef }) => {
						return {
							codeTable: colDef.cellRendererParams
								? {
									dict: typeof colDef.cellRendererParams.dict === 'string' ? context.dicts[colDef.cellRendererParams.dict] : colDef.cellRendererParams.dict ? colDef.cellRendererParams.dict : {},
									asyncTrans: context.gridDicts[colDef.colId]
								}[colDef.type]
								: {},
							columnAlign: colDef.type === 'number' ? 'right' : 'center',
							columnId: colDef.field,
							columnTitle: colDef.headerName,
							dataType: config[colDef.type] ? config[colDef.type] : 'string',
							format: { number: '###,###,###, ##0.00', date: 'yyyy-MM-dd', datetime: 'yyyy-MM-dd HH:mm:ss' }[colDef.type],
							subtotal: colDef.cellRendererParams ? (typeof colDef.cellRendererParams.subTotal === 'boolean'?colDef.cellRendererParams.subTotal:false) : false
						};
					}),
				exportFileName: exportFileName,
				externalObj: pager.externalObj,
				externalParameters: pager.externalParameters,
				fastQueryExpression: '',
				fastQueryParameters: pager.fastQueryParameters,
				maxRecorderCount: exportConfig.state === "1" ? 5000 : exportConfig.max,
				nowPage: exportConfig.state === "1" ? pager.nowPage : 1,
				pageSize: pager.pageSize
			},
			{ responseType: 'arraybuffer' }
		)
		.then(response => {
			//console.log(response);
			let url = window.URL.createObjectURL(new Blob([response.data]));
			let link = document.createElement('a');
			link.style.display = 'none';
			link.href = url;
			link.setAttribute('download', exportFileName + '.xlsx');

			document.body.appendChild(link);
			link.click();
		})
		.catch(err => {
			console.error(err);
		});
};
