YYC
2023-07-12 ac8862d883ce562a4f263ee01acaf40ca6091538
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
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
//当前节点 入库质检
var layer;
var laydate;
var form;
var table;
var scanCodeTag = false;
var page = 1;
var limit = 10;
var curCheckData = null;// 当前编辑数据
var curCheckItems = null;// 当前数据的检查项信息
 
$(function () {
    layui.use(['layer', 'laydate', 'form', 'table'], function () {
        layer = layui.layer;
        form = layui.form;
        table = layui.table;
        laydate = layui.laydate;
 
        laydate.render({
            elem: '#start',
            theme: '#7b8e9f',
            value: startTime
        });
 
        laydate.render({
            elem: '#end',
            theme: '#7b8e9f',
            value: endTime
        });
 
        laydate.render({
            elem: '#foodYear',
            theme: '#7b8e9f',
            value: foodYear,
            type: 'year'
        });
 
        laydate.render({
            elem: '#checkTime',
            theme: '#7b8e9f',
            format: 'yyyy-MM-dd HH:mm:ss',
            type: 'datetime'
        });
 
        // 初始化表单数据
        renderTable();
 
        // 监听行工具事件
        table.on('tool(tableData)', function (obj) {
            if (obj.event === 'edit') {
                //更新仓库下拉列表
                updateSelect();
                //展示数据
                showDetail(obj.data);
            }
        });
 
        //监听粮食品种,获取化验项
        layui.form.on('select(select_foodVariety)', function (data) {
            updateFoodVariety(data.value);
        });
 
        //监听粮食等级,获取粮食定价
        layui.form.on('select(select_foodLevel)', function (data) {
            getPriceByFoodLevel(data.value);
        });
 
        //监听化验结果单填写数据,并给出提示结果
        table.on('edit(tableCheckItem)', function (obj) {
            getResult(obj);
        });
    });
 
    //显示入库流程
    showProgress();
});
window.onbeforeunload = function () {
}
 
window.onunload = function () {
}
window.onload = function () {
 
    //扫描枪自动回车事件
    $('#checkId').bind('keyup', function (event) {
        if (event.keyCode == "13") {
            // //去掉焦点,防止刷新页面
            // $('#checkId').blur();
            getDataByCheckId();
        }
    });
};
 
// socket信息返回處理
function socketOnMessage(packet) {
    layer.alert(packet.data);
    window.parent.sysNotify(packet.data);
}
 
//控制流程环节显示
function showProgress() {
    if (!inoutProgress) {
        return;
    }
    if (inoutProgress.indexOf("REGISTER") == -1) {
        $("#progress-register").css("display", "none");
    }
    if (inoutProgress.indexOf("CHECK") == -1) {
        $("#progress-check").css("display", "none");
    }
    if (inoutProgress.indexOf("WEIGHT_FULL") == -1) {
        $("#progress-fullWeight").css("display", "none");
    }
    if (inoutProgress.indexOf("HANDLE") == -1) {
        $("#progress-hand").css("display", "none");
    }
    if (inoutProgress.indexOf("WEIGHT_EMPTY") == -1) {
        $("#progress-emptyWeight").css("display", "none");
    }
    if (inoutProgress.indexOf("CARD_BACK") == -1) {
        $("#progress-cardBack").css("display", "none");
    }
}
 
//根据填写化验数据,给出提醒是否合格
function getResult(obj) {
    var data = obj.data;
    //填写的数据值
    var newValue = data.value;
    //标准值
    var limit = data.upperLimit;
    //运算符
    var symbol = data.operaSymbol;
    if (symbol && limit) {
        if (">=" == symbol) {
            if (newValue < limit) {
                data.result = "0";
            } else {
                data.result = "1";
            }
        }
        if ("<=" == symbol) {
            if (newValue > limit) {
                data.result = "0";
            } else {
                data.result = "1";
            }
        }
        if ("==" == symbol) {
            if (newValue != limit) {
                data.result = "0";
            } else {
                data.result = "1";
            }
        }
    }
    obj.update(data);
    //根据化验结果提醒是否合格
    updateCheckResultTip();
}
 
