var doorData;
|
$(function() {
|
layui.use([ 'layer', 'form', 'laydate'], function() {
|
form = layui.form;
|
layer = layui.layer;
|
var laydate = layui.laydate;
|
laydate.render({
|
elem: '#startTime',
|
type: 'datetime'
|
});
|
laydate.render({
|
elem: '#endTime',
|
type: 'datetime'
|
});
|
|
//查询门禁信息
|
query();
|
});
|
});
|
|
//根据仓库查询
|
function query() {
|
var index = layer.load();
|
var depotId = $("#depotId").val();
|
var data = {
|
depotId: depotId,
|
deptId: deptId
|
};
|
$.ajax({
|
type : "POST",
|
url : "../../basic/security/doorSensor-data",
|
data : JSON.stringify(data),
|
dataType : "json",
|
contentType : "application/json;charset=UTF-8",
|
success : function(result) {
|
layer.close(index);
|
console.log(result);
|
if (result.code == "0000") {
|
doorData = result.data;
|
renderView(result.data);
|
} else {
|
renderView(null);
|
layer.alert(result.msg);
|
}
|
},
|
error : function(result) {
|
layer.close(index);
|
renderView(null);
|
layer.msg("获取数据失败,请重新尝试!");
|
}
|
});
|
}
|
|
//渲染页面数据
|
function renderView(list) {
|
$("#div_main").empty();
|
|
var html = "";
|
if(list && list.length > 0){
|
$.each(list,function(index, item) {
|
html += "<div class='layui-col-md3 layui-col-sm6'><div class='layadmin-contact-box'>";
|
html += "<div class='layui-col-md6 layui-col-sm6'><div class='layadmin-text-center'>";
|
if(item.status == "OPEN"){
|
html += "<img src='../../static/images/icon-door-open.png'>";
|
html += "<div class='layadmin-maillist-img layadmin-font-blod'>";
|
html += "<span>打开</span>";
|
}else if(item.status == "CLOSE"){
|
html += "<img src='../../static/images/icon-door-close.png'>";
|
html += "<div class='layadmin-maillist-img layadmin-font-blod'>";
|
html += "<span>关闭</span>";
|
}else {
|
html += "<img src='../../static/images/icon-door-close.png'>";
|
html += "<img style='position: absolute;top: 75px;left: 66px;max-width: 60px;z-index: 2;' src='../../static/images/icon-tanhao.png'>";
|
html += "<div class='layadmin-maillist-img layadmin-font-blod'>";
|
html += "<span>未知状态</span>";
|
}
|
html += "</div></div></div><div class='layui-col-md6 layui-col-sm6' style='padding: 15px'>";
|
html += "<h3 class='layadmin-title'><strong id='depot_0135'>";
|
html += item.name + "</strong></h3><div class='layui-col-md12'>";
|
html += "<p class='layadmin-textimg color-a'>所属仓库:" + mapDept[item.depotId] + "</p>";
|
html += "<button type='button' class='layui-btn btn-mar' onclick='cheFang(\""+ item.id +"\")'>撤防</button>";
|
html += "<button type='button' class='layui-btn btn-mar layui-btn-danger' onclick='buFang(\""+ item.depotId +"\")'>布防</button>";
|
html += "</div></div></div></div>";
|
|
});
|
}
|
|
$("#div_main").append(html);
|
}
|
|
//跳转门禁记录
|
function showDoorRecord() {
|
var url = "com.ld.igds.door.DoorRecord.d";
|
window.parent.openTab(url,"门禁记录","doorRecordData");
|
}
|
|
//布防
|
function buFang(depotId) {
|
$("#depotName2").val(mapDept[depotId]);
|
//弹出布防框
|
layer.open({
|
type: 1,
|
title: '布防',
|
area: ['360px', '240px'],
|
content: $('#buFang'),
|
btnAlign : 'c',
|
btn : [ '提交', '关闭取消' ],
|
yes : function() {
|
submitBuFang(depotId);
|
layer.closeAll();
|
},
|
btn2 : function() {
|
layer.closeAll();
|
},
|
closeBtn: 1
|
});
|
}
|
|
//撤防
|
function cheFang(id) {
|
if(!doorData || doorData.length <= 0){
|
layer.msg("数据为空,请重试!");
|
return;
|
}
|
var data;
|
for(var i = 0;i<doorData.length;i++){
|
if(id == doorData[i].id){
|
data = doorData[i];
|
}
|
}
|
if(!data){
|
layer.msg("数据为空,请重试!");
|
return;
|
}
|
var time1 = new Date();
|
var startTime = dateFtt("yyyy-MM-dd hh:mm:ss", time1);
|
|
var time2 = new Date(time1.setHours(time1.getHours() + 3));
|
var endTime = dateFtt("yyyy-MM-dd hh:mm:ss", time2);
|
|
$("#name").val(data.name);
|
$("#id").val(data.depotId);
|
$("#depotName").val(mapDept[data.depotId]);
|
$("#start").val(startTime);
|
$("#end").val(endTime);
|
|
//弹出撤防框
|
layer.open({
|
type: 1,
|
title: '撤防',
|
area: ['480px', '320px'],
|
content: $('#cheFang'),
|
btnAlign : 'c',
|
btn : [ '提交', '关闭取消' ],
|
yes : function() {
|
submitCheFang();
|
layer.closeAll();
|
},
|
btn2 : function() {
|
layer.closeAll();
|
},
|
closeBtn: 1
|
});
|
}
|
|
function submitBuFang(depotId) {
|
var data = {
|
"deptId": deptId,
|
"depotId": depotId
|
};
|
$.ajax({
|
type : "POST",
|
url : "../../basic/security/del-door-access",
|
dataType : "json",
|
contentType : "application/json;charset=UTF-8",
|
data : JSON.stringify(data),
|
success : function(result) {
|
if (result.code != "0000") {
|
layer.alert(result.msg);
|
} else {
|
layer.alert("布防成功!");
|
}
|
},
|
error : function() {
|
layer.alert("提交失败,请重新尝试!");
|
}
|
});
|
}
|
|
function submitCheFang() {
|
|
var depotId = $("#id").val();
|
var startTime = $("#start").val();
|
var endTime = $("#end").val();
|
var data = {
|
deptId: deptId,
|
depotId: depotId,
|
start: startTime,
|
end: endTime
|
};
|
$.ajax({
|
type : "POST",
|
url : "../../basic/security/add-door-access",
|
dataType : "json",
|
contentType : "application/json;charset=UTF-8",
|
data : JSON.stringify(data),
|
success : function(result) {
|
if (result.code != "0000") {
|
layer.alert(result.msg);
|
} else {
|
layer.alert("撤防成功!");
|
}
|
},
|
error : function() {
|
layer.alert("提交失败,请重新尝试!");
|
}
|
});
|
}
|
|
//fmt 时间格式化例如:yyyy-MM-dd hh:mm:ss date 时间 return 字符串
|
function dateFtt(fmt, date) {
|
var o = {
|
"M+": date.getMonth() + 1, // 月份
|
"d+": date.getDate(), // 日
|
"h+": date.getHours(), // 小时
|
"m+": date.getMinutes(), // 分
|
"s+": date.getSeconds(), // 秒
|
"q+": Math.floor((date.getMonth() + 3) / 3), // 季度
|
"S": date.getMilliseconds()
|
// 毫秒
|
};
|
if (/(y+)/.test(fmt))
|
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "")
|
.substr(4 - RegExp.$1.length));
|
for (var k in o)
|
if (new RegExp("(" + k + ")").test(fmt))
|
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k])
|
: (("00" + o[k]).substr(("" + o[k]).length)));
|
return fmt;
|
}
|