var layer = layui.layer; var table; var depotId; var depotData; var listDevice; (function() { layui.use([ 'layer', 'laydate', 'table', 'form' ], function() { table = layui.table; layer = layui.layer; var form = layui.form; var laydate = layui.laydate; // 监听仓库选择 form.on('select(select_depotId)', function(obj) { flushData(); // 更新当前仓库信息 updateDepotInfo(); }); }); // 初始化WebSocket initWS(deptId, bizType,null, userId); }).call(this); // socket信息返回處理 function socketOnMessage(pocket) { if (pocket.orderResp == "MSG_SUCCESS") {// 信息解析成功刷新当前数据 flushData(); } // 调用通知信息 window.parent.sysNotify(pocket.data); //layer.msg(pocket.data); }; // 点击刷新操作 function flushData() { depotId = $("#depotId").val(); if (!depotId) { layer.msg("请先选择仓库!"); return; } $.ajax({ type : "POST", url : "../../basic/temp/list-device-manual", data : JSON.stringify({ depotId : depotId }), dataType : "json", contentType : "application/json;charset=UTF-8", success : function(result) { console.log(result); if (result.code != "0000") { layer.msg(result.msg); } else { listDevice = result.data; renderDeviceInfo(); } }, error : function() { layer.msg("根据条件获取设备列表失败!"); } }); }; function renderDeviceInfo() { table.render({ elem : '#tableDevice', data : listDevice, page : false, id : 'tableDevice', cols : [ [ { type : 'radio' }, { field : 'name', title : '设备名称', align : 'center', sort : true }, { field : 'statusName', title : '设备状态', align : 'center', sort : true }, { field : 'ext1', title : '设定温度(℃)', align : 'center', }, { field : 'ext2', title : '空调模式', align : 'center', templet: '#templeteModel' } ] ] }); }; /** * 更新仓库信息 */ function updateDepotInfo() { $.each(listDepot, function(index, data) { if (data.id == depotId) { renderDepotInfo(data); return; } }); }; // 填写数据 function renderDepotInfo(data) { $("#storeKeeperName").attr("value",data.storeKeeperName); $("#broken").attr("value",data.broken); $("#perImpurity").attr("value",data.perImpurity); $("#bulkWeight").attr("value",data.bulkWeight); $("#foodLocation").attr("value",data.foodLocation); $("#perWet").attr("value",data.perWet); $("#foodLevelName").attr("value",data.foodLevelName); $("#storageReal").attr("value",data.storageReal); $("#storeDate").attr("value",data.storeDate); $("#depotTypeName").attr("value",data.depotTypeName); }; function queryStatus() { depotId = $("#depotId").val() if (!depotId) { layer.msg("请先选择仓库!"); return; } var data = { depotId : depotId, } $.ajax({ type : "POST", url : "../../basic/temp/query-status", data : JSON.stringify(data), dataType : "json", contentType : "application/json;charset=UTF-8", success : function(result) { if ("ORDER_SUCCESS" == result.code) { layer.msg("状态查询发送成功,请请等待执行结果……"); } else { layer.msg("执行失败,信息:" + result.msg); } }, error : function() { layer.msg("温控执行失败,后台出现错误!"); } }); }; // 空调控制 function tempControl() { depotId = $("#depotId").val() if (!depotId) { layer.msg("请先选择仓库!"); return; } var checkStatus = table.checkStatus('tableDevice'); var selectDevice = checkStatus.data; if (!selectDevice || selectDevice.length == 0) { layer.msg("请先选择需要操作的空调!"); return; } // 弹出选择框 layer.open({ type : 1, title : '空调操作配置', area : [ '400px', '300px' ], shade : 0, content : $('#dialogTempControl'), btn : [ '确定执行', '取消操作' ], yes : function() { tempControlTodo(selectDevice[0]); layer.msg("开始执行……"); layer.closeAll(); }, btn2 : function() { layer.closeAll(); }, closeBtn : 0 }); }; // 开始操作空调 function tempControlTodo(exeDevice) { var targetStatus = $('input[name="targetStatus"]:checked').val(); var targetTemp = $("#targetTemp").val(); var targetModel = $('input[name="targetModel"]:checked').val(); console.log(targetStatus); var data = { depotId : depotId, targetStatus : targetStatus, targetTemp : targetTemp, targetModel : targetModel, exeDevice : exeDevice } $.ajax({ type : "POST", url : "../../basic/temp/control", data : JSON.stringify(data), dataType : "json", contentType : "application/json;charset=UTF-8", success : function(result) { if ("ORDER_SUCCESS" == result.code) { layer.msg("温控命令发送成功,请请等待执行结果……"); } else { layer.msg("执行失败,信息:" + result.msg); } }, error : function() { layer.msg("温控执行失败,后台出现错误!"); } }); };