var layer;
var form;
var deviceList = [];
var deviceMap = [];
var deviceParam = [];
$(function () {
layui.use(["layer", "form"],function () {
layer = layui.layer;
form = layui.form;
form.render();
checkboxSetAll();
//获取全部设备
queryDeviceAll();
});
});
function reset() {
form.val("form-param",{});
}
function allCheckbox() {
var b = $("#all").is(":checked");
$(".ckeck").prop('checked', b);
}
function checkboxSetAll() {
$(".ckeck").click(function () {
var b = $(this).is(":checked");
// console.log(b);
if(b){
// console.log("=========遍历====");
var tag = true;
$.each($(".ckeck"), function (index, item) {
var c = $(".ckeck").eq(index).is(":checked");
if(!c){
tag = false;
return;
}
});
$("#all").prop('checked', tag);
}else{
//取消全选
$("#all").prop('checked', false);
}
});
// var b = $("#all").is(":checked");
// $(".ckeck").prop('checked', b);
}
function listSetMap(list) {
var map = [];
$.each(list,function(index,item){
map[item.id] = item;
});
return map;
}
//初始化菜单
function queryDeviceAll() {
$.ajaxSettings.async = false;
$.get("./cgi-bin/device/query-all", function (data, status) {
if ("success" == status) {
deviceList = data;
deviceMap = listSetMap(deviceList);
renderDeviceData();
} else {
window.parent.notify("系统获取监控设备信息失败!");
}
}, "json");
};
//渲染设备列表
function renderDeviceData() {
var html = '';
$.each(deviceList, function (index, item) {
//1000~1999是IO扩展设备,不显示
if(item.type != CATEGORY.D3004.code && (item.id < 1000 || item.id >= 2000)
&& item.type != CATEGORY.D2091.code && item.type != CATEGORY.D2090.code){
html += '
';
html += ' | ';
html += '' + item.name + ' | ';
html += '' + item.id + ' | ';
// html += '' + item.address + ' | ';
html += '' + (item.vld == 0 ? '启用' : '停用') + ' | ';
html += '
';
}
});
$("#tbodyList").html(html);
}
function getParam() {
var param = {};
var tag = false;
//开始通道
var b = $(".passcode0-check").is(":checked");
if(b){
param.passcode0 = $("#passcode0").val();
tag = true;
}
//结束通道
b = $(".passcode1-check").is(":checked");
if(b){
param.passcode1 = $("#passcode1").val();
tag = true;
}
//告警标识
b = $(".alarmFlag-check").is(":checked");
if(b){
param.alarmFlag = $("#alarmFlag").val();
tag = true;
}
//阈值下限
b = $(".val0-check").is(":checked");
if(b){
param.val1 = $("#val0").val();
tag = true;
}
//阈值上限
b = $(".val1-check").is(":checked");
if(b){
param.val2 = $("#val1").val();
tag = true;
}
//运算符
b = $(".operation-check").is(":checked");
if(b){
param.operation = $("#operation").val();
tag = true;
}
//运算值
b = $(".operValue-check").is(":checked");
if(b){
param.operValue = $("#operValue").val();
tag = true;
}
//是否启用
b = $(".vld-check").is(":checked");
if(b){
param.vld = $("#vld").val();
tag = true;
}
//获取选中的设备信息
deviceParam = [];
$.each($(".ckeck"), function (index, item) {
var c = $(".ckeck").eq(index).is(":checked");
if(c){
var id = $(".ckeck").eq(index).attr('id');
deviceParam.push(deviceMap[id]);
}
});
if(tag){
return param;
}else{
return null;
}
}
function save() {
var param = getParam();
// console.log(param);
if(param == null){
window.parent.notify("请选择设置参数!");
return ;
}
// console.log(deviceParam);
if(deviceParam.length < 1){
window.parent.notify("请先选择设备信息!");
return ;
}
var ids = "";
$.each(deviceParam, function (index, item) {
if(index > 0){
ids += ",";
}
ids += item.id;
});
param.ids = ids;
$.ajaxSettings.async = false;
$.post("./cgi-bin/device-warn/update", JSON.stringify(param), function (data, status) {
if ("success" == data.code) {
window.parent.notify("设置成功!");
} else {
window.parent.notify("处理失败,请重新操作!");
}
}, "json");
}