var layer;
|
var form;
|
var deviceList;// 当前仓库的所有设备列表
|
var depotId;
|
var deviceType = DeviceType.TYPE_05;// 被选中的设备类型,设备类型 空调
|
var viewTargetStatus;// 目标状态,根据设备类型和当前值调用动效
|
var domSelectDevice;// 被选中的设备dom对象
|
|
$(function () {
|
layui.use(['layer', 'form'], function () {
|
form = layui.form;
|
layer = layui.layer;
|
|
form.render();
|
|
// 监听仓库选择
|
form.on('select(select_depotId)', function (obj) {
|
return onDepotChange(obj);
|
});
|
|
//初始化刷新数据
|
initData();
|
});
|
|
// 添加切换动作
|
$(".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");
|
});
|
});
|
|
function initData() {
|
if (depotId) {
|
$("#depotId").val(depotId);
|
query(true, true, true);
|
form.render();
|
}
|
}
|
|
/**
|
* 检测仓库类型是否发生改变,如果发生改变,重新切换页面
|
*/
|
function onDepotChange(obj) {
|
var depotType = obj.elem[obj.elem.selectedIndex].getAttribute('type');
|
if (depotType == DEPOT_TYPE) {
|
query(true, true, true);
|
} else {
|
changeView(depotType);
|
}
|
}
|
|
function changeView(depotType) {
|
//类型改变,自动切换页面
|
if (socket) {
|
socket.close();
|
}
|
depotId = $("#depotId").val();
|
window.location.href = "./gateway?depotId=" + depotId + "&depotType=" + depotType;
|
return true;
|
}
|
|
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;
|
}
|
//把当前页面的设备传递到后台
|
var data = {
|
depotId: depotId,
|
deptId: deptId,
|
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/temp/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("获取数据失败,请重新尝试!");
|
}
|
});
|
};
|
|
/**
|
* @param isNew 是否新库跟新仓库信息并执行状态刷新
|
* @param isCut 是否切换页面
|
* @param isQueryStatus 是否更新状态
|
*/
|
function query(isNew, isCut, isQueryStatus) {
|
depotId = $("#depotId").val();
|
if (!depotId) {
|
layer.msg("请先选择仓库!");
|
return;
|
}
|
if (isNew) {
|
updateGrainInfo();
|
}
|
deviceList = [{"companyId":"5303","depotId":"P0101","id":"53030P190220_11001","link":"3001","location":"01","locationName":"02-背面","name":"空调#1","passCode":1001,"posX":857,"posY":216,"serId":"20","status":"OPEN","statusName":"风机正转","type":"05","typeName":"05-空调"},{"companyId":"5303","depotId":"P0101","id":"53030P190220_11002","link":"3002","location":"01","locationName":"02-背面","name":"空调#2","passCode":1002,"posX":469,"posY":212,"serId":"20","status":"CLOSE","statusName":"风口开","type":"05","typeName":"05-空调"}];
|
if(isCut){
|
toCutExe(viewAB,true);
|
}
|
// $.ajax({
|
// type: "POST",
|
// url: "../../basic/temp/list-device-manual",
|
// dataType: "json",
|
// contentType: "application/json;charset=UTF-8",
|
// data: JSON.stringify({
|
// depotId: depotId
|
// }),
|
// success: function (result) {
|
// if (isNew) {
|
// updateGrainInfo();
|
// }
|
//
|
// if (result.code != "0000") {
|
// layer.msg(result.msg);
|
// deviceList = null;
|
// if(isCut){
|
// toCutExe(viewAB,true);
|
// }
|
// return;
|
// }
|
// deviceList = result.data;
|
// if(isCut){
|
// toCutExe(viewAB,true);
|
// }
|
// if (isQueryStatus) {
|
// queryStatus();
|
// }
|
// },
|
// error: function (result) {
|
// layer.msg("获取数据失败,请重新尝试!");
|
// }
|
// });
|
};
|
|
// 获取当前仓库的最新粮情数据信息
|
function updateGrainInfo() {
|
$("#tempIn").text("26.6");
|
$("#humidityIn").text("41");
|
$("#humidityOut").text("63");
|
$("#tempOut").text("32.4");
|
$("#updateTime").text("2025-05-16 09:05");
|
// $.ajax({
|
// type: "POST",
|
// url: "../../basic/grain/grain-data",
|
// 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;
|
// }
|
// var grainData = result.data;
|
// // 更新信息
|
// $("#tempIn").text(grainData.tempIn <= -100?"--":(grainData.tempIn).toFixed(1));
|
// $("#humidityIn").text((grainData.humidityIn).toFixed(1));
|
// $("#humidityOut").text((grainData.humidityOut).toFixed(1));
|
// $("#tempOut").text(grainData.tempOut <= -100?"--":(grainData.tempOut).toFixed(1));
|
// $("#updateTime").text(grainData.receiveDate);
|
// },
|
// error: function (result) {
|
// layer.msg("当前仓库的粮情数据信息获取失败!");
|
// }
|
// });
|
};
|
|
/**
|
* 切换效果
|
* @param target 正反面
|
* @param isCutImg 是否执行切图
|
*/
|
function toCutExe(target, isCutImg) {
|
// 获取当前仓库效果图
|
viewAB = target;
|
if (isCutImg) {
|
cutImg(depotId, viewAB);
|
}
|
// 根据设备列表添加原型信息
|
addDevice(deviceList, viewAB);
|
};
|
|
// 手动执行,同时更新状态
|
function toCut(target) {
|
if(target == "03" || target == "04"){
|
layer.msg("暂未对接!");
|
return;
|
}
|
toCutExe(target, true);
|
};
|
|
// 添加操作日志
|
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) {
|
addLog("<font color='red'>当前所选设备:" + domSelectDevice.attr("name")
|
+ "【非所选仓库】</font>");
|
return;
|
} else {
|
addLog("当前所选设备:" + domSelectDevice.attr("name"));
|
}
|
// 更新所选择的设备类型
|
deviceType = domSelectDevice.attr("type");
|
if (1 == deviceType)
|
deviceType = "01";
|
if (2 == deviceType)
|
deviceType = "02";
|
if (3 == deviceType)
|
deviceType = "03";
|
if (4 == deviceType)
|
deviceType = "04";
|
if (5 == deviceType)
|
deviceType = "05";
|
if (6 == deviceType)
|
deviceType = "06";
|
if (7 == deviceType)
|
deviceType = "07";
|
if (8 == deviceType)
|
deviceType = "08";
|
if (9 == deviceType)
|
deviceType = "09";
|
|
// 根据设备类型弹出不一样的弹出框
|
if (DeviceType.TYPE_04 == deviceType) {// 环流风机
|
layer.open({
|
type: 1,
|
title: '设备操作-' + domSelectDevice.attr("name"),
|
area: ['450px', '200px'],
|
shade: 0,
|
content: $('#control-HL2'),
|
btn: 0,
|
closeBtn: 2
|
});
|
} else {
|
layer.open({
|
type: 1,
|
title: '空调控制-' + domSelectDevice.attr("name"),
|
area: ['420px', '280px'],
|
shade: 0,
|
content: $('#tempControl'),
|
btn: ['确定执行', '取消操作'],
|
yes: function () {
|
layer.msg("暂未对接设备");
|
return;
|
toExecute();
|
layer.closeAll();
|
layer.msg("开始执行……");
|
},
|
btn2: function () {
|
layer.closeAll();
|
},
|
closeBtn: 0
|
});
|
}
|
};
|
|
function toExecute(targetStatus) {
|
if (deviceType == "04"){
|
toExecute04(targetStatus)
|
}
|
if (deviceType == "05"){
|
toExecute05()
|
}
|
};
|
|
// 操作空调
|
function toExecute05() {
|
var targetStatus = $('input[name="targetStatus"]:checked').val();
|
var targetTemp = $("#targetTemp").val();
|
var targetModel = $('input[name="targetModel"]:checked').val();
|
|
if (!targetTemp)
|
targetTemp = 16;
|
if (targetTemp < 16)
|
targetTemp = 16;
|
if (targetTemp > 24)
|
targetTemp = 24;
|
|
if ("on" == targetStatus) {
|
targetStatus = "OPEN";
|
} else {
|
targetStatus = "CLOSE";
|
}
|
var exeDevice = null;
|
$.each(deviceList, function (index, item) {
|
if (item.id == domSelectDevice.attr("id")) {
|
exeDevice = item;
|
return true;
|
}
|
});
|
|
var data = {
|
companyId: companyId,
|
deptId: deptId,
|
depotId: depotId,
|
targetStatus: targetStatus,
|
targetTemp: targetTemp,
|
targetModel: targetModel,
|
deviceList: [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("温控执行失败,后台出现错误!");
|
}
|
});
|
};
|
|
// 操作环流风机
|
function toExecute04(targetStatus) {
|
viewTargetStatus = targetStatus;
|
|
var data = {
|
depotId: depotId,
|
deptId: deptId,
|
deviceList: []
|
};
|
|
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
|
});
|
|
// 开始调用后台执行
|
layer.load(1);
|
$.ajax({
|
type: 'POST',
|
url: "../../basic/verb/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("操作发生异常,暂时无法解决!!");
|
}
|
});
|
};
|