var layer; var depotId; var view_tag = "A";//A-仓外 B-仓内 var windowWidth = 1920; var windowHeight = 1080; $(function () { layui.use(['layer'], function () { layer = layui.layer; renderDevice(); }); }); window.onload = function () { $("#m-container").css("background-image", "url(" + backgroundImg + ")"); windowWidth = document.body.offsetWidth; windowHeight = document.body.offsetHeight; }; function shoControl(id) { $.each(listDevice, function (index, item) { if (item.id == id) { depotId = item.depotId; return true; } }); layer.open({ type: 1, title: '当前仓操作', area: ['450px', '210px'], shade: 0, content: $('#control-FK'), btn: 0, closeBtn: 2 }); }; function showTips(msg) { $("#fire_info").text("信息:" + msg); }; //添加设备信息 function renderDevice() { if (!listDevice || listDevice.length == 0) { showTips("没有获取到照明配置信息!"); return; } //删除之前的渲染 $("div").remove(".device"); var container = $("#m-container"); var parentWidth = container.width(); var parentHeight = container.height(); var temp; var left = 50, top = 50; $.each(listDevice, function (index, item) { //外部设备 if (view_tag == "A" && DeviceLocation.L_05 == item.location) { return true; } //内部 if (view_tag == "B" && DeviceLocation.L_05 != item.location) { return true; } left = (parentWidth * item.posX).toFixed(4); top = (parentHeight * item.posY).toFixed(4); if (left < 1) left = 50; if (top < 1) top = 50; temp = ""; temp += "
"; if (DeviceStatus.OPEN == item.status) { temp += "
"; } else { temp += ""; } container.append(temp); }); }; function cut(tag) { if ("A" == tag) { $("#btnA").removeClass("layui-btn-primary"); $("#btnB").addClass("layui-btn-primary"); } if ("B" == tag) { $("#btnB").removeClass("layui-btn-primary"); $("#btnA").addClass("layui-btn-primary"); } view_tag = tag; renderDevice(); }; //内部操作 function executeIn(targetStatus) { toExecute(targetStatus, "IN"); }; //外部操作 function executeOut(targetStatus) { toExecute(targetStatus, "OUT"); }; //正库区操作 function executeALL(targetStatus) { depotId = null; toExecute(targetStatus, "ALL"); }; //全部状态查询 function queryAllStatus() { depotId = null; queryStatus(); }; //设备操作 function toExecute(targetStatus, type) { var param = { companyId: companyId, deptId: deptId, depotId: depotId, type: type, targetStatus: targetStatus, deviceList: listDevice }; // console.log(param); // 开始调用后台执行 layer.load(1); $.ajax({ type: 'POST', url: "../../basic/lamp/control-device", dataType: 'JSON', contentType: "application/json;charset=UTF-8", data: JSON.stringify(param), success: function (result) { layer.closeAll(); if (result.code != "ORDER_SUCCESS") { layer.alert("执行失败:" + result.msg); } else { layer.alert("操作指令发送成功,待终端响应……"); query(); } }, error: function () { layer.closeAll(); layer.alert("操作发生异常,暂时无法解决!!"); } }); }; // 状态查询 function queryStatus() { layer.load(1); var param = { companyId: companyId, deptId: deptId, depotId: depotId, deviceList: listDevice }; $.ajax({ type: "POST", url: "../../basic/lamp/query-status", dataType: "json", contentType: "application/json;charset=UTF-8", data: JSON.stringify(param), success: function (result) { layer.closeAll(); if ("ORDER_SUCCESS" != result.code) { // layer.alert(result.msg); showTips(result.msg); } query(); }, error: function () { layer.closeAll(); layer.alert("获取数据失败,请重新尝试!"); } }); }; // 执行查询 function query() { //console.log('-----------query----------------'); layer.load(1); var param = { companyId: companyId, deptId: deptId }; $.ajax({ type: "POST", url: "../../basic/lamp/list-device-group", dataType: "json", contentType: "application/json;charset=UTF-8", data: JSON.stringify(param), success: function (result) { layer.closeAll(); if (result.code != "0000") { layer.msg(result.msg); return; } listDevice = result.data; // 根据设备渲染 renderDevice(); }, error: function () { layer.closeAll(); layer.alert("获取设备列表失败,请重新刷新页面!"); } }); }; // 根据CSS标签控制那些组件支持拖拽.device function dragDevice() { var tips = $(".device"); if (tips.length == 0) { return; } var maxX = windowWidth; var maxY = windowHeight; $.each(tips, function (index, item) { var dd = new Dragdrop({ target: item, area: [0, maxX, 0, maxY], callback: function (obj) { // console.log('x:' + (obj.moveX - parentLeft) + ' y:' + (obj.moveY - parentTop)); } }); dd.dragAll(); }); }; // 保存设备位置信息 function updatePos() { var tips = $(".device"); if (tips.length == 0) { return; } var container = $("#m-container"); var parentWidth = container.width(); var parentHeight = container.height(); var parentTop = container.offset().top; var parentLeft = container.offset().left; // 封装数据进行保存 var data = new Array(); var id = null, offset, posX = 0.0, posY = 0.0; $.each(tips, function (index, item) { id = item.id; offset = $('#' + id).offset(); //调整为相对位置 posX = (offset.left - parentLeft) / parentWidth; posY = (offset.top - parentTop) / parentHeight; data[index] = { bizId: id, posX: posX.toFixed(4), posY: posY.toFixed(4) }; }); $.ajax({ type: 'POST', url: "../../basic/common/update-verb-pos", dataType: 'JSON', contentType: "application/json;charset=UTF-8", data: JSON.stringify(data), success: function (result) { layer.msg(result.msg); }, error: function (result) { layer.msg(result.msg); } }); }