var form;
|
var table;
|
var element;
|
var deviceList = [];
|
|
layui.use(['layer'], function () {
|
layer = layui.layer;
|
});
|
|
//初始化设备分类列表
|
renderCategroy();
|
//查询扩展设备信息并渲染
|
queryDeviceExpandList();
|
|
//查询设备信息并渲染
|
queryDeviceList();
|
//查询扩展设备信息 -设置为同步请求
|
function queryDeviceExpandList() {
|
$.ajaxSettings.async = false;
|
$.get("./cgi-bin/device-io/query-ext", function (data, status) {
|
if ("success" == status) {
|
renderExpandSelect(data);
|
} else {
|
window.parent.notify("系统获取扩展设备列表出错!");
|
}
|
}, "json");
|
}
|
|
//渲染扩展设备下拉框
|
function renderExpandSelect(list) {
|
$.each(list, function (index, item) {
|
$("#device-devId").append("<option value='" + item.id + "'> " + item.name + " </option>");
|
});
|
}
|
|
//查询开关量设备信息
|
function queryDeviceList() {
|
$.get("./cgi-bin/device-io/query", function (data, status) {
|
if ("success" == status) {
|
deviceList = data;
|
renderDevice();
|
} else {
|
window.parent.notify("系统获取开关量设备列表出错!");
|
}
|
}, "json");
|
}
|
|
//渲染设备列表
|
function renderDevice() {
|
var html = '';
|
$.each(deviceList, function (index, item) {
|
html += '<tr><td>' + item.name + '</td>';
|
html += '<td>' + item.id + '</td>';
|
html += '<td>' + item.devChn + '</td>';
|
html += '<td>' + (item.vld==0?'启用':'停用') + '</td>';
|
//根据所属设备Id获取设备名称,需要先渲染扩展设备下拉框才能使用
|
var devName = item.devId?$("#devId option[value = '"+ item.devId +"']").text():item.devId;
|
html += '<td>' + (devName?devName:item.devId) + '</td>';
|
html += '<td><button style="height: 29px;line-height: 29px;" ' +
|
'class="layui-btn layui-btn-normal" onclick="deviceUpdate(\''+ index +'\')">编辑</button>';
|
html += '<button style="height: 29px;line-height: 29px;" ' +
|
'class="layui-btn layui-btn-normal" onclick="copy(\''+ index +'\')">复制</button>';
|
if(item.vld==0){
|
html += '<button style="height: 29px;line-height: 29px;" ' +
|
'class="layui-btn layui-btn-warm" onclick="changeStatus(\''+ index +'\')">停用</button>';
|
}else {
|
html += '<button style="height: 29px;line-height: 29px;" ' +
|
'class="layui-btn" onclick="changeStatus(\''+ index +'\')">启用</button>';
|
}
|
html += '<button style="height: 29px;line-height: 29px;" ' +
|
'class="layui-btn layui-btn-danger" onclick="deviceDel(\''+ index +'\')">删除</button>';
|
html += '</td></tr>';
|
});
|
$("#deviceList").html(html);
|
}
|
|
//设备编辑
|
function deviceUpdate(index) {
|
$(".pop-btn").hide();
|
if(index != -1){
|
$(".pop-name").html("编辑设备配置信息");
|
$("#edit").show();
|
$("#device-id").attr("readOnly",true);
|
var cur = deviceList[index];
|
$("#device-name").val(cur.name);
|
$("#device-id").val(cur.id);
|
$("#device-type").val(cur.type);
|
$("#device-devId").val(cur.devId);
|
$("#device-devChn").val(cur.devChn);
|
$("#device-condition").val(cur.condition);
|
$("#device-vld").val(cur.vld);
|
}else{
|
$("#device-id").attr("readOnly",false);
|
$(".pop-name").html("新增设备配置信息");
|
$("#add").show();
|
}
|
|
var widthPop = "55%";
|
var heightPop = "45%";
|
if(screen.width==1920 && screen.height==1080){
|
widthPop = "55%";
|
heightPop = "45%";
|
}else if(screen.width==1280 && screen.height==1024){
|
widthPop = "75%";
|
heightPop = "60%";
|
}else{
|
widthPop = "55%";
|
heightPop = "45%";
|
}
|
|
layer.open({
|
skin: 'mypop',
|
type: 1,
|
// title: '警报信息',
|
title: false,
|
area: [widthPop, heightPop],
|
closeBtn: 0,
|
shade: 0,
|
scrollbar: false,
|
content: $('#editDeviceDom')
|
});
|
}
|
//设备编辑
|
function copy(index) {
|
$(".pop-btn").hide();
|
$("#device-id").attr("readOnly",false);
|
$(".pop-name").html("新增设备配置信息");
|
$("#add").show();
|
var cur = deviceList[index];
|
$("#device-name").val(cur.name);
|
$("#device-id").val(cur.id);
|
$("#device-type").val(cur.type);
|
$("#device-devId").val(cur.devId);
|
$("#device-devChn").val(cur.devChn);
|
$("#device-condition").val(cur.condition);
|
$("#device-vld").val(cur.vld);
|
|
var widthPop = "55%";
|
var heightPop = "45%";
|
if(screen.width==1920 && screen.height==1080){
|
widthPop = "55%";
|
heightPop = "45%";
|
}else if(screen.width==1280 && screen.height==1024){
|
widthPop = "75%";
|
heightPop = "60%";
|
}else{
|
widthPop = "55%";
|
heightPop = "45%";
|
}
|
|
layer.open({
|
skin: 'mypop',
|
type: 1,
|
// title: '警报信息',
|
title: false,
|
area: [widthPop, heightPop],
|
closeBtn: 0,
|
shade: 0,
|
scrollbar: false,
|
content: $('#editDeviceDom')
|
});
|
}
|
//执行保存
|
function save(btn) {
|
var data = {
|
name : $("#device-name").val(),
|
id : $("#device-id").val(),
|
type : $("#device-type").val(),
|
devId : $("#device-devId").val(),
|
devChn : $("#device-devChn").val(),
|
condition : $("#device-condition").val(),
|
vld : $("#device-vld").val()
|
};
|
console.log("----------开关量设备需要执行保存的数据信息--------");
|
console.log(JSON.stringify(data));
|
|
if (!data.id) {
|
window.parent.notify("设备ID不能为空!");
|
return;
|
}
|
var r = /^\d{4}$/;
|
if(!r.test(data.id)){
|
window.parent.notify("设备ID不是一个4位的正整数!");
|
return;
|
}
|
if (data.id<3000 || data.id>3999) {
|
window.parent.notify("开关量设备ID设置范围为3000~3999!");
|
return;
|
}
|
|
var url = "./cgi-bin/device-io/add";
|
if ("edit" == btn) {
|
url = "./cgi-bin/device-io/edit";
|
}
|
$.post(url, JSON.stringify(data), function (data, status) {
|
if ("success" == data.code) {
|
layer.closeAll();
|
window.parent.notify("数据保存成功!");
|
queryDeviceList();
|
} else {
|
window.parent.notify("数据保存出错,请重新操作!"+data.msg+"!");
|
}
|
}, "json");
|
}
|
//数据删除
|
function deviceDel(index) {
|
var data = deviceList[index];
|
var param = {"id": data.id};
|
layer.confirm('确定删除此条数据吗?', function (index) {
|
$.post("./cgi-bin/device-io/delete", JSON.stringify(param), function (data, status) {
|
if ("success" == status && "success" == data.code) {
|
layer.close(index);
|
window.parent.notify("数据删除成功,页面自动刷新!");
|
|
queryDeviceList();
|
} else {
|
layer.close(index);
|
window.parent.notify("数据删除失败");
|
}
|
}, "json");
|
});
|
}
|
|
//状态设置
|
function changeStatus(index) {
|
var data = deviceList[index];
|
var param = {"id": data.id};
|
var msg = "确定要停用么?", url = "./cgi-bin/device-io/val-1";
|
if (1 == data.vld) {
|
msg = "确定启用用么?";
|
url = "./cgi-bin/device-io/val-0";
|
}
|
layer.confirm(msg, function (index) {
|
$.post(url, JSON.stringify(param), function (data, status) {
|
if ("success" == status && "success" == data.code) {
|
layer.close(index);
|
window.parent.notify("操作成功,页面自动刷新!");
|
queryDeviceList();
|
} else {
|
layer.close(index);
|
window.parent.notify("数据操作失败,请重新尝试!");
|
}
|
}, "json");
|
});
|
}
|
|
function closepopBtn() {
|
//清空表单信息
|
$("#device-io")[0].reset();
|
layer.closeAll();
|
|
}
|
//初始化设备分类列表
|
function renderCategroy(){
|
$.each(CATEGORY, function (index, item) {
|
//漏水
|
if(item.code == "2005"){
|
$("#device-type").append("<option value='" + item.code + "'>" + item.name + "</option>");
|
}
|
//门禁
|
// if(item.code == "3001"){
|
// $("#device-type").append("<option value='" + item.code + "'>" + item.name + "</option>");
|
// }
|
//烟感
|
if(item.code == "3002"){
|
$("#device-type").append("<option value='" + item.code + "'>" + item.name + "</option>");
|
}
|
//红外
|
if(item.code == "3003"){
|
$("#device-type").append("<option value='" + item.code + "'>" + item.name + "</option>");
|
}
|
//消防
|
// if(item.code == "3007"){
|
// $("#device-type").append("<option value='" + item.code + "'>" + item.name + "</option>");
|
// }
|
//温感
|
if(item.code == "3008"){
|
$("#device-type").append("<option value='" + item.code + "'>" + item.name + "</option>");
|
}
|
//通用开关量
|
if(item.code == "3009"){
|
$("#device-type").append("<option value='" + item.code + "'>" + item.name + "</option>");
|
}
|
//消防开关量
|
if(item.code == "3012"){
|
$("#device-type").append("<option value='" + item.code + "'>" + item.name + "</option>");
|
}
|
//防雷
|
if(item.code == "3013"){
|
$("#device-type").append("<option value='" + item.code + "'>" + item.name + "</option>");
|
}
|
});
|
}
|
|