| var layer; | 
| var form; | 
| var deviceList;// 当前仓库的所有设备列表 | 
| var depotId; | 
| var deviceType = DeviceType.TYPE_01;// 被选中的设备类型,默认是通风窗 | 
| var viewTargetStatus;// 目标状态,根据设备类型和当前值调用动效 | 
| var domSelectDevice;// 被选中的设备dom对象 | 
| var token; | 
| $(function () { | 
|     layui.use(['layer', 'form'], function () { | 
|         form = layui.form; | 
|         layer = layui.layer; | 
|         form.render(); | 
|         // 监听仓库选择 | 
|         form.on('select(select_depotId)', function () { | 
|             query(true); | 
|         }); | 
|   | 
|         //弹出密码验证框 | 
|         layer.open({ | 
|             type: 1, | 
|             title: '门禁权限码', | 
|             area: ['400px', '220px'], | 
|             content: $('#checkPwd'), | 
|             closeBtn: 0 | 
|         }); | 
|     }); | 
|   | 
|     // 添加切换动作 | 
|     $(".js-tf-btn").click( | 
|         function () { | 
|             $(this).addClass("active").siblings(".js-tf-btn").removeClass( | 
|                 "active"); | 
|         }); | 
|   | 
|     $(".js-xg115-arrow").click(function () { | 
|         $(this).siblings(".xg115-btnhide").toggle() | 
|         $(this).toggleClass("active"); | 
|     }); | 
|   | 
|     // 初始化ws | 
|     initWS(deptId, bizType, null, userId); | 
| }); | 
|   | 
| // socket信息返回處理 | 
| function socketOnMessage(pocket) { | 
|     window.parent.sysNotify(pocket.data); | 
|     if (pocket.orderResp == "MSG_SUCCESS") { | 
|         addLog(pocket.data); | 
|         query(false); | 
|         // 调整动作为结束 | 
|         updateAnimate(deviceType, viewTargetStatus, true); | 
|     } else if (pocket.orderResp == "ORDER_INPROGRESS") | 
|         addLog(pocket.data); | 
|     else { | 
|         addRedLog(pocket.data); | 
|     } | 
| }; | 
|   | 
| /** 视频查看直接跳转到视频概览页面**/ | 
| function showVideo() { | 
|     window.parent.openTab("./basic/security/aerial-video?t=1","视频鸟瞰","aerial-video"); | 
| }; | 
|   | 
| function closeAll() { | 
|     layer.msg("终端不支持当前功能……"); | 
| }; | 
|   | 
| // 状态查询 | 
| function queryStatus() { | 
|     depotId = $("#depotId").val(); | 
|     if (!depotId) { | 
|         layer.msg("请先选择仓库!"); | 
|         return; | 
|     } | 
|     layer.msg("状态查询……"); | 
|     $.ajax({ | 
|         type: "POST", | 
|         url: "../../basic/security/query-status", | 
|         dataType: "json", | 
|         contentType: "application/json;charset=UTF-8", | 
|         data: JSON.stringify({ | 
|             depotId: depotId | 
|         }), | 
|         success: function (result) { | 
|             if (result.msg) { | 
|                 layer.msg(result.msg); | 
|             } | 
|         }, | 
|         error: function (result) { | 
|             layer.msg("获取数据失败,请重新尝试!"); | 
|         } | 
|     }); | 
| }; | 
|   | 
|   | 
| //直接调动query不更新粮库信息 | 
| function query() { | 
|     query(false); | 
| } | 
|   | 
| // 执行查询 | 
| function query(isUpdateGrain) { | 
|     depotId = $("#depotId").val(); | 
|     if (!depotId) { | 
|         layer.msg("请先选择仓库!"); | 
|         return; | 
|     } | 
|     $.ajax({ | 
|         type: "POST", | 
|         url: "../../basic/security/list-device-manual", | 
|         dataType: "json", | 
|         contentType: "application/json;charset=UTF-8", | 
|         data: JSON.stringify({ | 
|             depotId: depotId | 
|         }), | 
|         success: function (result) { | 
|             if (result.code != "0000") { | 
|                 layer.msg(result.msg); | 
|                 return; | 
|             } | 
|             deviceList = result.data; | 
|             //console.log(deviceList); | 
|             // 根据设备渲染 | 
|             renderDevice(deviceList, depotId); | 
|             // 获取当前仓库的粮情信息 | 
|             if (isUpdateGrain) | 
|                 updateGrainInfo(); | 
|   | 
|         }, | 
|         error: function (result) { | 
|             layer.msg("获取数据失败,请重新尝试!"); | 
|         } | 
|     }); | 
| }; | 
|   | 
| // 获取当前仓库的最新粮情数据信息 | 
| function updateGrainInfo() { | 
|     $.ajax({ | 
|         type: "POST", | 
|         url: "../../basic/common/grain-data", | 
|         dataType: "json", | 
|         contentType: "application/json;charset=UTF-8", | 
|         data: JSON.stringify({ | 
|             depotId: depotId | 
|         }), | 
|         success: function (result) { | 
|             if (result.code != "0000") { | 
|                 addRedLog(result.msg) | 
|                 return; | 
|             } | 
|             var grainData = result.data; | 
|             // 更新信息 | 
|             $("#tempIn").text(grainData.tempIn); | 
|             $("#humidityIn").text(grainData.humidityIn); | 
|             $("#tempAve").text((grainData.tempAve).toFixed(1)); | 
|             $("#tempOut").text(grainData.tempOut); | 
|             $("#updateTime").text(grainData.receiveDate); | 
|         }, | 
|         error: function (result) { | 
|             layer.msg("当前仓库的粮情数据信息获取失败!"); | 
|         } | 
|     }); | 
| }; | 
|   | 
| // 按钮事件切换正反面 | 
| function toCut(target) { | 
|     // 首先清空div中的内容 | 
|     $("#device_view").empty(); | 
|     // 获取当前仓库效果图 | 
|     viewAB = target; | 
|     cutImg(depotId, viewAB); | 
|     // 根据设备列表添加原型信息 | 
|     addDevice(deviceList, viewAB); | 
| }; | 
|   | 
| // 添加操作日志 | 
| function addLog(htmlStr) { | 
|     var info = $("#areationInfo").html(); | 
|     $("#areationInfo").html(htmlStr + "</br>" + info); | 
| }; | 
|   | 
| function addRedLog(htmlStr) { | 
|     var info = $("#areationInfo").html(); | 
|     $("#areationInfo").html( | 
|         "<span class='font-red'>" + htmlStr + "</span></br>" + info); | 
| }; | 
|   | 
| /** | 
|  * 弹出操作框 | 
|  */ | 
| function showControl(id) { | 
|     domSelectDevice = $("#" + id); | 
|     var curDepotId = domSelectDevice.attr("depotid"); | 
|     // 如果点击的设备不是选择仓库的,不执行 | 
|     if (curDepotId != depotId) { | 
|         addRedLog("当前所选设备:" + domSelectDevice.attr("name") + "【非所选仓库】"); | 
|         return; | 
|     } else { | 
|         addLog("当前所选设备:" + domSelectDevice.attr("name")); | 
|     } | 
|   | 
|     // 更新所选择的设备类型 | 
|     deviceType = domSelectDevice.attr("type"); | 
|   | 
|     // 弹出操作框。 | 
|     layer.open({ | 
|         type: 1, | 
|         title: '设备操作-' + domSelectDevice.attr("name"), | 
|         area: ['480px', '150px'], | 
|         shade: 0, | 
|         content: $('#areationControl'), | 
|         btn: 0, | 
|         closeBtn: 2 | 
|     }); | 
| }; | 
|   | 
| // 根据操作目标状态和选择的设备进行执行-目标状态 | 
| function toExecute(targetStatus) { | 
|     var batchTag = false; | 
|     if ("W_OPEN_ALL" == targetStatus) { | 
|         batchTag = true; | 
|         targetStatus = DeviceStatus.OPEN; | 
|     } | 
|     if ("W_CLOSE_ALL" == targetStatus) { | 
|         batchTag = true; | 
|         targetStatus = DeviceStatus.CLOSE; | 
|     } | 
|   | 
|     // 根据设备类型进行调整,针对风机类 | 
|     if (targetStatus == DeviceStatus.OPEN) { | 
|         if (deviceType == DeviceType.TYPE_02) | 
|             targetStatus = DeviceStatus.W_OPEN; | 
|         if (deviceType == DeviceType.TYPE_0C) | 
|             targetStatus = DeviceStatus.W_OPEN; | 
|     } | 
|   | 
|     if (targetStatus == DeviceStatus.CLOSE) { | 
|         if (deviceType == DeviceType.TYPE_02) | 
|             targetStatus = DeviceStatus.W_CLOSE; | 
|         if (deviceType == DeviceType.TYPE_0C) | 
|             targetStatus = DeviceStatus.W_CLOSE; | 
|     } | 
|   | 
|     viewTargetStatus = targetStatus; | 
|   | 
|     var data = { | 
|         depotId: depotId, | 
|         token: token, | 
|         deviceList: [] | 
|     } | 
|   | 
|     //批量设备操作,只处理相同的设备类型 | 
|     if (batchTag) { | 
|         // 获取设备信息 | 
|         var tips = $(".device"); | 
|         $.each(tips, function (index, item) { | 
|             if (deviceType == item.getAttribute("type") | 
|                 && depotId == item.getAttribute("depotid")) { | 
|                 data.deviceList.push({ | 
|                     id: item.id, | 
|                     depotId: item.getAttribute("depotid"), | 
|                     passCode: item.getAttribute("passcode"), | 
|                     name: item.getAttribute("name"), | 
|                     serId: item.getAttribute("serid"), | 
|                     link: item.getAttribute("link"), | 
|                     type: item.getAttribute("type"), | 
|                     targetStatus: targetStatus | 
|                 }); | 
|             } | 
|         }); | 
|     } else { | 
|         data.deviceList.push({ | 
|             id: domSelectDevice.id, | 
|             depotId: domSelectDevice.attr("depotid"), | 
|             passCode: domSelectDevice.attr("passcode"), | 
|             name: domSelectDevice.attr("name"), | 
|             serId: domSelectDevice.attr("serid"), | 
|             link: domSelectDevice.attr("link"), | 
|             type: domSelectDevice.attr("type"), | 
|             targetStatus: targetStatus | 
|         }); | 
|     } | 
|   | 
|     //console.log("toExecute--deviceList="+JSON.stringify(data)); | 
|   | 
|     // 开始调用后台执行 | 
|     layer.load(1); | 
|     $.ajax({ | 
|         type: 'POST', | 
|         url: "../../basic/security/control-device", | 
|         dataType: 'JSON', | 
|         contentType: "application/json;charset=UTF-8", | 
|         data: JSON.stringify(data), | 
|         success: function (result) { | 
|             layer.closeAll(); | 
|             if (result.code != "ORDER_SUCCESS") { | 
|                 layer.msg("执行失败:" + result.msg); | 
|             } else { | 
|                 layer.msg("操作指令发送成功,待终端响应……"); | 
|                 // 开始调用动画 TODO | 
|                 updateAnimate(deviceType, targetStatus, false); | 
|             } | 
|         }, | 
|         error: function (result) { | 
|             layer.closeAll(); | 
|             layer.msg("操作发生异常,暂时无法解决!!"); | 
|         } | 
|     }); | 
| }; | 
|   | 
| function checkPassword() { | 
|     var pwd = $("#password").val(); | 
|     var data = { | 
|         "token": pwd | 
|     }; | 
|     $.ajax({ | 
|         type: 'POST', | 
|         url: "../../basic/security/check-door-token", | 
|         dataType: 'JSON', | 
|         contentType: "application/json;charset=UTF-8", | 
|         data: JSON.stringify(data), | 
|         success: function (result) { | 
|             if (result.code == "0000") { | 
|                 token = pwd; | 
|                 layer.closeAll(); | 
|             } else { | 
|                 layer.msg(result.msg); | 
|             } | 
|         }, | 
|         error: function (result) { | 
|             layer.msg("服务异常,请重试!"); | 
|         } | 
|     }); | 
| } |