diff --git a/js/demandPlan/child/delivery_batch_list.js b/js/demandPlan/child/delivery_batch_list.js index 14ce8d4..2aeb773 100644 --- a/js/demandPlan/child/delivery_batch_list.js +++ b/js/demandPlan/child/delivery_batch_list.js @@ -262,7 +262,7 @@ function exportExcel() { 'module': $('#module').val(), 'proId': objParam.proId, 'id': id, - 'curryDay':time + 'curryDay': time } let url = dataUrl + "backstage/export/exportPcList"; exportExcelUtil(url, '发货详情-批次-' + time, JSON.stringify(params)); @@ -330,7 +330,7 @@ function viewFile(obj) { { "alt": "layer", "pid": 1, - "src": "../../../images/captcha.jpg", + "src": fileUrl + obj.fileUrl + '?token=' + sessionStorage.getItem("gz-token"), } ] } @@ -340,5 +340,10 @@ function viewFile(obj) { // 下载文件 function downLoadFile(obj) { - alert('下载'); + console.log(obj); + let params = { + 'fileId': obj.id, + } + let url = dataUrl + "backstage/export/download"; + downLoadFileUtil(url, obj.fileName, JSON.stringify(params)); } \ No newline at end of file diff --git a/js/demandPlan/child/excess_inventory_list.js b/js/demandPlan/child/excess_inventory_list.js index dd32756..bc35da3 100644 --- a/js/demandPlan/child/excess_inventory_list.js +++ b/js/demandPlan/child/excess_inventory_list.js @@ -189,7 +189,7 @@ function exportExcel() { 'module': $('#module').val(), type: 1 } - let url = dataUrl + "backstage/export/exportFhList"; + let url = dataUrl + "backstage/export/exportWarnExcel"; exportExcelUtil(url, '超库存量', JSON.stringify(params)); } diff --git a/js/demandPlan/child/unplanned_quantity_list.js b/js/demandPlan/child/unplanned_quantity_list.js index 0f12c7f..960b9b5 100644 --- a/js/demandPlan/child/unplanned_quantity_list.js +++ b/js/demandPlan/child/unplanned_quantity_list.js @@ -177,7 +177,7 @@ function exportExcel() { 'module': $('#module').val(), type: 2 } - let url = dataUrl + "backstage/export/exportFhList"; + let url = dataUrl + "backstage/export/exportWarnExcel"; exportExcelUtil(url, '计划外量', JSON.stringify(params)); } diff --git a/js/public.js b/js/public.js index 68f57ee..acafd41 100644 --- a/js/public.js +++ b/js/public.js @@ -1,4 +1,5 @@ -const dataUrl = 'http://127.0.0.1:21995/'; +const dataUrl = 'http://127.0.0.1:21995/'; // 数据请求路径 +const fileUrl = 'http://127.0.0.1:21995/'; // 文件路径 @@ -82,6 +83,32 @@ function exportExcelUtil(url, fileName,params) { xhr.send(params); } + +// 下载文件的公共方法 +function downLoadFileUtil(url, fileName,params) { + let loadingMsg = layer.msg("数据导出中,请稍候...", { icon: 16, scrollbar: false, time: 0, }); + let xhr = new XMLHttpRequest(); + xhr.open("POST", url, true); + xhr.responseType = "blob"; // 转换流 + xhr.setRequestHeader('Content-Type','application/json;charset=UTF-8') + xhr.setRequestHeader("authorization", sessionStorage.getItem("gz-token")); + xhr.onload = function () { + layer.close(loadingMsg); + if (this.status === 200) { + let blob = this.response; + var a = document.createElement("a"); + var url = window.URL.createObjectURL(blob); + a.href = url; + a.download = fileName + ".xlsx"; // 文件名 + } else { + layer.msg("数据发生异常,请稍后重试", { icon: 16, scrollbar: false, time: 2000 }); + } + a.click(); + window.URL.revokeObjectURL(url); + }; + xhr.send(params); +} + // 格式化日对象 const getNowDate = () => { var date = new Date();