var layer;
|
|
$(function () {
|
layui.use(['layer'], function () {
|
layer = layui.layer;
|
addDevice(listFire);
|
});
|
|
});
|
|
function showDetail(id) {
|
var curFire = null;
|
|
$.each(listFire, function (index, item) {
|
if (item.id == id) {
|
curFire = item;
|
return true;
|
}
|
});
|
|
if (!curFire) {
|
layer.alert("没有获取到当前消防栓信息……");
|
return;
|
}
|
|
var cont = '<span>名称:' + curFire.name + '</span><br><span>巡更人:' + curFire.updateUser
|
+ '</span><br><span>巡更时间:' + dateFormatStr(curFire.updateTime) + '</span><br><span>启用时间:'
|
+ dateFormatStr(curFire.startTime) + '</span>';
|
|
layer.open({
|
type: 1,
|
title: '详细信息',
|
area: ['210px', '140px'],
|
shade: 0,
|
content: cont,
|
// btn: '关闭',
|
// yes: function () {
|
// layer.closeAll();
|
// }
|
});
|
};
|
|
function showTips(name) {
|
$("#fire_info").text("信息:当前设备名称:" + name);
|
};
|
|
// 开始拖拽
|
function drag() {
|
var tips = $(".device");
|
if (tips.length == 0) {
|
return;
|
}
|
var container = $("#m-container");
|
console.log(container);
|
|
// var parentTop = container.offset().top;
|
var parentLeft = container.offset().left;
|
var maxX = parentLeft + container.width();
|
|
$.each(tips, function (index, item) {
|
var dd = new Dragdrop({
|
target: item,
|
area: [0, maxX, 0, 1000],
|
callback: function (obj) {
|
console.log('x:' + (obj.moveX) + ' y:' + (obj.moveY));
|
}
|
});
|
dd.dragAll();
|
});
|
};
|
|
//添加设备信息
|
function addDevice(list) {
|
console.log(list);
|
if (!list || list.length == 0) {
|
return;
|
}
|
var container = $("#m-container");
|
var parentTop = container.offset().top;
|
var parentLeft = container.offset().left;
|
var temp;
|
var left = 0, top = 0;
|
$.each(list, function (index, item) {
|
left = parentLeft + item.posX;
|
top = parentTop + item.posY;
|
temp = "";
|
temp += "<div id='" + item.id + "' class='device' "
|
+ "' onclick=showTips('" + item.name + "') "
|
+ "' ondblclick=showDetail('" + item.id + "') style='left:"
|
+ left + "px;top:" + top + "px;'>";
|
temp += "<img src='../../static/images/fire.png' /></div>";
|
container.append(temp);
|
});
|
};
|
|
// 保存设备位置信息
|
function updatePos() {
|
var tips = $(".device");
|
if (tips.length == 0) {
|
return;
|
}
|
var container = $("#m-container");
|
var parentTop = container.offset().top;
|
var parentLeft = container.offset().left;
|
|
// 封装数据进行保存
|
var data = new Array();
|
var id = null, posX = 0.0, posY = 0.0;
|
var offset;
|
$.each(tips, function (index, item) {
|
id = item.id;
|
offset = $('#' + id).offset();
|
data[index] = {
|
id: id,
|
posX: offset.left - parentLeft,
|
posY: offset.top - parentTop
|
};
|
});
|
$.ajax({
|
type: 'POST',
|
url: "../../basic/security/update-fire-pos",
|
dataType: 'JSON',
|
contentType: "application/json;charset=UTF-8",
|
data: JSON.stringify(data),
|
success: function (result) {
|
layer.msg("信息更新完成!!");
|
},
|
error: function (result) {
|
layer.msg(result.msg);
|
}
|
});
|
}
|
|
//格式化时间
|
function dateFormatStr(time) {
|
if (time) {
|
var d = new Date(time);
|
return dateFtt("yyyy-MM-dd", d);
|
}
|
return "";
|
}
|