wuwei
2025-07-08 4416a04fd4f79e8bbe1f20830c41dc84d21aa994
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
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 += '<tr>';
            html += '<td><input class="ckeck" name="ckeck" type="checkbox" id="'+item.id+'"/></td>';
            html += '<td>' + item.name + '</td>';
            html += '<td>' + item.id + '</td>';
            // html += '<td>' + item.address + '</td>';
            html += '<td>' + (item.vld == 0 ? '启用' : '停用') + '</td>';
            html += '</tr>';
        }
    });
    $("#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");
}