jiazx0107@163.com
2023-05-17 620eab6cca2bc9ef9ea6d3067a0a5ba1deadbd1c
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
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
var layer;
var grainData;// 当前仓粮情数据
var form;
var table;
var element;
var compareData = null;// 对比数据
var listGrainData;// 默认页面中的粮情列表
var mapGrainData;// 批量打印中的批量粮情信息
 
$(function () {
    layui.use(['layer', 'laydate', 'form', 'table', 'element'], function () {
        element = layui.element;
        form = layui.form;
        layer = layui.layer;
        var laydate = layui.laydate;
        table = layui.table;
 
        // 日期
        laydate.render({
            elem: '#checkDateMore',
            type: 'month',
            theme: '#7b8e9f',
            position: 'static',
            done: function (value, date, endDate) {
                flushGrain(value);
            }
        });
 
        laydate.render({
            elem: '#compareCheckDate',
            type: 'month',
            theme: '#7b8e9f',
            done: function (value, date, endDate) {
                compareStep2(value);
            }
        });
 
        laydate.render({
            elem: '#printCheckDate',
            theme: '#7b8e9f'
        });
 
        laydate.render({
            elem: '#printCheckDate2',
            theme: '#7b8e9f'
        });
        form.render();
 
        // 监听仓库选择
        form.on('select(select_depotId)', function (obj) {
            return onDepotChange(obj);
        });
 
        // 监听选择批次
        form.on('select(select_batchId)', function (obj) {
            var value = obj.value;
            if (value == "0") {// 表示弹出更多批次
                showMore();
            } else {
                flushGrainByBatchId(value);
            }
        });
 
        // 监听显示类型
        form.on('switch(filter_switch)', function (obj) {
            var value = obj.value;
            var checked = obj.elem.checked;
            if (checked) {
                if ("lay" == value) {// 层
                    $("#switch_row").prop("checked", false);
                    $("#switch_col").prop("checked", false);
                    lay();
                }
                if ("row" == value) {
                    $("#switch_lay").prop("checked", false);
                    $("#switch_col").prop("checked", false);
                    row();
                }
                if ("col" == value) {
                    $("#switch_lay").prop("checked", false);
                    $("#switch_row").prop("checked", false);
                    col();
                }
                form.render();
            }
        });
 
        form.on('switch(filter_switch2)', function (obj) {
            var value = obj.value;
            var checked = obj.elem.checked;
            console.log(value);
 
            if (checked) {
                if ("outer" == value) {
                    $("#switch_all").prop("checked", false);
                    $("#switch_inner").prop("checked", false);
                    display_outside();
                }
                if ("all" == value) {
                    $("#switch_inner").prop("checked", false);
                    $("#switch_outer").prop("checked", false);
                    display_all();
                }
                if ("inner" == value) {
                    $("#switch_all").prop("checked", false);
                    $("#switch_outer").prop("checked", false);
                    display_inside();
                }
                form.render();
            }
        });
 
        // 监听对比数据
        table.on('radio(filterTable)', function (obj) {
            compareData = obj.data;
        });
 
        //初始化刷新数据
        initData();
    });
 
    // 初始化坐标系
    initGrainChar3d();
 
    // 初始化WebSocket
    initWS(deptId, bizType, null, userId);
});
 
function initData() {
    if (depotId) {
        $("#depotId").val(depotId);
        flushGrain(null);
        form.render();
    }
}
 
/**
 * 检测仓库类型是否发生改变,如果发生改变,重新切换页面
 */
function onDepotChange(obj) {
    //仓库类型
    var depotType = obj.elem[obj.elem.selectedIndex].getAttribute('type');
    //储粮方式
    var storeType = listDepot[obj.elem.selectedIndex - 1].storeType;
    if (depotType == DEPOT_TYPE) {
        if (storeType && storeType == "2") {
            changeView(depotType, storeType);
        } else {
            flushGrain(null);
            return true;
        }
    } else {
        changeView(depotType, storeType);
    }
}
 
function changeView(depotType, storeType) {
    //类型改变,自动切换页面
    if (socket) {
        socket.close();
    }
    depotId = $("#depotId").val();
    window.location.href = "../../basic/grain/gateway?depotId=" + depotId
        + "&depotType=" + depotType + "&storeType=" + storeType;
    return true;
}
 
// socket信息返回處理
function socketOnMessage(pocket) {
    if (pocket.orderResp == "MSG_SUCCESS") {// 信息解析成功刷新当前数据
        window.parent.sysNotify(pocket.data);
    }
};
 
// 单仓打印
function printSingle() {
    layer.msg("开始调用后台打印模板……");
    toPrintSingle(grainData);
}
 