//动态更换仓库下拉列表
function updateSelect() {
    $('#depotId option').remove();
    for (var i = 0; i < listDepot.length; i++) {
        $('#depotId').append('<option value="' + listDepot[i].id + '">' + listDepot[i].name + '</option>');
    }
    //重新渲染
    form.render('select');
}
 
//根据品种获取化验项
function updateFoodVariety(foodVariety) {
    if (null == foodVariety || "" == foodVariety) return;
    form.val("form-detail", {
        foodVariety: foodVariety
    });
    form.render();
 
    flushCheckItem(foodVariety);
}
 
//根据选择仓库显示粮食品种
function getPriceByFoodLevel(foodLevel) {
    if (null == foodLevel || "" == foodLevel) return;
    form.val("form-detail", {
        foodLevel: foodLevel
    });
    form.render();
    var data = form.val("form-detail");
 
    $.ajax({
        type: "POST",
        url: "../../basic/inout/get-price",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(data),
        success: function (result) {
            if (result.code != "0000") {
                layer.msg(result.msg);
            } else {
                $("#check-result-tip2").text("粮食定价:" + result.data.price + "元/公斤");
            }
        },
        error: function () {
            layer.msg("后台异常,请重试或者联系管理员!!");
        }
    });
}
 
// 查询
function flushData() {
    var index = layer.load();
    var param = form.val("form-param");
 
    table.reload('tableData', {
        url: "../../basic/inout/page-check-data",
        where: param,
    });
 
    $("thead tr").css({
        "border-bottom": "2px solid #53adce",
        "background": "#eff4f6"
    });
    layer.close(index);
};
 
// 导出数据-- 跳转新页面处理
function exportData() {
    // var url = "com.ld.igds.inout.ReportInoutCheck.d";
    // window.parent.openTab(url, "化验结果导出", "checkDataExport");
};
 
// 扦样机解除急停
function checkResetStop() {
    var param = JSON.stringify(checkDto);
    var index = layer.load();
    $.ajax({
        type: "POST",
        url: "../../api/check/reset-stop",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: param,
        success: function (result) {
            layer.close(index);
            if (result.code != "0000") {
                layer.alert(result.msg);
            } else {
                layer.msg("操作命令发送成功!");
            }
        },
        error: function () {
            layer.close(index);
            layer.alert("后台异常,操作命令发送失败!");
        }
    });
};
 
// 更新化验结果提醒,只做提醒,不做自动判断
function updateCheckResultTip() {
    if (!curCheckItems || curCheckItems.length == 0) {
        return;
    }
    if (curCheckData.checkStatus != "NONE") {
        return;
    }
    var msg;
    $.each(curCheckItems, function (index, data) {
        if (!data.result) {
            return true;
        }
        if (data.result == "0") {
            msg = "不合格";
            return false;
        }
        if (data.result == "1") {
            msg = "合格";
        }
    });
    if (msg) {
        $("#check-result-tip").text("质检结果:" + msg);
    } else {
        $("#check-result-tip").text("质检结果:#");
    }
}
 
/**
 * 渲染表格
 */
function renderTableCheckItem() {
    // 清空数据
    $("#tableCheckItem").empty();
    table.render({
        elem: '#tableCheckItem',
        data: curCheckItems,
        page: false,
        // skin: 'line',
        even: true,
        cols: [[{
            field: 'standardName',
            title: '检验项目',
            align: 'center',
            width: '10%'
        }, {
            field: 'value',
            title: '检验值',
            align: 'center',
            width: '10%',
            edit: 'text'
        }, {
            field: 'operaSymbolValue',
            title: '标准值',
            align: 'center',
            width: '10%'
        }, {
            field: 'unit',
            title: '单位',
            align: 'center',
            width: '10%'
        }, {
            field: 'deNum',
            title: '扣重',
            align: 'center',
            width: '10%',
            edit: 'text'
        }, {
            field: 'addNum',
            title: '增重',
            align: 'center',
            width: '10%',
            edit: 'text'
        }, {
            field: 'dePrice',
            title: '扣价',
            align: 'center',
            width: '10%',
            edit: 'text'
        }, {
            field: 'addPrice',
            title: '增价',
            align: 'center',
            width: '10%',
            edit: 'text'
        }, {
            field: 'result',
            title: '检验结果',
            align: 'center',
            width: '10%',
            templet: function (item) {
                if (item.result == null) {
                    return "";
                }
                if (item.result == '0') {
                    return "不合格";
                }
                if (item.result == '1') {
                    return "合格";
                }
            }
        }, {
            field: 'remarks',
            title: '备注说明',
            align: 'center',
            edit: 'text'
        }]]
    });
 
    $("thead tr").css({
        "border-bottom": "2px solid #53adce",
        "background": "#eff4f6"
    });
}
 
