var viewAB = "01";// 默认正面
|
|
/**
|
* 根据设备列表渲染设备示意图,要求被渲染的divID = device_view
|
*
|
* @param listDevice
|
*/
|
renderDevice = function (listDevice) {
|
// 首先清空div中的内容
|
$("#device_view").empty();
|
// 根据设备列表添加原型信息
|
addDevice(listDevice, viewAB);
|
};
|
|
// 切换图片a=正面,b=背面
|
function cutImg(depotId, target) {
|
$("#device_view").empty();
|
|
var imgPath = "../../img/dzhwk/depot/pfc_a.png";
|
if (target == "02") {
|
imgPath = "../../img/dzhwk/depot/pfc_b.png";
|
}
|
|
$("#device_view").html('<img style="width: 100%;" src="'+imgPath+'"/>');
|
viewAB = target;
|
};
|
// 动态添加设备信息
|
function addDevice(list) {
|
if (!list || list.length == 0) return;
|
var mainImg = $("#device_view");
|
var parentLeft = mainImg.offset().left, parentTop = mainImg.offset().top;
|
|
var temp;
|
var left = 0, top = 0;
|
var imgResult;
|
$.each(list, function (index, item) {
|
// 获取PC的位置
|
left = parentLeft + item.posX - 20;
|
top = parentTop + item.posY - 10;
|
// left = item.posX - 15;
|
// top = item.posY - parentTop + 10;
|
// console.log(item.name+"---"+left +"---"+top);
|
|
temp = "";
|
if(viewAB == item.location){
|
imgResult = getStatusImg(item);
|
if (!imgResult.statusImg) {
|
return true;// 跳过
|
}
|
temp += "<div id='" + item.id + "' class='device' " + "depotid='"
|
+ item.depotId + "' name='" + item.name + "' type='"
|
+ item.type + "' passcode='" + item.passCode + "' serid='"
|
+ item.serId + "' posx='" + item.posX + "' posy='"
|
+ item.posY
|
+ "' status='" + item.status
|
+ "' link='" + item.link
|
+ "' select='false"
|
+ "' onclick=showControl('" + item.id + "') style='left:"
|
+ left + "px;top:" + top + "px;'>";
|
|
if (imgResult.statusImg.indexOf("gif") > 0) {
|
temp += "<img class='img_device' src='" + imgResult.statusImg
|
+ "' />";
|
} else {
|
if (item.type == DeviceType.TYPE_04) {
|
temp += "<img class='img_device' src='" + imgResult.statusImg
|
+ "' style='height:30px;' />";
|
} else {
|
temp += "<img class='img_device' src='" + imgResult.statusImg + "' />";
|
}
|
}
|
//表示有故障
|
if(imgResult.errorTag){
|
temp +="<i class='err-img'></i>";
|
}
|
temp +="</div>";
|
|
mainImg.append(temp);
|
}
|
});
|
};
|
|
// 根据设备类型和状态,获取当前设备的显示状态图片
|
function getStatusImg(item) {
|
var result = {
|
statusImg: null,
|
errorTag: false
|
}
|
if (DeviceType.TYPE_01 == item.type) {
|
if (!item.status || DeviceStatus.ERROR == item.status || DeviceStatus.ZERO == item.status) {
|
result.statusImg = "/img/dzhwk/device/STATUS_01_CLOSE.png";
|
result.errorTag = true;
|
return result;
|
}
|
if (DeviceStatus.CLOSE == item.status) {
|
result.statusImg = "/img/dzhwk/device/STATUS_01_CLOSE.png";
|
return result;
|
}
|
if (DeviceStatus.OPEN == item.status) {
|
result.statusImg = "/img/dzhwk/device/STATUS_01_OPEN.png";
|
return result;
|
}
|
}
|
if (DeviceType.TYPE_02 == item.type) {
|
if (!item.status || DeviceStatus.ERROR == item.status || DeviceStatus.ZERO == item.status) {
|
result.statusImg = "/img/dzhwk/device/STATUS_02_W_CLOSE.png";
|
result.errorTag = true;
|
return result;
|
}
|
if (DeviceStatus.W_CLOSE == item.status) {
|
result.statusImg = "/img/dzhwk/device/STATUS_02_W_CLOSE.png";
|
return result;
|
}
|
if (DeviceStatus.W_OPEN == item.status) {
|
result.statusImg = "/img/dzhwk/device/STATUS_02_W_OPEN.png";
|
return result;
|
}
|
if (DeviceStatus.F_CLOSE == item.status) {
|
result.statusImg = "/img/dzhwk/device/STATUS_02_W_OPEN.png";
|
return result;
|
}
|
if (DeviceStatus.F_OPEN == item.status) {
|
result.statusImg = "/img/dzhwk/device/STATUS_02_F_OPEN.gif";
|
return result;
|
}
|
if (DeviceStatus.F_OPEN_F == item.status) {
|
result.statusImg = "/img/dzhwk/device/STATUS_02_F_OPEN_F.gif";
|
return result;
|
}
|
}
|
if (DeviceType.TYPE_04 == item.type) {
|
if (!item.status || DeviceStatus.ERROR == item.status || DeviceStatus.ZERO == item.status) {
|
result.statusImg = "/img/dzhwk/device/STATUS_04_CLOSE.png";
|
result.errorTag = true;
|
return result;
|
}
|
if (DeviceStatus.CLOSE == item.status) {
|
result.statusImg = "/img/dzhwk/device/STATUS_04_CLOSE.png";
|
return result;
|
}
|
if (DeviceStatus.F_CLOSE == item.status) {
|
result.statusImg = "/img/dzhwk/device/STATUS_04_CLOSE.png";
|
return result;
|
}
|
if (DeviceStatus.OPEN == item.status) {
|
result.statusImg = "/img/dzhwk/device/STATUS_04_OPEN.gif";
|
return result;
|
}
|
if (DeviceStatus.F_OPEN == item.status) {
|
result.statusImg = "/img/dzhwk/device/STATUS_04_OPEN.gif";
|
return result;
|
}
|
}
|
|
if (DeviceType.TYPE_07 == item.type) {// 电动蝶阀
|
if (!item.status){
|
result.statusImg = "/img/dzhwk/device/icon-off.png";
|
result.errorTag = true;
|
return result;
|
}
|
if (DeviceStatus.ERROR == item.status || DeviceStatus.ZERO == item.status){
|
result.statusImg = "/img/dzhwk/device/icon-off.png";
|
return result;
|
}
|
if (DeviceStatus.CLOSE == item.status){
|
result.statusImg = "/img/dzhwk/device/icon-off.png";
|
return result;
|
}
|
if (DeviceStatus.OPEN == item.status){
|
result.statusImg = "/img/dzhwk/device/icon-on.png";
|
return result;
|
}
|
}
|
if (DeviceType.TYPE_0B == item.type) {
|
if (!item.status || DeviceStatus.ERROR == item.status || DeviceStatus.ZERO == item.status) {
|
result.statusImg = "/img/dzhwk/device/STATUS_0B_CLOSE.png";
|
result.errorTag = true;
|
return result;
|
}
|
if (DeviceStatus.CLOSE == item.status) {
|
result.statusImg = "/img/dzhwk/device/STATUS_0B_CLOSE.png";
|
return result;
|
}
|
if (DeviceStatus.OPEN == item.status) {
|
result.statusImg = "/img/dzhwk/device/STATUS_0B_OPEN.png";
|
return result;
|
}
|
}
|
if (DeviceType.TYPE_0C == item.type) {
|
if (!item.status || DeviceStatus.ERROR == item.status || DeviceStatus.ZERO == item.status) {
|
result.statusImg = "/img/dzhwk/device/STATUS_0C_W_CLOSE.png";
|
result.errorTag = true;
|
return result;
|
}
|
if (DeviceStatus.W_CLOSE == item.status) {
|
result.statusImg = "/img/dzhwk/device/STATUS_0C_W_CLOSE.png";
|
return result;
|
}
|
if (DeviceStatus.W_OPEN == item.status) {
|
result.statusImg = "/img/dzhwk/device/STATUS_0C_W_OPEN.png";
|
return result;
|
}
|
if (DeviceStatus.F_CLOSE == item.status) {
|
result.statusImg = "/img/dzhwk/device/STATUS_0C_W_OPEN.png";
|
return result;
|
}
|
if (DeviceStatus.F_OPEN == item.status) {
|
result.statusImg = "/img/dzhwk/device/STATUS_0C_F_OPEN.gif";
|
return result;
|
}
|
if (DeviceStatus.F_OPEN_F == item.status) {
|
result.statusImg = "/img/dzhwk/device/STATUS_0C_F_OPEN_F.gif";
|
return result;
|
}
|
}
|
|
if (DeviceType.TYPE_0D == item.type) {
|
if (!item.status || DeviceStatus.ERROR == item.status || DeviceStatus.ZERO == item.status) {
|
result.statusImg = "/img/dzhwk/device/STATUS_0D_CLOSE.png";
|
result.errorTag = true;
|
return result;
|
}
|
if (DeviceStatus.CLOSE == item.status) {
|
result.statusImg = "/img/dzhwk/device/STATUS_0D_CLOSE.png";
|
return result;
|
}
|
if (DeviceStatus.OPEN == item.status) {
|
result.statusImg = "/img/dzhwk/device/STATUS_0D_OPEN.gif";
|
return result;
|
}
|
}
|
return result;
|
};
|
|
// 根据CSS标签控制那些组件支持拖拽.device
|
function dragDevice() {
|
var tips = $(".device");
|
if (tips.length == 0) {
|
return;
|
}
|
var container = $("#device_view");
|
var parentLeft = container.offset().left, parentTop = container.offset().top;
|
// var height = container.outerHeight();
|
// console.log("parentLeft=" + parentLeft);
|
// console.log("parentTop=" + parentTop);
|
var maxX = 1800, maxY = 1000;
|
$.each(tips, function (index, item) {
|
var dd = new Dragdrop({
|
target: item,
|
area: [0, maxX, 0, maxY],
|
callback: function (obj) {
|
console.log('x:' + (obj.moveX) + ' y:' + (obj.moveY));
|
}
|
});
|
dd.dragAll();
|
});
|
};
|
|
// 保存设备位置信息
|
function updatePos() {
|
return;
|
var tips = $(".device");
|
if (tips.length == 0) {
|
return;
|
}
|
var container = $("#device_view");
|
var parentLeft = container.offset().left, parentTop = container.offset().top;
|
// 封装数据进行保存
|
var data = new Array();
|
var id = null, curDepotId = null;
|
var offset;
|
|
$.each(tips, function (index, item) {
|
id = item.id;
|
posX = item.getAttribute("posx");
|
posY = item.getAttribute("posy");
|
curDepotId = item.getAttribute("depotid");
|
offset = $('#' + id).offset();
|
// console.log(item);
|
// console.log("left=" + (offset.left - parentLeft) + "-----top="
|
// + (offset.top - parentTop));
|
data[index] = {
|
bizId: id,
|
depotId: curDepotId,
|
selfTag: viewAB,
|
posX: offset.left - parentLeft,
|
posY: offset.top - parentTop
|
};
|
});
|
$.ajax({
|
type: 'POST',
|
url: "../../basic/control/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);
|
}
|
});
|
}
|
|
/**
|
* 根据设备类型和目标状态,调整动画效果
|
*
|
* @param deviceType
|
* 设备类型
|
* @param targetStatus
|
* 目标状态
|
* @param isEnd
|
* 是否执行完成
|
*/
|
function updateAnimate(deviceType, targetStatus, isEnd) {
|
// console.log("deviceType===" + deviceType);
|
// console.log("targetStatus===" + targetStatus);
|
// 获取动效的操作
|
var img = "/img/dzhwk/device/STATUS_01_CLOSE.png";
|
if (deviceType == DeviceType.TYPE_01) {
|
if (targetStatus == DeviceStatus.CLOSE) {
|
img = "/img/dzhwk/device/ANIMATE_01_CLOSE.gif";
|
if (isEnd)
|
img = "/img/dzhwk/device/STATUS_01_CLOSE.png";
|
}
|
if (targetStatus == DeviceStatus.OPEN) {
|
img = "/img/dzhwk/device/ANIMATE_01_OPEN.gif";
|
if (isEnd)
|
img = "/img/dzhwk/device/STATUS_01_OPEN.png";
|
}
|
}
|
|
if (deviceType == DeviceType.TYPE_02) {
|
if (targetStatus == DeviceStatus.W_CLOSE) {
|
img = "/img/dzhwk/device/ANIMATE_02_W_CLOSE.gif";
|
if (isEnd)
|
img = "/img/dzhwk/device/STATUS_02_CLOSE.png";
|
}
|
if (targetStatus == DeviceStatus.W_OPEN) {
|
img = "/img/dzhwk/device/ANIMATE_02_W_OPEN.gif";
|
if (isEnd)
|
img = "/img/dzhwk/device/STATUS_02_W_OPEN.png";
|
}
|
if (targetStatus == DeviceStatus.F_OPEN) {
|
img = "/img/dzhwk/device/ANIMATE_02_F_OPEN.gif";
|
if (isEnd)
|
img = "/img/dzhwk/device/STATUS_02_F_OPEN.gif";
|
}
|
if (targetStatus == DeviceStatus.F_CLOSE) {
|
img = "/img/dzhwk/device/ANIMATE_02_F_CLOSE.gif";
|
if (isEnd)
|
img = "/img/dzhwk/device/STATUS_02_W_OPEN.png";
|
}
|
}
|
|
if (deviceType == DeviceType.TYPE_0B) {
|
if (targetStatus == DeviceStatus.CLOSE) {
|
img = "/img/dzhwk/device/ANIMATE_0B_CLOSE.gif";
|
if (isEnd)
|
img = "/img/dzhwk/device/STATUS_0B_CLOSE.png";
|
}
|
if (targetStatus == DeviceStatus.OPEN) {
|
img = "/img/dzhwk/device/ANIMATE_0B_OPEN.gif";
|
if (isEnd)
|
img = "/img/dzhwk/device/STATUS_0B_OPEN.png";
|
}
|
}
|
|
if (deviceType == DeviceType.TYPE_0C) {
|
if (targetStatus == DeviceStatus.W_CLOSE) {
|
img = "/img/dzhwk/device/ANIMATE_0C_W_CLOSE.gif";
|
if (isEnd)
|
img = "/img/dzhwk/device/STATUS_0C_W_CLOSE.png";
|
}
|
if (targetStatus == DeviceStatus.W_OPEN) {
|
img = "/img/dzhwk/device/ANIMATE_0C_W_OPEN.gif";
|
if (isEnd)
|
img = "/img/dzhwk/device/STATUS_0C_W_OPEN.png";
|
}
|
if (targetStatus == DeviceStatus.F_OPEN) {
|
img = "/img/dzhwk/device/ANIMATE_0C_F_OPEN.gif";
|
if (isEnd)
|
img = "/img/dzhwk/device/STATUS_0C_F_OPEN.gif";
|
}
|
if (targetStatus == DeviceStatus.F_OPEN_F) {
|
img = "/img/dzhwk/device/ANIMATE_0C_F_OPEN_F.gif";
|
if (isEnd)
|
img = "/img/dzhwk/device/STATUS_0C_F_OPEN.gif";
|
}
|
if (targetStatus == DeviceStatus.F_CLOSE) {
|
img = "/img/dzhwk/device/ANIMATE_0C_F_CLOSE.gif";
|
if (isEnd)
|
img = "/img/dzhwk/device/STATUS_0C_W_OPEN.png";
|
}
|
}
|
$("#img_animate").attr('src', img);
|
}
|