// 批量打印
function printBatch() {
    // 首先去除之前的选择
    $('#batchPrintSelect input').each(function () {
        var name = $(this).prop("name");
        if (name == "printCheckDate") {// 跳过
            return true;
        }
        $(this).prop("disabled", false);
        $(this).prop("checked", false);
    });
    form.render();
 
    //初始化批量模板
    initModel();
 
    // 弹出选择框
    layer.open({
        type: 1,
        title: '批量粮情打印(红色表示没有粮情记录,默认为当天)',
        area: ['750px', '450px'],
        shade: 0,
        content: $('#batchPrintSelect'),
        btn: ['全选', '反选', '重选', '执行打印', '取消打印'],
        yes: function () {
            var name;
            $('#batchPrintSelect input').each(function () {
                name = $(this).prop("name");
                if (name == "printCheckDate" || $(this).prop("disabled")) {
                    // doNothing
                } else {
                    $(this).prop("checked", true);
                }
            });
            form.render();
        },
        btn2: function () {
            var name;
            $('#batchPrintSelect input').each(function () {
                name = $(this).prop("name");
                if (name == "printCheckDate" || $(this).prop("disabled")) {
                    // doNothing
                } else {
                    if ($(this).prop("checked")) {
                        $(this).prop("checked", false);
                    } else {
                        $(this).prop("checked", false);
                    }
                }
            });
            form.render();
            return false;
        },
        btn3: function () {
            var name;
            $('#batchPrintSelect input').each(function () {
                name = $(this).prop("name");
                if (name == "printCheckDate" || $(this).prop("disabled")) {
                    // doNothing
                } else {
                    $(this).prop("checked", false);
                }
            });
            form.render();
            return false;
        },
        btn4: function () {
            printBatchTodo();
        },
        btn5: function () {
            layer.close(0);
        },
        closeBtn: 0
    });
    // 默认调用获取数据更新
    $("#printCheckDate").prop("value", dateFtt("yyyy-MM-dd", new Date()));
    getPrintBatchDepot();
};
 
// 获取批量打印的信息
function getPrintBatchDepot() {
    layer.msg("验证粮情检测记录……");
    var checkDate = $("#printCheckDate").val();
    var checkHour = $("#printCheckHour").val();
 
    //console.log(checkTime);
 
    $.ajax({
        type: "POST",
        url: "../../basic/grain/query-checkDate-map",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify({
            checkDate: checkDate,
            checkHour: checkHour
        }),
        success: function (result) {
            if (result.code != "0000") {
                layer.msg(result.msg);
                disabledAllSelectDepot();
            } else {
                mapGrainData = result.data;
                updateSelectDepot();
            }
        },
        error: function () {
            layer.msg("批量打印获取粮情信息失败!");
        }
    });
};
 
// 根据查询的数据批量打印预览
function printBatchTodo() {
    layer.msg("开始批量生成打印模版……");
    var strHtml;
    var value;
    var checked;
    var printGrainData;
    // 将仓库数据列表转换为MAP
    var mapDepot = {};
    $.each(listDepot, function (index, data) {
        mapDepot[data.id] = data;
    });
    var LODOP = CLODOP;
    // 设置默认满张打印
    LODOP.PRINT_INIT("粮情报表");// 初始化在循环外
    LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "A4");
    $('#batchPrintSelect input').each(function () {
        if ($(this).prop("name") == "printCheckDate") {// 跳过
            return true;
        }
        checked = $(this).prop("checked");
        if (checked) {
            value = $(this).val();
            printGrainData = mapGrainData[value];
            if (!printGrainData) {// 如果没有粮情数据跳过执行下一个
                return true;
            }
            LODOP.NewPage();
            printGrainData.depotData = mapDepot[value];
            strHtml = builderModel(printGrainData);
            LODOP.ADD_PRINT_HTM(30, 40, "180mm", "100%", strHtml);
        }
    });
    layer.msg("开始调用打印程序预览……");
    LODOP.SET_PRINT_MODE("PRINT_PAGE_PERCENT", "Full-Page");
    LODOP.PREVIEW();
};
 
// 设置批量打印中所有仓库不可选择
function disabledAllSelectDepot() {
    var name;
    $('#batchPrintSelect input').each(function () {
        name = $(this).prop("name");
        if (name == "printCheckDate") {// 跳过
            return true;
        }
        $(this).prop("disabled", true);
    });
    form.render();
};
 
function updateSelectDepot() {
    var value, name;
    $('#batchPrintSelect input').each(function () {
        value = $(this).val();
        name = $(this).prop("name");
        if (name == "printCheckDate") {// 跳过
            return true;
        }
        if (mapGrainData[value]) {
            $(this).prop("disabled", false);
        } else {
            $(this).prop("disabled", true);
        }
    });
    form.render();
};
 
