CZT
2023-10-21 3e7773504d6bd15e6ed20ecf5c6236b163ba0fe8
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
var layer;
var form;
var depotId;
var listAuto;
$(function () {
    layui.use(['layer', 'table', 'form'], function () {
        table = layui.table;
        form = layui.form;
        layer = layui.layer;
        //监听仓库选择
        form.on('select(select_depotId)', function () {
            query();
        });
        //监听提交
        form.on('submit(submitAuto)', function (data) {
            addSubmit(data.field);
            return false;
        });
        //监听工具条
        table.on('tool(table_auto_conf)', function (obj) {
            var data = obj.data;
            if (obj.event === 'ZERO') {
                data.targetStatus = "ZERO";
            } else if (obj.event === 'OPEN' || obj.event === 'W_OPEN') {
                if (data.type == "0C" || data.type == "02") {
                    data.targetStatus = "W_OPEN";
                } else {
                    data.targetStatus = "OPEN";
                }
            } else if (obj.event === 'F_OPEN') {
                if (data.type == "0C" || data.type == "02") {
                    data.targetStatus = "F_OPEN";
                } else {
                    layer.msg("当前设备不支持该目标操作……");
                }
            } else if (obj.event === 'F_OPEN_F') {
                if (data.type == "0C" || data.type == "02") {
                    data.targetStatus = "F_OPEN_F";
                } else {
                    layer.msg("当前设备不支持该目标操作……");
                }
            }
            obj.update(data);
        });
    });
    //初始化ws
    initWS(deptId, bizType, null, userId);
});
 
//socket信息返回處理
function socketOnMessage(pocket) {
    window.parent.sysNotify(pocket.data);
};
 
//根据仓库查询
function query() {
    var param = {
        companyId: companyId,
        deptId: deptId
    }
    $.ajax({
        type: "POST",
        url: "../../basic/verb/list-auto",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(param),
        success: function (result) {
            if (result.code == "0000") {
                listAuto = result.data;
                renderAuto();
            } else {
                $("#div_main").text(result.msg);
                layer.msg(result.msg);
            }
        },
        error: function () {
            layer.msg("获取数据失败,请重新尝试!");
        }
    });
};
 
//动态渲染自动模式数据
function renderAuto() {
    var strHtml = "";
    $.each(listAuto, function (index, item) {
        strHtml += "<div class=\"layui-col-md4 layui-col-sm6\">\n <div class=\"layadmin-contact-box\">\n <div class=\"layui-col-md4 layui-col-sm6\">\n <div class=\"layadmin-text-center\">";
        //控制模式效果
        if (item.exeMode == "01") {//表示平台执行
            strHtml += "<img src=\"../../static/images/areation-icon.gif\">";
            strHtml += "<div class=\"layadmin-maillist-img layadmin-font-blod\">平台执行</div>";
        } else {
            strHtml += "<img src=\"../../static/images/areation-icon.png\">";
            strHtml += "<div class=\"layadmin-maillist-img layadmin-font-blod\">控制柜执行</div>";
        }
        strHtml += "</div></div>\n <div class=\"layui-col-md8 layadmin-padding-left20 layui-col-sm6\">";
        strHtml += "<h3 class=\"layadmin-title\"><strong>" + item.name + "</strong></h3>";
        strHtml += "<div class=\"layadmin-address\">\n <strong><i class=\"layui-icon layui-icon-tips\"></i> 说明</strong> <br>";
        strHtml += "<p class=\"layadmin-textimg\">" + item.remark + "</p></div>";
        strHtml += "<p class=\"layadmin-textimg\">";
        strHtml += "<button type=\"button\" class=\"layui-btn\" onclick=\"runAuto('" + item.id + "')\">开启</button>";
        strHtml += "<button type=\"button\" class=\"layui-btn layui-btn-normal\" onclick=\"stopAuto('" + item.id + "')\">关闭</button>";
        strHtml += "<button type=\"button\" class=\"layui-btn layui-btn-warm\" onclick=\"editAuto('" + item.id + "')\">编辑</button>";
        strHtml += "<button type=\"button\" class=\"layui-btn layui-btn-danger\" onclick=\"editAutoConf('" + item.id + "')\">配置</button>";
        strHtml += "</div></div></div>\n";
    });
    $("#div_main").html(strHtml);
};
 
