var layer; var depotId;// 当前仓库id var curData;// 当前仓粮情数据 var mapData;// 根据日期查询的每个仓库一条数据 var form; var table; var listData;// 默认页面中的粮情列表 var gasConf;// 气体采集配置信息,包括开始采集点和截至采集点。 $(function () { layui.use(['layer', 'laydate', 'form', 'table'], function () { form = layui.form; layer = layui.layer; var laydate = layui.laydate; table = layui.table; // 日期 laydate.render({ elem: '#checkDateMore', theme: '#7b8e9f' }); laydate.render({ elem: '#printCheckDate', theme: '#7b8e9f' }); // 监听仓库选择 form.on('select(select_depotId)', function (obj) { flushData(null); //获取当前仓库效果图 // cutImg(obj.value); //根据仓库编码切换采集点位置 // cutPoint(obj.value); }); // 监听选择批次 form.on('select(select_batchId)', function (obj) { var value = obj.value; if (value == "0") {// 表示弹出更多批次 showMore(); } else { flushByBatchId(value); } }); flushData(null); }); }); /** * 切换采集点 * @param depotId */ function cutPoint(depotId) { //首先除去已有效果 $(".qt-pic-icon-active").removeClass("qt-pic-icon-active"); $("#list-point-right").css("display","none"); $("#list-point-left").css("display","block"); } //根据采集进度信息渲染采集点效果 function renderCheckPoint(checkProgress) { if (depotId != checkProgress.depotId) { $("#progress-info").text(""); return; } $("#progress-info").text(checkProgress.msg); //首先除去已有效果 $(".qt-pic-icon-active").removeClass("qt-pic-icon-active"); var id = "#point" + checkProgress.checkPoint+"-left"; $(id).addClass("qt-pic-icon-active"); id = "#point" + checkProgress.checkPoint+"-right"; $(id).addClass("qt-pic-icon-active"); }; // 单仓打印 function printSingle() { layer.msg("当前协议未对接!"); return; layer.msg("开始生成打印模版……"); var html = builderModel(curData,dept); layer.msg("开始调用打印机程序预览……"); previewA4(html); }; // 批量打印 function printBatch() { layer.msg("当前协议未对接!"); return; // 首先去除之前的选择 var name; $('#batchPrintSelect input').each(function () { name = $(this).prop("name"); if (name == "printCheckDate") {// 跳过 return true; } $(this).prop("disabled", false); $(this).prop("checked", false); }); form.render(); // 弹出选择框 layer.open({ type: 1, title: '批量打印(红色表示没有检测记录,默认为当天)', area: ['690px', '450px'], shade: 0, content: $('#batchPrintSelect'), btn: ['全选', '反选', '重选', '打印预览', '取消打印'], yes: function () { var disabled, name; $('#batchPrintSelect input').each(function () { disabled = $(this).prop("disabled"); name = $(this).prop("name"); if (name == "printCheckDate" || disabled) { } else { $(this).prop("checked", true); } }); form.render(); }, btn2: function () { var disabled, name; $('#batchPrintSelect input').each(function () { disabled = $(this).prop("disabled"); name = $(this).prop("name"); if (name == "printCheckDate" || disabled) { // 不做处理 } else { if ($(this).prop("checked")) { $(this).prop("checked", false); } else { $(this).prop("checked", true); } } }); form.render(); return false; }, btn3: function () { var disabled, name; $('#batchPrintSelect input').each(function () { disabled = $(this).prop("disabled"); name = $(this).prop("name"); if (name == "printCheckDate" || disabled) { // 不做处理 } else { $(this).prop("checked", false); } }); form.render(); return false; }, btn4: function () { printBatchTodo(); }, btn5: function () { layer.close(0); }, closeBtn: 0 }); // 默认调用获取数据更新 $("#printCheckDate").prop("value", dateFtt("yyyy-MM-dd", new Date())); getPrintBatchDepot(); }; // 获取批量打印的信息 function getPrintBatchDepot() { layer.msg("验证粮情检测记录……"); var checkDate = $("#printCheckDate").val(); $.ajax({ type: "POST", url: "../../basic/pest/query-checkDate-map", dataType: "json", contentType: "application/json;charset=UTF-8", data: JSON.stringify({ checkDate: checkDate }), success: function (result) { if (result.code != "0000") { layer.msg(result.msg); // 设置所有仓库不可选 var name; $('#batchPrintSelect input').each(function () { name = $(this).prop("name"); if (name != "printCheckDate") {// 跳过 $(this).prop("disabled", true); } }); form.render(); } else { mapData = result.data; // 动态调整仓库是否可以选择 var name, value; $('#batchPrintSelect input').each(function () { name = $(this).prop("name"); value = $(this).val(); if (name != "printCheckDate") {// 跳过 if (mapData[value]) { $(this).prop("disabled", false); } else { $(this).prop("disabled", true); } } }); form.render(); } }, error: function () { layer.msg("批量打印获取粮情信息失败!"); } }); }; // 根据查询的数据批量打印预览 function printBatchTodo() { layer.msg("开始批量生成打印模版……"); var strHtml; var value; var checked; var printData; // 将仓库数据列表转换为MAP var mapDepot = {}; $.each(listDepot, function (index, data) { mapDepot[data.id] = data; }); var LODOP = getLodop(); LODOP.PRINT_INIT("气体检测报表");// 初始化在循环外 LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "A4"); $('#batchPrintSelect input').each(function () { if ($(this).prop("name") == "printCheckDate") {// 跳过 return true; } checked = $(this).prop("checked"); if (checked) { value = $(this).val(); LODOP.NewPage(); printData = mapData[value]; if (!printData) {// 如果没有粮情数据跳过执行下一个 return true; } printData.depotData = mapDepot[value]; strHtml = builderModel(printData,dept); LODOP.ADD_PRINT_HTM(30, 40, "180mm", "100%", strHtml); } }); layer.msg("开始调用打印程序预览……"); LODOP.PREVIEW(); }; // 点击刷新操作 function flushData(checkDate) { depotId = $("#depotId").val(); if (!depotId) { layer.msg("请先选择仓库!"); return; } cleanData(); listData = [{"batchId":"202410230838","checkNum":5,"checkUser":"管理员","companyId":"1000","depotData":{"bulkWeight":600,"companyId":"1000","depotStatus":"3","depotStatusName":"封仓","depotType":"01","depotTypeName":"平房仓","deptId":"1000001001","foodLevel":"03","foodLevelName":"三等","foodLocation":"江西省","foodType":"123","foodTypeName":"县级地方储备粮","foodVariety":"1131","foodYear":"2024","id":"LB03","name":"L1-1C仓","orderNum":3,"storageMax":5000000,"storageReal":1825000,"storeDate":1724342400000,"storeKeeperLevel":"高级保管员","storeKeeperPhone":"####","storeType":"1"},"depotId":"LB03","listPoint":[{"passCode":1,"pestNum":0,"pestType":"","receiveDate":"2024-10-23 08:38"},{"passCode":2,"pestNum":0,"pestType":"","receiveDate":"2024-10-23 08:38"},{"passCode":3,"pestNum":0,"pestType":"","receiveDate":"2024-10-23 08:38"},{"passCode":4,"pestNum":0,"pestType":"","receiveDate":"2024-10-23 08:38"},{"passCode":5,"pestNum":0,"pestType":"","receiveDate":"2024-10-23 08:38"}],"pestEnd":5,"pestMax":2,"pestStart":1,"points":"1,0;2,0;3,0;4,0;5,2;","receiveDate":"2024-10-23 08:38","remark":"基本无虫粮","sysDate":1747965415141},{"batchId":"202410100836","checkNum":5,"checkUser":"地磅室","companyId":"1000","depotData":{"$ref":"$[0][0].depotData"},"depotId":"LB03","listPoint":[{"passCode":1,"pestNum":0,"pestType":"","receiveDate":"2024-10-23 09:38"},{"passCode":2,"pestNum":0,"pestType":"","receiveDate":"2024-10-23 09:38"},{"passCode":3,"pestNum":0,"pestType":"","receiveDate":"2024-10-23 09:38"},{"passCode":4,"pestNum":0,"pestType":"","receiveDate":"2024-10-23 09:38"},{"passCode":5,"pestNum":0,"pestType":"","receiveDate":"2024-10-23 09:38"}],"pestEnd":5,"pestMax":0,"pestStart":1,"points":"1,0;2,0;3,0;4,0;5,0;","receiveDate":"2024-10-23 09:38","remark":"基本无虫粮","sysDate":1747965415141},{"batchId":"202410081616","checkNum":5,"checkUser":"地磅室","companyId":"1000","depotData":{"$ref":"$[0][0].depotData"},"depotId":"LB03","listPoint":[{"passCode":1,"pestNum":0,"pestType":"","receiveDate":"2024-10-23 11:38"},{"passCode":2,"pestNum":0,"pestType":"","receiveDate":"2024-10-23 11:38"},{"passCode":3,"pestNum":0,"pestType":"","receiveDate":"2024-10-23 11:38"},{"passCode":4,"pestNum":0,"pestType":"","receiveDate":"2024-10-23 11:38"},{"passCode":5,"pestNum":0,"pestType":"","receiveDate":"2024-10-23 11:38"}],"pestEnd":5,"pestMax":5,"pestStart":1,"points":"1,4;2,2;3,1;4,2;5,5;","receiveDate":"2024-10-23 11:38","remark":"一般虫粮","sysDate":1747965415141}]; if(!listData){ return; } curData = listData[0]; // 渲染数据 renderDataInfo(); // 在批次选择中添加下拉数据 resetSelectBatchId(); // 调用全部关闭 layer.closeAll(); layer.msg("更新成功……"); // var data = { // depotId: depotId, // checkDate: checkDate // }; // $.ajax({ // type: "POST", // url: "../../basic/pest/list-data", // dataType: "json", // contentType: "application/json;charset=UTF-8", // data: JSON.stringify(data), // success: function (result) { // if (result.code != "0000") { // layer.msg(result.msg); // } // listData = result.data; // if(!listData){ // return; // } // curData = listData[0]; // // // 渲染数据 // renderDataInfo(); // // // 在批次选择中添加下拉数据 // resetSelectBatchId(); // // // 调用全部关闭 // layer.closeAll(); // layer.msg("更新成功……"); // }, // error: function () { // layer.msg("根据当前条件获取粮情数据渲染图标失败!!"); // } // }); }; //清空数据 function cleanData() { //清空检测时间批次值 $("#batchId").empty(); form.render(); $("#checkNum").text("0"); $("#remark").text("无虫"); $("#tableInfo").html(""); } //切换仓库图片 function cutImg(depotId) { //默认图片 var gasImg = gasImgMap[depotId]; var imgPath = "../../basic/file/getImg?filePath=" + gasImg.fileImg; $("#depot_img").attr("src", imgPath); } //渲染表格,同时渲染排行 function renderTableInfo() { var listPoint = curData.listPoint; var v1 = curData.pestMax, v2 = 0.0, v3 = 0.0, v4 = 0.0; var tableHtml = ""; tableHtml += ""; tableHtml += ""; // 动态创建表格 $.each(listPoint, function (index, item) { tableHtml += ""; tableHtml += ""; tableHtml += ""; //渲染排行 if (index == 0) { $("#orderValue1").text(item.pestNum); $("#orderName1").text("采集位" + item.passCode); } if (index == 1) { $("#orderValue2").text(item.pestNum); $("#orderName2").text("采集位" + item.passCode); } if (index == 2) { $("#orderValue3").text(item.pestNum); $("#orderName3").text("采集位" + item.passCode); } if (index == 3) { $("#orderValue4").text(item.pestNum); $("#orderName4").text("采集位" + item.passCode); } }); tableHtml += "
检测位虫害头数虫害类型
" + item.passCode + "" + item.pestNum + "" + item.pestType + "
"; $("#tableInfo").html(tableHtml); }; // 回填检测信息 function renderDataInfo() { $("#checkNum").text(curData.checkNum); $("#remark").text(curData.remark); //渲染表格和排行 renderTableInfo(); }; // 根据批次更新的值调整 function flushByBatchId(batchId) { var temp; $.each(listData, function (index, item) { if (item.batchId == batchId) { temp = item; return false; } }); if (temp) { curData = temp; renderDataInfo(); layer.msg("更新成功……"); } }; // 重置批次下拉框 function resetSelectBatchId() { // 首先清空原来的值 $("#batchId").empty(); // 未下拉框赋值 $.each(listData, function (index, item) { $('#batchId').append(new Option(item.receiveDate, item.batchId));// 下拉菜单里添加元素 }); $('#batchId').append(new Option("选择时间……", "0")); form.render(); }; // 更多批次选择 function showMore() { layer.open({ type: 1, title: '请选择时间', area: ['380px', '250px'], shade: 0, content: $('#dialogMoreSelect'), btn: ['确认选择', '取消'], yes: function () { var checkDateMore = $("#checkDateMore").val(); if (checkDateMore) { flushData(checkDateMore); } else { layer.msg("请先确认时间!"); } }, btn2: function () { layer.close(0); }, closeBtn: 0 }); }; // 气体采集的入口方法,type=1,表示整仓采集;type=2,表示选择采集,type=3表示多仓采集 function checkStart(type) { layer.msg("当前协议未对接!"); return; if (3 == type) { checkBatch(); return; } // 整仓采集和选择采集需要获取到气体的配置信息后进行操作 depotId = $("#depotId").val(); if (!depotId) { layer.msg("请先选择仓库!"); return; } if (gasConf && gasConf.depotId == depotId) { if (1 == type) { check(); } if (2 == type) { checkSelect(); } return; } layer.msg("获取当前仓库的配置信息……"); var data = { depotId: depotId }; $.ajax({ type: "POST", url: "../../basic/pest/gas-conf", dataType: "json", contentType: "application/json;charset=UTF-8", data: JSON.stringify(data), success: function (result) { if (result.code != "0000") { layer.msg(result.msg); return; } gasConf = result.data; if (1 == type) { check(); return; } if (2 == type) { checkSelect(); return; } }, error: function () { layer.msg("获取当前仓库配置信息失败!"); } }); }; // 单个粮情检测 function check() { layer.msg("开始气体检测……"); var data = { depotId: depotId }; $.ajax({ type: "POST", url: "../../basic/pest/check-single", dataType: "json", contentType: "application/json;charset=UTF-8", data: JSON.stringify(data), success: function (result) { if (result.code != "ORDER_SUCCESS") { if (result.msg) { layer.msg(result.msg); } else { layer.msg("执行出现异常,请重试或联系管理员"); } } else { layer.msg("命令已经成功发送,待终端响应……"); } }, error: function () { layer.msg("气体检测出现异常,执行失败!"); } }); }; // 选择采集点采集 function checkSelect() { // 弹出选择框,选择信息 var gasStart = gasConf.gasStart, gasEnd = gasConf.gasEnd; var strHtml = ""; for (var i = gasStart; i <= gasEnd; i++) { if (i < 10) { strHtml += ""; strHtml += "
位置0" + i + "
"; } else { strHtml += ""; strHtml += "
位置" + i + "
"; } } $("#div_point_select").html(strHtml); form.render(); // 开始选择 layer.open({ type: 1, title: '选择采集点(全选请使用整仓采集)', area: ['690px', '450px'], shade: 0, content: $('#pointSelect'), btn: ['全选', '反选', '重选', '确定检测', '取消检测'], yes: function () { $('#pointSelect input').each(function () { $(this).prop("checked", true); }); form.render(); }, btn2: function () { $('#pointSelect input').each(function () { if ($(this).prop("checked")) { $(this).prop("checked", false); } else { $(this).prop("checked", true); } }); form.render(); return false; }, btn3: function () { $('#pointSelect input').each(function () { $(this).prop("checked", false); }); form.render(); return false; }, btn4: function () { return checkSelectStep2(); }, btn5: function () { layer.close(0); }, closeBtn: 1 }); }; // 执行采集点检测 function checkSelectStep2() { // 获取选择的采集点 var checkPoints = ""; $('#pointSelect input').each(function () { if ($(this).prop("checked")) { checkPoints += $(this).val() + ","; } }); if (checkPoints == "") { layer.msg("请选择需要检测的采集点"); return false; } layer.msg("开始气体检测……"); var data = { depotId: depotId, checkPoints: checkPoints }; $.ajax({ type: "POST", url: "../../basic/pest/check-select", dataType: "json", contentType: "application/json;charset=UTF-8", data: JSON.stringify(data), success: function (result) { if (result.code != "ORDER_SUCCESS") { if (result.msg) { layer.msg(result.msg); } else { layer.msg("执行出现异常,请重试或联系管理员"); } return false; } else { layer.msg("命令已经成功发送,待终端响应……"); return true; } }, error: function () { layer.msg("气体检测出现异常,执行失败!"); return false; } }); return true; }; // 批量粮情采集 function checkBatch() { // 首先去除之前的选择 $('#batchCheckSelect input').each(function () { $(this).prop("checked", false); }); form.render(); // 弹出选择框 layer.open({ type: 1, title: '批量采集选择', area: ['690px', '450px'], shade: 0, content: $('#batchCheckSelect'), btn: ['全选', '反选', '重选', '执行采集', '取消采集'], yes: function () { $('#batchCheckSelect input').each(function () { $(this).prop("checked", true); }); form.render(); }, btn2: function () { $('#batchCheckSelect input').each(function () { if ($(this).prop("checked")) { $(this).prop("checked", false); } else { $(this).prop("checked", true); } }); form.render(); return false; }, btn3: function () { $('#batchCheckSelect input').each(function () { $(this).prop("checked", false); }); form.render(); return false; }, btn4: function () { return checkBatchStep2(); }, btn5: function () { layer.close(0); }, closeBtn: 0 }); }; /** * 开始执行批量检测 */ function checkBatchStep2() { var depotIds = ""; $('#batchCheckSelect input').each(function () { if ($(this).prop("checked")) { depotIds += $(this).val() + ","; } }); if (depotIds == "") { layer.msg("请先选择需要检测的仓库……"); return false; } layer.msg("开始执行批量检测……"); // 调用后台批量检测 var data = { depotIds: depotIds }; $.ajax({ type: "POST", url: "../../basic/pest/check-batch", dataType: "json", contentType: "application/json;charset=UTF-8", data: JSON.stringify(data), success: function (result) { if (result.code != "ORDER_SUCCESS") { if (result.msg) { layer.msg(result.msg); } else { layer.msg("执行出现异常,请重试或联系管理员"); } return false; } else { layer.msg("命令已经成功发送,待终端响应……"); return true; } }, error: function () { layer.msg("检测出现异常,执行失败!"); return false; } }); return true; }; function gasChart() { layer.msg("当前协议未对接!"); return; layer.msg("功能暂未开放……"); };