// 粮情对比
function compare() {
    if (!depotId) {
        layer.msg("请先选择仓库……");
        return;
    }
    var batchId = $("#batchId").val();
    if (!batchId) {
        layer.msg("当前没有可以比较的数据……");
        return;
    }
    // 为了避免重复比较出现的问题,如果已经比较过数据,则在比较前刷新下数据
    if (compareData) {
        flushGrainByBatchId(batchId);
    }
    // 首先弹出层
    layer.open({
        type: 1,
        title: '粮情对比选择',
        area: ['330px', '640px'],
        shade: 0,
        content: $('#compareSelect'),
        btn: ['确认对比', '取消对比'],
        yes: function () {
            if (compareData) {
                layer.msg("开始执行批次对比……");
                compareStep3(grainData, compareData);
            } else {
                layer.msg("没有获取到对比数据!!");
            }
        },
        btn2: function () {
            layer.closeAll();
        },
        closeBtn: 1
    });
 
    $("#compareCheckDate").prop("value", null);
    compareStep2(null);
    form.render();
};
 
function compareStep2(compareDate) {
    depotId = $("#depotId").val();
    if (!depotId) {
        layer.msg("请先选择仓库!");
        return;
    }
    if (!compareDate) {
        compareDate = $("#compareCheckDate").val();
    }
    var data = {
        depotId: depotId,
        checkMonth: compareDate,
        extBatchId: grainData.batchId
    };
    $.ajax({
        type: "POST",
        url: "../../basic/grain/page-list",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(data),
        success: function (result) {
            if (result.code != "0000") {
                layer.msg(result.msg);
            } else {
                table.render({
                    elem: '#tableSelect',
                    height: 450,
                    data: result.data,
                    page: false,
                    limit: 100,
                    skin: "nob",
                    even: true,
                    size: "sm",
                    cols: [[{
                        type: 'radio',
                        fixed: 'left',
                        title: '选择'
                    }, {
                        field: 'receiveDate',
                        title: '检测时间',
                        align: 'center',
                    }]]
                });
            }
        },
        error: function () {
            layer.msg("获取当前仓库检测记录失败,请重新尝试!!");
        }
    });
};
 
// 开始批次对比
function compareStep3(dataA, dataB) {
    $.ajax({
        type: "POST",
        url: "../../basic/grain/data-compare",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify({
            dataA: dataA,
            dataB: dataB
        }),
        success: function (result) {
            if (result.code != "0000") {
                layer.msg(result.msg);
            } else {
                // 覆盖页面中的粮情数据
                grainData = result.data;
                // 显示采集点信息
                resetGrainChart3d();
                // 粮情信息赋值
                renderGrainInfo();
 
                layer.closeAll();
            }
        },
        error: function () {
            layer.msg("批次对比出现异常,请重新选择");
        }
    });
};
 
// 点击刷新操作
function flushGrain(checkMonth) {
    compareData = null;
    depotId = $("#depotId").val();
 
    if (!depotId) {
        layer.alert("请先选择仓库!");
        return;
    }
    var data = {
        depotId: depotId,
        checkMonth: checkMonth
    };
 
    $.ajax({
        type: "POST",
        url: "../../basic/grain/query-list-data",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(data),
        success: function (result) {
            if (result.code != "0000") {
                layer.msg(result.msg);
                clearGrainChart3d();
            }
            listGrainData = result.data;
            if (!listGrainData) {
                return;
            }
            grainData = listGrainData[0];
            // 显示采集点信息
            resetGrainChart3d();
            // 粮情信息赋值
            renderGrainInfo();
            // 在批次选择中添加下拉数据
            resetSelectBatchId();
            // 调用全部关闭
            layer.closeAll();
            layer.msg("更新成功……");
        },
        error: function () {
            layer.msg("根据当前条件获取粮情数据渲染图标失败!!");
        }
    });
};
 
// 填写粮情信息
function renderGrainInfo() {
    // 配置仓库卡片信息
    var depotData = grainData.depotData;
    $("#depotTypeName").text(depotData.depotTypeName);
    $("#storeDate").text(depotData.storeDate);
    $("#storageReal").text(depotData.storageReal);
    $("#foodVarietyName").text(depotData.foodVarietyName);
    $("#perWet").text(depotData.perWet);
    $("#depotStatus").text(DEPOT_STATUS_MSG(depotData.depotStatus));
    $("#foodLocation").text(depotData.foodLocation);
    $("#perImpurity").text(depotData.perImpurity);
    $("#storeKeeperName").text(depotData.storeKeeperName);
 
    // 粮情检测信息赋值
    $("#checkUser").text(grainData.checkUser);
    $("#tempMax").text(grainData.tempMax);
    $("#tempAve").text(grainData.tempAve);
    $("#tempMin").text(grainData.tempMin);
    $("#tempIn").text(grainData.tempIn <= -100.0 ? "--" : grainData.tempIn);
    $("#tempOut").text(grainData.tempOut <= -100.0 ? "--" : grainData.tempOut);
    $("#humidityIn").text(
        grainData.humidityIn <= -100.0 ? "--" : grainData.humidityIn);
    $("#humidityOut").text(
        grainData.humidityOut <= -100.0 ? "--" : grainData.humidityOut);
};
 