//点击运行,弹出选择原因
function runAuto(autoId) {
    depotId = $("#depotId").val();
    if (!depotId) {
        layer.msg("请先选择仓库!!");
        return;
    }
    layer.open({
        type: 1,
        title: '请选择通风目的',
        area: ['250px', '400px'],
        shade: 0,
        content: $('#select_target'),
        btn: ['确定执行', '取消操作'],
        yes: function () {
            runAutoStep2(autoId);
            layer.close(0);
        },
        btn2: function () {
            layer.close(0);
        },
        closeBtn: 1
    });
}
 
//运行第二步
function runAutoStep2(autoId) {
    var areationTarget = $('#select_target input[name="areation_target"]:checked ').val();
 
    if (!areationTarget) {
        layer.alert("请选择通风目的!");
        return;
    }
    var index = layer.load(0);
    $.ajax({
        type: "POST",
        url: "../../basic/verb/run-auto",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify({depotId: depotId, autoId: autoId, areationTarget: areationTarget}),
        success: function (result) {
            layer.close(index);
            if (result.code == "ORDER_SUCCESS") {
                layer.alert("设备操控指令发送成功!");
            } else {
                layer.alert(result.msg == null ? "系统后台执行失败,请联系统管理员" : result.msg);
            }
        },
        error: function (result) {
            layer.alert("系统后台执行失败,请联系统管理员!");
        }
    });
};
 
//停止
function stopAuto(autoId) {
    depotId = $("#depotId").val();
    if (!depotId) {
        layer.alert("请先选择仓库!!");
        return;
    }
    var index = layer.load(0);
    $.ajax({
        type: "POST",
        url: "../../basic/verb/stop-auto",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify({depotId: depotId, autoId: autoId}),
        success: function (result) {
            layer.close(index);
            if (result.code == "ORDER_SUCCESS") {
                layer.alert("设备操控指令发送成功!");
            } else {
                layer.alert(result.msg);
            }
        },
        error: function (result) {
            layer.alert("系统后台执行失败,请联系统管理原!");
        }
    });
};
 
//编辑
function editAuto(autoId) {
    var curItem = null;
    $.each(listAuto, function (index, item) {
        if (autoId == item.id) {
            curItem = item;
            return true;
        }
    });
    //开始赋值
    form.val('form_auto', curItem);
    form.render();
 
    layer.open({
        type: 1,
        title: '通风模式调整',
        area: ['700px', '430px'],
        shade: 0,
        content: $('#addAuto'),
        btn: ['提交', '删除', '取消'],
        yes: function () {
            addSubmit();
        },
        btn2: function () {
            layer.confirm('确定要删除么?', function (index) {
                delAuto();
            })
        },
        btn3: function () {
            layer.close(0);
        },
        closeBtn: 1
    });
 
};
 
//编辑配置信息
function editAutoConf(autoId) {
    depotId = $("#depotId").val();
    if (!depotId) {
        layer.msg("请先选择仓库!!");
        return;
    }
    //获取配置数据信息
    $.ajax({
        type: "POST",
        url: "../../basic/verb/list-auto-conf",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify({depotId: depotId, autoId: autoId}),
        success: function (result) {
            if (result.code == "0000") {
                //弹出对话框,并渲染数据
                renderAutoConf(autoId, result.data);
            } else {
                layer.msg(result.msg);
            }
        },
        error: function (result) {
            layer.msg("系统后台执行失败,请联系统管理原!");
        }
    });
};
 
