//当前节点 入库质检 var layer; var laydate; var form; var table; var page = 1; var limit = 10; var curSampleData = null;// 当前编辑数据 var curCheckItems = null;// 当前数据的检查项信息 $(function () { layui.use(['layer', 'laydate', 'form', 'table'], function () { layer = layui.layer; form = layui.form; table = layui.table; laydate = layui.laydate; laydate.render({ elem: '#start', theme: '#7b8e9f', value: startTime }); laydate.render({ elem: '#end', theme: '#7b8e9f', value: endTime }); laydate.render({ elem: '#sampleTime', theme: '#7b8e9f', format: 'yyyy-MM-dd HH:mm:ss', type: 'datetime' }); // 初始化表单数据 renderTable(); // 监听行工具事件 table.on('tool(tableData)', function (obj) { if (obj.event === 'edit') { //展示数据 showDetail(obj); } }); //监听粮食品种 layui.form.on('select(select_foodVariety)', function (data) { updateFoodVariety(data.value); }); //监听化验结果单填写数据,并给出提示结果 table.on('edit(tableCheckItem)', function (obj) { getResult(obj); }); }); //显示入库流程 showProgress(); // 初始化WebSocket initInoutWS(deptId, bizType, progress, userId); }); // socket信息返回處理 function socketOnMessage(packet) { layer.alert(packet.data); window.parent.sysNotify(packet.data); } /** * 条件查询 */ function flushData() { var index = layer.load(); var param = form.val("form-param"); table.reload('tableData', { url: "../../basic/inout/page-sample-data", where: param }); $("thead tr").css({ "border-bottom": "2px solid #53adce", "background": "#eff4f6" }); layer.close(index); } /** * 渲染表单数据 */ function renderTable() { var param = form.val("form-param"); // 清空数据 $("#tableData").empty(); table.render({ elem: '#tableData', url: '../../basic/inout/page-sample-data', page: true, limit: limit, even: true, method: 'POST', contentType: "application/json;charset=UTF-8", cols: [[{ field: 'checkId', title: '质检单号', style: 'color: #f67d06;font-weight: bold' }, { field: 'plateNum', title: '车船号', width: '15%', style: 'font-weight: bold' }, { field: 'registerTime', title: '登记时间', width: '15%' }, { field: 'sampleUser', title: '扦样人', width: '15%' }, { field: 'sampleTime', title: '扦样时间', width: '15%' }, { field: 'sampleType', title: '扦样类型', width: '10%', templet: function (item) { if (item.sampleType == null) { return "其他"; } if (item.sampleType == '0') { return "人工"; } if (item.sampleType == '1') { return "自动"; } if (item.sampleType == '2') { return "智能随机"; } } }, { field: 'sampleStatus', title: '是否扦样', width: '10%', templet: function (item) { if (item.sampleStatus == null) { return "未扦样"; } if (item.sampleStatus == 'NONE') { return "未扦样"; } if (item.sampleStatus == 'SAMPLE') { return "已扦样"; } } }, { field: '', title: '操作', width: '10%', toolbar: "#barControl" }]], where: param, parseData: function (res) { if ("0000" == res.code) { return { "code": "0", "msg": res.msg, "count": res.data.total, "data": res.data.records } } else { return { "code": "1", "msg": res.msg } } } }); $("thead tr").css({ "border-bottom": "2px solid #53adce", "background": "#eff4f6" }); } // 表单清空 function resetForm() { $("#form-param")[0].reset(); form.render(); }; //根据填写化验数据,给出提醒是否合格 function getResult(obj) { var data = obj.data; //填写的数据值 var newValue = data.value; //标准值 var limit = data.upperLimit; //运算符 var symbol = data.operaSymbol; if (symbol && limit) { if (">=" == symbol) { if (newValue < limit) { data.remarks = "不合格"; } else { data.remarks = "合格"; } } if ("<=" == symbol) { if (newValue > limit) { data.remarks = "不合格"; } else { data.remarks = "合格"; } } if ("==" == symbol) { if (newValue != limit) { data.remarks = "不合格"; } else { data.remarks = "合格"; } } } obj.update(data); //根据化验结果提醒是否合格 updateCheckResultTip(); } //根据选择仓库显示粮食品种 function updateFoodVariety(foodVariety) { if (null == foodVariety || "" == foodVariety) return; form.val("form-detail", { foodVariety: foodVariety }); form.render(); flushCheckItem(foodVariety); } // 根据模式启动开始扦样 function checkExe(type) { checkDto.type = type; var param = JSON.stringify(checkDto); var index = layer.load(); $.ajax({ type: "POST", url: "../../api/check/check-exe", dataType: "json", contentType: "application/json;charset=UTF-8", data: param, success: function (result) { layer.close(index); if (result.code != "0000") { layer.alert(result.msg); } else { layer.msg("操作命令发送成功!"); } }, error: function () { layer.close(index); layer.alert("后台异常,操作命令发送失败!"); } }); }; // 关闭扦样机器 function checkStop() { var param = JSON.stringify(checkDto); var index = layer.load(); $.ajax({ type: "POST", url: "../../api/check/stop", dataType: "json", contentType: "application/json;charset=UTF-8", data: param, success: function (result) { layer.close(index); if (result.code != "0000") { layer.alert(result.msg); } else { layer.msg("操作命令发送成功!"); } }, error: function () { layer.close(index); layer.alert("后台异常,操作命令发送失败!"); } }); }; // 扦样机复位 function checkReset() { var param = JSON.stringify(checkDto); var index = layer.load(); $.ajax({ type: "POST", url: "../../api/check/reset", dataType: "json", contentType: "application/json;charset=UTF-8", data: param, success: function (result) { layer.close(index); if (result.code != "0000") { layer.alert(result.msg); } else { layer.msg("操作命令发送成功!"); } }, error: function () { layer.close(index); layer.alert("后台异常,操作命令发送失败!"); } }); } // 扦样机解除急停 function checkResetStop() { var param = JSON.stringify(checkDto); var index = layer.load(); $.ajax({ type: "POST", url: "../../api/check/reset-stop", dataType: "json", contentType: "application/json;charset=UTF-8", data: param, success: function (result) { layer.close(index); if (result.code != "0000") { layer.alert(result.msg); } else { layer.msg("操作命令发送成功!"); } }, error: function () { layer.close(index); layer.alert("后台异常,操作命令发送失败!"); } }); } /** * 时间等 */ function getTime() { var now = new Date(); var time = now.toLocaleString('chinese', { hour12: false }); return time; } function formatDateTime(date, format) { const o = { 'M+': date.getMonth() + 1, // 月份 'd+': date.getDate(), // 日 'h+': date.getHours() % 12 === 0 ? 12 : date.getHours() % 12, // 小时 'H+': date.getHours(), // 小时 'm+': date.getMinutes(), // 分 's+': date.getSeconds(), // 秒 'q+': Math.floor((date.getMonth() + 3) / 3), // 季度 S: date.getMilliseconds(), // 毫秒 a: date.getHours() < 12 ? '上午' : '下午', // 上午/下午 A: date.getHours() < 12 ? 'AM' : 'PM', // AM/PM }; if (/(y+)/.test(format)) { format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length)); } for (let k in o) { if (new RegExp('(' + k + ')').test(format)) { format = format.replace( RegExp.$1, RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length) ); } } return format; } function showDetail(obj) { curSampleData = null; var nowTime = formatDateTime(new Date(), "yyyy-MM-dd HH:mm:ss"); $("#printTime").html(nowTime); curSampleData = obj.data; if(!curSampleData.sampleTime){ curSampleData.sampleTime = nowTime; } if(!curSampleData.sampleUser){ curSampleData.sampleUser = sampleUser; } // 赋值 form.val("form-detail", curSampleData); form.render(); layer.open({ type: 1, title: "扦样管理信息", area: ['900px', '520px'], shade: 0, content: $('#checkDetail'), btnAlign: 'c', btn: ['保存并打印', '保存提交','关闭取消'], yes: function () { layer.alert("条形码待确定!"); }, btn2: function () { // 更新到页面 var data = form.val("form-detail"); obj.update(data); // 合并更新當前编辑数据 Object.assign(curSampleData, data); submit(); }, btn3: function () { layer.closeAll(); }, closeBtn: 0 }); } // 当前完成 function submit() { if (!curSampleData.sampleUser) { layer.alert("请输入扦样人!!"); return; } if (!curSampleData.sampleTime) { layer.alert("请输入扦样时间!!"); return; } var index = layer.load(); $.ajax({ type: "POST", url: "../../basic/inout/update-sample", dataType: "json", contentType: "application/json;charset=UTF-8", data: JSON.stringify(curSampleData), success: function (result) { if (result.code != "0000") { layer.close(index); notify(result.msg, result.data); } else { layer.closeAll(); curSampleData = null; notify("数据提交成功", result.data); flushData(); } }, error: function () { layer.close(index); layer.alert("提交失败,请重新尝试!"); } }); } //控制流程环节显示 function showProgress() { if (!inoutProgress) { return; } if (inoutProgress.indexOf("REGISTER") == -1) { $("#progress-register").css("display", "none"); } if (inoutProgress.indexOf("CHECK") == -1) { $("#progress-check").css("display", "none"); } if (inoutProgress.indexOf("WEIGHT_FULL") == -1) { $("#progress-fullWeight").css("display", "none"); } if (inoutProgress.indexOf("HANDLE") == -1) { $("#progress-hand").css("display", "none"); } if (inoutProgress.indexOf("WEIGHT_EMPTY") == -1) { $("#progress-emptyWeight").css("display", "none"); } if (inoutProgress.indexOf("CARD_BACK") == -1) { $("#progress-cardBack").css("display", "none"); } } /** * 弹出提醒框 * @param msg 提醒信息 * @param data 数据信息,可能为空 */ function notify(msg, data) { if (data) { //赋值 $("#resultMsg").text(msg); $("#resultUserName").text(data.userName); $("#resultPlateNum").text(data.plateNum); if ("IN" == data.type) { $("#resultType").text("入库-" + INOUT_PROGRESS_MSG(data.progress)); } else { $("#resultType").text("出库-" + INOUT_PROGRESS_MSG(data.progress)); } $("#resultIntelCard").text(data.intelCard); layer.open({ type: 1, offset: ['150px', '200px'], area: '450px;', shade: 0.8, id: 'dialog_notify_info', btn: ['确定'], content: $('#dialog-from-notify'), yes: function (index) { layer.closeAll(); } }); } else { layer.alert(msg, {offset: ['300px', '300px']}); } }