// 根据批次更新的值调整
function flushGrainByBatchId(batchId) {
    var temp;
    $.each(listGrainData, function (index, item) {
        if (item.batchId == batchId) {
            temp = item;
            return false;
        }
    });
    if (temp) {
        grainData = temp;
        // 显示采集点信息
        resetGrainChart3d();
        // 粮情信息赋值
        renderGrainInfo();
        layer.msg("更新成功……");
    }
};
 
// 重置批次下拉框
function resetSelectBatchId() {
    // 首先清空原来的值
    $("#batchId").empty();
    // 未下拉框赋值
    $.each(listGrainData, function (index, item) {
        $('#batchId').append(new Option(item.receiveDate, item.batchId));// 下拉菜单里添加元素
    });
    $('#batchId').append(new Option("选择时间……", "0"));
    form.render();
};
 
// 更多批次选择
function showMore() {
    layer.open({
        type: 1,
        title: '选择检测时间',
        area: ['300px', '400px'],
        shade: 0,
        content: $('#dialogMoreSelect'),
        btn: 0,
        closeBtn: 1
    });
};
 
// 单个粮情检测
function checkGrain() {
    if (!depotId) {
        layer.msg("请先选择仓库!");
        return;
    }
    layer.msg("开始执行粮情采集……");
    var data = {
        depotId: depotId
    };
    $.ajax({
        type: "POST",
        url: "../../basic/grain/check-single",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(data),
        success: function (result) {
            if (result.code != "ORDER_SUCCESS") {
                layer.alert(result.msg);
            } else {
                layer.msg("命令已经成功发送,待终端响应……");
                showOrderProgress();
            }
        },
        error: function () {
            layer.alert("粮情检测出现异常,执行失败!");
        }
    });
};
 
// 批量粮情采集
function checkGrainBatch() {
    $('#batchCheckSelect input').each(function () {
        $(this).prop("checked", false);
    });
    form.render();
    // 弹出选择框
    layer.open({
        type: 1,
        title: '批量检测选择仓库',
        area: ['730px', '450px'],
        shade: 0,
        content: $('#batchCheckSelect'),
        btn: ['全选', '反选', '重选', '确定检测', '取消检测'],
        yes: function () {
            $('#batchCheckSelect input').each(function () {
                $(this).prop("checked", true);
            });
            form.render();
        },
        btn2: function () {
            $('#batchCheckSelect input').each(function () {
                if ($(this).prop("checked")) {
                    $(this).prop("checked", false);
                } else {
                    $(this).prop("checked", true);
                }
            });
            form.render();
            return false;
        },
        btn3: function () {
            $('#batchCheckSelect input').each(function () {
                $(this).prop("checked", false);
            });
            form.render();
            return false;
        },
        btn4: function () {
            showOrderProgress();
            return checkBatchTodo();
        },
        btn5: function () {
            layer.close(0);
        },
        closeBtn: 0
    });
};
 
/**
 * 开始执行批量检测
 */
function checkBatchTodo() {
    var depotIds = "";
    $('#batchCheckSelect input').each(function () {
        if ($(this).prop("checked")) {
            depotIds += $(this).val() + ",";
        }
    });
 
    if (depotIds == "") {
        layer.msg("请先选择需要检测的仓库……");
        return false;
    }
    layer.msg("开始执行批量检测……");
    // 调用后台批量检测
    var data = {
        depotIds: depotIds
    };
    $.ajax({
        type: "POST",
        url: "../../basic/grain/check-batch",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(data),
        success: function (result) {
            if (result.code != "ORDER_SUCCESS") {
                layer.alert("执行失败:" + result.msg);
                return false;
            } else {
                layer.msg("命令已经成功发送,待终端响应……");
                return true;
            }
        },
        error: function () {
            layer.alert("粮情检测出现异常,执行失败!");
            return false;
        }
    });
    return true;
};
 
/**
 * 弹出命令执行进度框
 */
var iframeOrderIndex = 0;
 
function showOrderProgress() {
    var domId = "#layui-layer-iframe" + iframeOrderIndex;
    if ($(domId).length == 0) {
        iframeOrderIndex = layer.open({
            type: 2,
            title: "执行进度和记录",
            icon: 1,
            shadeClose: true,
            shade: 0.3,
            closeBtn: 1,
            anim: 2,
            area: ['1000px', '600px'],
            content: '../../basic/grain/order-list?depotId=' + depotId + "&t="
                + Math.random()
        });
    }
}