function showDetail(data) {
    curCheckData = data;
    if (!curCheckData.checkTime) {
        curCheckData.checkTime = dateFtt("yyyy-MM-dd hh:mm:ss", new Date());
    }
    curCheckData.checkUser = checkUser;
 
    // 赋值
    form.val("form-detail", curCheckData);
    form.render();
 
    layer.open({
        type: 1,
        title: "化验单明细",
        area: ['1400px', '700px'],
        shade: 0,
        content: $('#checkDetail'),
        btnAlign: 'c',
        btn: ['仅保存', '保存提交', '关闭取消'],
        yes: function () {
            // 更新到页面
            var data = form.val("form-detail");
            // 合并更新當前编辑数据
            Object.assign(curCheckData, data);
            saveCheckData();
            if (scanCodeTag) {
                showScanCode();
            }
        }, btn2: function () {
            // 更新到页面
            var data = form.val("form-detail");
            // 合并更新當前编辑数据
            Object.assign(curCheckData, data);
            submit();
            if (scanCodeTag) {
                showScanCode();
            }
        }, btn3: function () {
            parent.layer.closeAll();
            if (scanCodeTag) {
                showScanCode();
            }
        },
        closeBtn: 0
    });
    // 获取化验项信息
    flushCheckItem(curCheckData.foodVariety);
    getPriceByFoodLevel(curCheckData.foodLevel);
}
 
/**
 * 刷新化验结果项
 */
function flushCheckItem(foodVariety) {
    curCheckItems = null;
    $("#check-result-tip").text("检验结果:#");
    $("#price-result-tip2").text("粮食定价:#元/公斤");
    curCheckData.foodVariety = foodVariety;
    var index = layer.load();
    $.ajax({
        type: "POST",
        url: "../../basic/inout/get-check-item",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(curCheckData),
        success: function (result) {
            if (result.code != "0000") {
                layer.msg(result.msg);
            } else {
                curCheckItems = result.data;
                // 根据化验结果提醒是否合格
                updateCheckResultTip();
                // 页面渲染检测项
                renderTableCheckItem();
                layer.close(index);
            }
        },
        error: function () {
            layer.close(index);
            layer.msg("后台异常,请重试或者联系管理员!!");
        }
    });
};
 
//仅保存
function saveCheckData() {
    if (!curCheckData.foodVariety) {
        layer.alert("请确认粮食品种!!");
        return;
    }
    curCheckData.checkItems = curCheckItems;
    var index1 = layer.load();
    $.ajax({
        type: "POST",
        url: "../../basic/inout/submit-checkItem",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        async: false,
        data: JSON.stringify(curCheckData),
        success: function (result) {
            if (result.code != "0000") {
                layer.close(index1);
                notify(result.msg, result.data);
            } else {
                layer.closeAll();
                curCheckData = null;
                notify("数据保存成功", result.data);
                flushData();
            }
        },
        error: function () {
            layer.close(index1);
            layer.alert("保存失败,请重新尝试!");
        }
    });
}
 
