| var layer; | 
| var form; | 
| var table; | 
| var deviceList;//当前仓库的所有设备列表 | 
| var depotId; | 
| var tableHeight= 550; | 
| var deviceType = DeviceType.TYPE_01;//被选中的设备类型,默认是通风窗 | 
| var viewTargetStatus; | 
|   | 
| $(function() { | 
|     layui.use([ 'layer', 'table', 'form' ], function() { | 
|         table = layui.table; | 
|         form = layui.form; | 
|         layer = layui.layer; | 
|   | 
|         form.render(); | 
|   | 
|         //监听仓库选择 | 
|         form.on('select(select_depotId)', function() { | 
|             query(); | 
|             //调整已经勾选的设备为取消 | 
|             clearSelectDevice(); | 
|         }); | 
|   | 
|         //监听层选择 | 
|         form.on('radio(check_deviceType)', function(obj) { | 
|             var value = obj.value; | 
|             if(1== value) value ="01"; | 
|             if(2== value) value ="02"; | 
|             if(3==value)  value ="03"; | 
|             deviceType = value; | 
|              | 
|             //调整已经勾选的设备为取消 | 
|             clearSelectDevice(); | 
|         }); | 
|     }); | 
|      | 
|     //如果是管理员登陆支持更改设备位置 | 
|     if(loginUser.administrator){ | 
|         $("#btn-update-drag").removeClass("layui-btn-disabled"); | 
|         $("#btn-save-pos").removeClass("layui-btn-disabled"); | 
|     } | 
|   | 
|     // 根据页面自动计算余下款低-选择框的高度 | 
|     var bodyHeight = window.innerHeight; | 
|     var headerHeight = $("#header-condition").outerHeight(); | 
|     var mainHeight = bodyHeight - headerHeight - 90; | 
|   | 
|     // 初始化ws | 
|     initWS(deptId, bizType,null, userId); | 
| }); | 
|   | 
|   | 
| //socket信息返回處理 | 
| function socketOnMessage(pocket) { | 
|     if (pocket.orderResp == "MSG_SUCCESS") { | 
|         query(); | 
|         //调整已经勾选的设备为取消 | 
|         clearSelectDevice(); | 
|         //调整动作为结束 | 
|         updateAnimate(deviceType,viewTargetStatus,true); | 
|     } | 
|     window.parent.sysNotify(pocket.data); | 
| }; | 
|   | 
| function showVideo(){ | 
|     layer.msg("该功能暂未配置……"); | 
| }; | 
|   | 
| function closeAll(){ | 
|     layer.msg("该功能暂未配置……"); | 
| }; | 
|   | 
| //状态查询 | 
| function queryStatus(){ | 
|     depotId = $("#depotId").val(); | 
|     if(!depotId){ | 
|         layer.msg("请先选择仓库!"); | 
|         return; | 
|     } | 
|     //把当前页面的设备传递到后台 | 
|     var data = { | 
|         depotId : depotId, | 
|         deviceList : [] | 
|     }; | 
|     var tips = $(".device"); | 
|     $.each(tips, function(index, item) { | 
|         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"), | 
|             companyId : companyId | 
|         }); | 
|     }); | 
|   | 
|     $.ajax({ | 
|         type : "POST", | 
|         url : "../../basic/verb/query-status", | 
|         dataType : "json", | 
|         contentType : "application/json;charset=UTF-8", | 
|         data : JSON.stringify(data), | 
|         success : function(result) { | 
|             layer.msg(result.msg); | 
|         }, | 
|         error : function(result) { | 
|             layer.msg("获取数据失败,请重新尝试!"); | 
|         } | 
|     }); | 
| }; | 
|   | 
| // 执行查询 | 
| function query() { | 
|     depotId = $("#depotId").val(); | 
|     if(!depotId){ | 
|         layer.msg("请先选择仓库!"); | 
|         return; | 
|     } | 
|     $.ajax({ | 
|         type : "POST", | 
|         url : "../../basic/verb/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; | 
|   | 
|             //根据设备渲染 | 
|             renderDevice(deviceList,depotId); | 
|         }, | 
|         error : function(result) { | 
|             layer.msg("获取数据失败,请重新尝试!"); | 
|         } | 
|     }); | 
| }; | 
|   | 
| //按钮事件切换正反面 | 
| function toCut(target){ | 
|     renderDevice2(deviceList,depotId,target); | 
| }; | 
|   | 
| renderDevice2 = function(deviceList,depotId,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 toExecute(targetStatus){ | 
|     //根据设备类型进行调整,针对风机类 | 
|     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, | 
|         deviceList: [] | 
|     } | 
|     //获取设备信息 | 
|     var tips = $(".device"); | 
|     var select; | 
|     $.each(tips, function(index, item) { | 
|         select = item.getAttribute("select"); | 
|         if("true" == select){ | 
|             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 | 
|             }); | 
|         } | 
|     }); | 
|      | 
|     //开始调用后台执行 | 
|     layer.msg("开始执行……"); | 
|     $.ajax({ | 
|         type : 'POST', | 
|         url : "../../basic/verb/control-device", | 
|         dataType : 'JSON', | 
|         contentType : "application/json;charset=UTF-8", | 
|         data : JSON.stringify(data), | 
|         success : function(result) { | 
|             if(result.code != "ORDER_SUCCESS"){ | 
|                 layer.msg(result.msg); | 
|             }else{ | 
|                 layer.msg("操作指令发送成功,待终端响应……"); | 
|                 //开始调用动画 TODO  | 
|                 updateAnimate(deviceType,targetStatus,false); | 
|             } | 
|         }, | 
|         error : function(result) { | 
|             layer.msg("操作发生异常,暂时无法解决!!"); | 
|         } | 
|     }); | 
|      | 
| }; |