//渲染配置信息
function renderAutoConf(autoId, listAutoConf) {
    // 弹出选择框
    layer.open({
        type: 1,
        title: '配置自动模式设备控制',
        area: ['860px', '600px'],
        shade: 0,
        content: $('#autoConf'),
        btn: ['提交配置', '取消'],
        yes: function () {
            submitAutoConf(autoId);
        },
        btn2: function () {
            layer.close(0);
        },
        closeBtn: 1
    });
    //渲染表格
    table.render({
        elem: '#table_auto_conf',
        height: 450,
        data: listAutoConf,
        page: false,
        limit: 100,
        even: "true",
        cols: [[{
            width: '25%',
            field: 'name',
            title: '设备名称',
        }, {
            width: '15%',
            field: 'location',
            title: '位置',
            align: 'center',
            templet: locationStatus
        }, {
            width: '25%',
            field: 'targetStatus',
            title: '目标状态',
            align: 'center',
            templet: targetStatus
        }, {
            width: '35%',
            title: '配置操作',
            align: 'center',
            toolbar: '#barAutoConf'
        }
        ]]
    });
};
 
function locationStatus(d) {
    if (d.location == "01") {
        return "正面";
    } else {
        return "背面";
    }
};
 
function targetStatus(d) {
    var targetStatus = d.targetStatus;
    var result = "<span style=\"color: #C9C9C9;\">无控制</span>";
    if (targetStatus == "OPEN" || targetStatus == "W_OPEN") {
        result = "<span style=\"color: #1E9FFF;\">窗口开</span>";
    }
    if (targetStatus == "F_OPEN") {
        result = "<span style=\"color: #FFB800;\">风机正转</span>";
    }
    if (targetStatus == "F_OPEN_F") {
        result = "<span style=\"color: #009688;\">风机反转</span>";
    }
    return result;
};
 
function submitAutoConf(autoId) {
    var listData = table.cache["table_auto_conf"];
    layer.msg("开始提交配置信息……");
    $.ajax({
        type: "POST",
        url: "../../basic/verb/update-auto-conf",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify({deviceList: listData, autoId: autoId}),
        success: function (result) {
            if (result.code == "0000") {
                layer.msg("数据提交完成……");
            } else {
                layer.msg(result.msg);
            }
        },
        error: function (result) {
            layer.msg("系统后台执行失败,请联系统管理原!");
        }
    });
};
 
//删除
function delAuto() {
    var formData = form.val('form_auto');
    //编辑删除标记
    formData["delTag"] = "Y";
    $.ajax({
        type: "POST",
        url: "../../basic/verb/update-auto",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(formData),
        success: function (result) {
            if (result.code == "0000") {
                layer.msg("数据删除成功!!");
                query();
                layer.closeAll();
            } else {
                layer.msg(result.msg);
            }
        },
        error: function (result) {
            layer.msg("系统后台执行失败,请联系统管理原!");
        }
    });
};
 
//新增手动模式
function addAuo() {
    //重置
    $("#form_auto")[0].reset();
    form.render();
 
    // 弹出选择框
    layer.open({
        type: 1,
        title: '新增通风模式',
        area: ['680px', '400px'],
        shade: 0,
        content: $('#addAuto'),
        btn: ['提交', '取消'],
        yes: function () {
            addSubmit();
        },
        btn2: function () {
            layer.close(0);
        },
        closeBtn: 1
    });
};
 
//提交模式新增数据
function addSubmit() {
    var formData = form.val('form_auto');
    $.ajax({
        type: "POST",
        url: "../../basic/verb/update-auto",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(formData),
        success: function (result) {
            if (result.code == "0000") {
                layer.msg("手动模式添成功!");
                layer.closeAll();
                query();
            } else {
                layer.msg(result.msg);
            }
        },
        error: function () {
            layer.msg("系统后台执行失败,请联系统管理原!");
        }
    });
};