//保存提交
function submit() {
    if (curCheckData.checkStatus == "NONE" || curCheckData.checkStatus == "NONE2") {
        layer.alert("请确认化验结果!!");
        return;
    }
    if (!curCheckData.foodVariety) {
        layer.alert("请确认粮食品种!!");
        return;
    }
    if (!curCheckData.foodLevel) {
        layer.alert("请确认粮食等级!!");
        return;
    }
    if (!curCheckData.price) {
        layer.alert("请确认粮食定价,如不考虑定价,请填写0.0");
        return;
    }
    curCheckData.checkItems = curCheckItems;
 
    var index = layer.load();
    $.ajax({
        type: "POST",
        url: "../../basic/inout/submit-check",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        async: false,
        data: JSON.stringify(curCheckData),
        success: function (result) {
            if (result.code != "0000") {
                layer.close(index);
                notify(result.msg, result.data);
            } else {
                parent.layer.closeAll();
                curCheckData = null;
                notify("数据提交成功", result.data);
                flushData();
            }
        },
        error: function () {
            layer.close(index);
            layer.alert("提交失败,请重新尝试!");
        }
    });
}
 
//扫码弹窗
function showScanCode() {
    //清空表单
    $("#form-sacnCodeDetail")[0].reset();
    form.render();
 
    //扫码弹窗-赋值true
    scanCodeTag = true;
    layer.open({
        type: 1,
        title: "扫码信息",
        area: ['700px', '320px'],
        shade: 0,
        content: $('#scanCodeDetail'),
        success: function () {
            document.getElementById('checkId').focus();
        },
        btnAlign: 'c',
        btn: ['查询', '关闭取消'],
        yes: function () {
            getDataByCheckId();
        }, btn2: function () {
            scanCodeTag = false;
            layer.closeAll();
        },
        closeBtn: 0
    });
}
 
//根据质检单号获取信息
function getDataByCheckId() {
    var param = form.val("form-sacnCodeDetail");
    if (!param.checkId) {
        layer.alert("质检单号为空,请扫码或输入质检单号");
    }
    var index = layer.load();
    $.ajax({
        type: "POST",
        url: "../../basic/inout/inout-check-scan-code",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(param),
        success: function (result) {
            if (result.code != "0000") {
                layer.close(index);
                $("#form-sacnCodeDetail")[0].reset();
                form.render();
                notify(result.msg, result.data);
            } else {
                updateSelect();
                showDetail(result.data);
            }
        },
        error: function () {
            layer.close(index);
            $("#form-sacnCodeDetail")[0].reset();
            form.render();
            alertError("保存失败,请重新尝试!")
        }
    });
}
 
// 渲染表单数据
function renderTable() {
    var param = form.val("form-param");
    // 清空数据
    $("#tableData").empty();
    table.render({
        elem: '#tableData',
        url: '../../basic/inout/page-check-data',
        page: true,
        limit: limit,
        even: true,
        method: 'POST',
        contentType: "application/json;charset=UTF-8",
        cols: [[{
            field: 'checkId',
            title: '质检单号',
            width: '10%',
            style: 'color: #f67d06;font-weight: bold'
        }, {
            field: 'registerTime',
            title: '登记时间',
            width: '15%',
            style: 'font-weight: bold'
        }, {
            field: 'sampleStatus',
            title: '是否扦样',
            width: '10%',
            templet: function (item) {
                if (item.sampleStatus == null) {
                    return "未扦样";
                }
                if (item.sampleStatus == 'NONE') {
                    return "未扦样";
                }
                if (item.sampleStatus == 'SAMPLE') {
                    return "已扦样";
                }
            }
        }, {
            field: 'sampleUser',
            title: '扦样人',
            width: '10%',
            style: 'font-weight: bold'
        }, {
            field: 'sampleTime',
            title: '扦样时间',
            width: '15%',
            style: 'font-weight: bold'
        }, {
            field: 'foodVariety',
            title: '粮食品种',
            width: '11%',
            templet: function (item) {
                var result = item.foodVariety;
                $.each(listFoodVariety, function (index, data) {
                    if (item.foodVariety == data.code) {
                        result = data.name;
                        return true;
                    }
                });
                return result == null ? "" : result;
            }
        }, {
            field: 'depotId',
            title: '装卸仓库',
            width: '11%',
            templet: function (item) {
                var result = item.depotId;
                $.each(listDepot, function (index, data) {
                    if (item.depotId == data.id) {
                        result = data.name;
                        return true;
                    }
                });
                return result == null ? "" : result;
            }
        }, {
            field: 'checkStatus',
            title: '检验结果',
            style: 'font-weight: bold',
            templet: function (item) {
                if (item.checkStatus == 'NONE') {
                    return "未化验";
                }
                if (item.checkStatus == 'PASS') {
                    return "合格";
                }
                if (item.checkStatus == 'UNPASS') {
                    return "不合格";
                }
                return item.checkStatus == null ? "" : item.checkStatus;
            }
        }, {
            field: '',
            title: '操作',
            width: '8%',
            toolbar: "#barControl"
        }]],
        where: param,
        parseData: function (res) {
            if ("0000" == res.code) {
                return {
                    "code": "0",
                    "msg": res.msg,
                    "count": res.data.total,
                    "data": res.data.records
                }
            } else {
                return {
                    "code": "1",
                    "msg": res.msg
                }
            }
        }
    });
    $("thead tr").css({
        "border-bottom": "2px solid #53adce",
        "background": "#eff4f6"
    });
}
 
