// 粮情批量导出EXCEL function exportBatch() { // 弹出选择框 layer.open({ type: 1, title: '批量导出报表', area: ['730px', '450px'], shade: 0, content: $('#batchExportSelect'), btn: ['全选', '反选', '重选', '执行导出', '取消导出'], yes: function () { var name; $('#batchExportSelect input').each(function () { name = $(this).prop("name"); if (name == "printCheckDate2" || $(this).prop("disabled")) { } else { $(this).prop("checked", true); } }); form.render(); }, btn2: function () { var name; $('#batchExportSelect input').each(function () { name = $(this).prop("name"); if (name == "printCheckDate2" || $(this).prop("disabled")) { // doNothing } else { if ($(this).prop("checked")) { $(this).prop("checked", false); } else { $(this).prop("checked", false); } } }); form.render(); return false; }, btn3: function () { var name; $('#batchExportSelect input').each(function () { name = $(this).prop("name"); if (name == "printCheckDate2" || $(this).prop("disabled")) { // doNothing } else { $(this).prop("checked", false); } }); form.render(); return false; }, btn4: function () { exportBatchTodo(); }, btn5: function () { layer.close(0); }, closeBtn: 0 }); // 默认调用获取数据更新 if (grainData) { $("#printCheckDate2").prop("value", grainData.receiveDate.substr(0, 10)); } else { $("#printCheckDate2").prop("value", dateFtt("yyyy-MM-dd", new Date())); } }; function exportBatchTodo() { var depotIds = ""; $('#batchExportSelect input').each(function () { if ($(this).prop("checked")) { depotIds += $(this).val() + ","; } }); if (depotIds == "") { layer.alert("请选择需要导出的仓库……"); return false; } layer.load(); // 调用后台批量检测 var checkDate = $("#printCheckDate2").val(); var data = { companyId: companyId, deptId: deptId, depotIds: depotIds, checkDate: checkDate }; $.ajax({ type: "POST", url: "../../basic/grain/export-batch", dataType: "json", contentType: "application/json;charset=UTF-8", data: JSON.stringify(data), success: function (result) { layer.closeAll('loading'); if (result.code != "ORDER_SUCCESS") { layer.alert("导出模版失败:" + result.msg); return false; } else { layer.closeAll('loading'); downLoadExcel(result.msg); return true; } }, error: function () { layer.closeAll('loading'); layer.alert("粮情导出EXCEl执行出错,请从新执行"); return false; } }); return true; } /** * 创建一个A标签执行下载 * @param fileName */ function downLoadExcel(fileName) { var url = "../../basic/file/download-temp?companyId=" + companyId + "&fileName=" + fileName; var link = document.createElement('a'); link.style.display = 'none'; link.href = url; document.body.appendChild(link) link.click(); }