// 表单清空
function resetForm() {
    $("#form-param")[0].reset();
    form.render();
}
 
// ---------------------------粮食产地 -开始 -------------------//
// 弹出粮食产地下拉框
function showFoodLocation() {
    var index = layer.load();
    // 渲染往来单位列表
    table.render({
        elem: '#tableFoodLoaction',
        url: '../../basic/common/page-food-location',
        page: false,
        toolbar: '#toolbarFoodLocaton',
        even: true,
        method: 'POST',
        contentType: "application/json;charset=UTF-8",
        cols: [[{
            field: 'code',
            title: '编码',
        }, {
            field: 'simple',
            title: '简拼',
        }, {
            field: 'name',
            title: '名称',
            width: '60%'
        }]],
        where: {
            "page": 1,
            "limit": 100
        },
        parseData: function (res) {
            if ("0000" == res.code) {
                return {
                    "code": "0",
                    "msg": res.msg,
                    "count": res.data.total,
                    "data": res.data.records
                }
            } else {
                return {
                    "code": "1",
                    "msg": res.msg
                }
            }
        },
        done: function (res) {
            layer.close(index);
        }
    });
 
    //双击显示选中数据
    table.on('rowDouble(tableFoodLoaction)', function (obj) {
        var data = obj.data;
        // 赋值
        form.val("form-detail", {
            foodLocation: data.name,
        });
        // 关闭
        layer.close(index2);
    });
 
    // 弹出对话框
    var index2 = layer.open({
        type: 1,
        title: "选择粮产地",
        area: ['600px', '600px'],
        shade: 0,
        content: $('#listFoodLocation'),
        btn: 0,
        btn: ['取消'],
        yes: function () {
            // 关闭
            layer.close(index2);
        },
        closeBtn: 0
    });
 
};
 
// 刷新
function flushFoodLocation() {
    var key = $("#key2").val();
    table.reload('tableFoodLoaction', {
        url: "../../basic/common/page-food-location",
        where: {
            key: key
        },
        done: function (res) {
            if (key) {
                $("#key2").val(key);
            }
        }
    });
};
 
/**
 * 弹出提醒框
 * @param msg 提醒信息
 * @param data 数据信息,可能为空
 */
function notify(msg, data) {
    if (data) {
        //赋值
        $("#resultMsg").text(msg);
        $("#resultUserName").text(data.userName);
        $("#resultPlateNum").text(data.plateNum);
        if ("IN" == data.type) {
            $("#resultType").text("入库-" + INOUT_PROGRESS_MSG(data.progress));
        } else {
            $("#resultType").text("出库-" + INOUT_PROGRESS_MSG(data.progress));
        }
        $("#resultIntelCard").text(data.intelCard);
 
        layer.open({
            type: 1,
            offset: ['150px', '200px'],
            area: '450px;',
            shade: 0.8,
            id: 'dialog_notify_info',
            btn: ['确定'],
            content: $('#dialog-from-notify'),
            yes: function (index) {
                layer.closeAll();
            }
        });
    } else {
        layer.alert(msg, {offset: ['300px', '300px']});
    }
}
 
// ---------------------------粮食产地 -结束 -------------------//