jiazx0107@163.com
2023-11-04 43ce77a85d8297a53dc25430fff10ead57296167
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
//称重-包括空车和满车称重
var layer;
var form;
var table;
var recordData = null;// 业务数据信息
var snapData;//系统抓拍对象信息
var timerWeight;
var paramIntelCard;//设备识别结果
var paramIdCard;//设备识别结果
var curCheckItems = null;// 当前数据的检查项信息
var step = 1;
 
$(function () {
    layui.use(['layer', 'laydate', 'form', 'table', 'util'], function () {
        var util = layui.util;
        layer = layui.layer;
        form = layui.form;
        table = layui.table;
        layui.laydate.render({
            elem: '#test1',
            theme: '#7b8e9f'
        });
 
        // 右下角添加固定信息
        util.fixbar({
            bar1: true,
            css: {
                right: 10,
                bottom: 20
            },
            bgcolor: '#53adce',
            click: function (type) {
                if (type === 'bar1') {
                    layer.closeAll();
                    layer.open({
                        type: 2,
                        title: false,
                        shadeClose: true,
                        shade: 0.3,
                        closeBtn: 2,
                        offset: ['50px', '120px'],
                        area: ['1000px', '640px'],
                        content: '../../basic/inout/inout-progress?type=' + type + "&t=" + Math.random()
                    });
                }
            }
        });
    });
 
    //显示流程环节
    showProgress();
 
    // 监听重量变化
    $(".weight").blur(function () {
        deAutoByIn(this.name);
    });
 
    // 初始化WebSocket
    initInoutWS(companyId, bizType, progress, userId);
});
 
window.onload = function () {
    //自动连接地磅信息,2.5秒获取一次地磅重量信息
    clearInterval(timerWeight);
    timerWeight = setInterval(function () {
        flushWeight();
    }, 2500);
 
    // 加载视频
    initVideo(snapDto1, snapDto2, snapDto3);
 
    //设置地磅
    $("#scaleName").val(weightDto.sort);
 
    //监听地磅选择
    $("#scaleName").change(function () {
        layer.confirm('调整地磅需重新加载页面,确定调整?', {
            btn: ['确定', '取消']
        }, function () {
            updateWeight();
        });
    });
};
 
// socket信息返回處理
function socketOnMessage(packet) {
    //暂无
}
 
//点击称重
function weight() {
    // 没有业务数据不可执行
    if (!recordData) {
        alertError("没有查询到业务数据,执行被拒绝!");
        return;
    }
    // 如果是空车称重
    if (InoutProgress.WEIGHT_EMPTY == recordData.progress) {
        form.val("form-data", {
            emptyWeight: weightDto.weight
        });
        form.render();
    }
    // 如果是满车称重
    if (InoutProgress.WEIGHT_FULL == recordData.progress) {
        form.val("form-data", {
            fullWeight: weightDto.weight
        });
        form.render();
    }
 
    // 点击称重自动调用抓拍
    snapData = {
        companyId: companyId,
        deptId: deptId,
        progress: recordData.progress,
        bizType: bizType,
        bizId: recordData.id,
        plateNum: recordData.plateNum,
        id1: snapDto1.id,
        id2: snapDto2.id,
        id3: snapDto3.id,
        sort: $("#scaleName").val(),
        weight: weightDto.weight
    };
 
    //当前AJAX服务为同步服务,返回数据包装照片信息
    var index = layer.load();
    $.ajax({
        sync: false,
        type: "POST",
        url: "../../inout/api/snap-img",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(snapData),
        success: function (result) {
            layer.close(index);
            if (result.code != "0000") {
                alertError(result.msg);
            } else {
                snapData = result.data;
            }
        },
        error: function () {
            layer.close(index);
            alertError("后台调用截图失败,请重新尝试");
        }
    });
    //如果是第二次称重,默认执行自动计算
    if (InoutProgress.WEIGHT_EMPTY == recordData.progress) {
        deAutoByIn("emptyWeight");
    }
}
 
//读智慧卡
function flushICCard() {
    if (!cardDto.protocol) {
        flushICCard1();
    } else {
        flushICCard2();
    }
}
 
/**
 * 协议读取智慧卡
 */
function flushICCard2() {
    var index = layer.load();
    var param = JSON.stringify(cardDto);
    $.ajax({
        type: "POST",
        url: "../../inout/api/get-icCard",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: param,
        success: function (result) {
            layer.close(index);
            if (result.code != "0000") {
                alertError(result.msg);
            } else {
                paramIntelCard = data;
                $("#text-param").text("识别卡号:" + paramIntelCard);
                flushData(paramIntelCard, null);
            }
        },
        error: function () {
            layer.close(index);
            alertError("IC卡读取失败");
        }
    });
}
 
/**
 * 本地读取智慧卡
 */
function flushICCard1() {
    var index = layer.load();
    $("#text-param").val(null);
    $("#form-data")[0].reset();
    form.render();
    recordData = null;
    $.ajax({
        type: "GET",
        async: true,
        url: "http://127.0.0.1:9111/ICCARD",
        data: {},
        dataType: "jsonp",
        jsonp: "callback",
        jsonpCallback: "jsonpCallback",
        success: function (json) {
            var data = json.no;
            layer.close(index);
            if (data === "not found") {
                alertError("请重新读卡!");
            } else {
                paramIntelCard = data;
                $("#text-param").text("识别卡号:" + paramIntelCard);
                flushData(paramIntelCard, null);
            }
        },
        error: function () {
            layer.close(index);
            alertError("IC卡读取出错!");
        }
    });
}
 
// 使用插件获取身份证
function flushIdCard() {
    var index = layer.load();
    $.ajax({
        type: "GET",
        async: true,
        url: "http://127.0.0.1:9111/IDCARD",
        data: {},
        dataType: "jsonp",
        jsonp: "callback",
        jsonpCallback: "jsonpCallback",
        success: function (json) {
            layer.close(index);
            var data = json.content;
            if (data === "not found") {
                alertError("没有读取到身份证信息!");
                return;
            }
            paramIdCard = data;
            $("#text-param").text("识别身份证:" + paramIdCard);
            flushData(null, paramIdCard);
        },
        error: function () {
            alertError("没有读取到身份证信息!");
            layer.close(index);
        }
    });
}
 
function flushByHand() {
    var intelCard = $("#intelCard").val();
    flushData(intelCard, null);
}
 
function flushWeight() {
    $.ajax({
        type: "GET",
        async: true,
        timeout: 2000,
        url: "http://127.0.0.1:9111/WEIGHT",
        data: {},
        dataType: "jsonp",
        jsonp: "callback",
        jsonpCallback: "jsonpCallback",
        success: function (json) {
            var data = json.content;
            if (!data) data = 0.0;
            weightDto.weight = data;
            $("#weightValue").text(data);
            $("#img_scale_statule").attr("src", "../../static/images/icon-gree.png");
        },
        error: function () {
            weightDto.weight = 0.0;
            $("#weightValue").text("0.0");
            $("#img_scale_statule").attr("src", "../../static/images/icon-red.png");
        }
    });
}
 
 
// 点击打印,系统判断是否已经执行完成,如果已经完成,直接打印,如果未完成则先执行完成
function printBill() {
    if (!recordData) {
        alertError("没有获取到业务数据,打印被拒绝!");
        return;
    }
    // 从后台获取模版并打印
    var data = form.val("form-data");
    // 合并更新當前编辑数据
    Object.assign(recordData, data);
 
    var index = layer.load();
    $.ajax({
        type: "POST",
        url: "../../basic/inout/report/bill-weight",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(recordData),
        success: function (result) {
            layer.close(index);
            if (result.code != "0000") {
                alertError(result.msg);
            } else {
                layer.msg("开始渲染打印单……");
                printWeight(result.data);
            }
        },
        error: function () {
            layer.close(index);
            alertError("获取打印模版失败,请联系管理员查看原因");
        }
    });
}
 
// 表单清空
function resetForm() {
    $("#form-data")[0].reset();
    form.render();
    recordData = null;
    weightDto.weight = 0.0;
    $("#weightValue").text("0.0");
    $("#img_scale_statule").attr("src", "../../static/images/icon-red.png");
 
    $("#text-param").val(null);
}
 
function flushPage() {
    layer.confirm('确定要刷新页面吗?', {icon: 3, title: '提示'}, function (index) {
        resetForm();
        layer.close(index);
    });
}
 
// --查询方法,获取身份证号、卡号、车牌号,进行查询
function flushData(intelCard, userIdCard) {
    var index = layer.load();
    var userIdCard = userIdCard;
    var intelCard = intelCard;
    var plateNum = $("#plateNum").val();
    var param = {
        type: type,
        progress: progress,
        intelCard: intelCard,
        userId: userIdCard,
        plateNum: plateNum
    };
    $.ajax({
        type: "POST",
        url: "../../basic/inout/inout-query",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(param),
        success: function (result) {
            layer.close(index);
            if (result.code != "0000") {
                notifyProgress(result.msg, result.data);
            } else {
                recordData = result.data;
                // 返回的数据进行赋值
                form.val("form-data", recordData);
                form.render();
 
                updateEditAndProgress();
            }
        },
        error: function () {
            layer.close(index);
            alertError("查询失败,请重新尝试");
        }
    });
}
 
 
/**
 * 根据业务数据更新页面中的状态
 */
function updateEditAndProgress() {
    if (!recordData) return true;
    var curProgress = recordData.progress;
 
    //空车称重
    if (InoutProgress.WEIGHT_EMPTY == curProgress) {
        $("#progress-hand").addClass("active");
        $("#progress-emptyWeight").addClass("active");
 
        $("#depotIdLabel").removeClass("color-red");
    }
 
    //满车称重
    if (InoutProgress.WEIGHT_FULL == curProgress) {
        $("#progress-hand").removeClass("active");
        $("#progress-emptyWeight").removeClass("active");
 
        //装卸仓库必填
        $("#depotIdLabel").addClass("color-red");
    }
 
    //设置可编辑
    if (weightEditTag == 'Y') {
        $("#fullWeight").removeClass("rkbk-search-input");
        $("#fullWeight").attr("disabled", false);
 
        $("#emptyWeight").removeClass("rkbk-search-input");
        $("#emptyWeight").attr("disabled", false);
    }
}
 
// 当前完成
function submit() {
    if (!recordData) {
        alertError("没有业务数据信息,执行被拒绝");
        return;
    }
    var data = form.val("form-data");
 
    if (!data.depotId) {
        alertError("提示:装卸仓库必填");
        return;
    }
    if (!data.customerName) {
        alertError("提示:客户名称必填");
        return;
    }
 
    // 校验-入库满车称重
    if (InoutProgress.WEIGHT_FULL == recordData.progress) {
        if (data.fullWeight <= 0.0) {
            alertError("提示:满车称重信息必填");
            return;
        }
    }
    if (InoutProgress.WEIGHT_EMPTY == recordData.progress) {
        if (data.emptyWeight <= 0.0) {
            alertError("提示:空车称重信息必填");
            return;
        }
        if (!data.foodVariety) {
            alertError("提示:粮食品种必填");
            return;
        }
 
        if (!data.settleWeight || data.settleWeight <= 0.0) {
            alertError("结算重量不合规,请核对");
            return;
        }
        if (!data.recordWeight || data.recordWeight <= 0.0) {
            alertError("入库重量不合规,请核对");
            return;
        }
    }
 
    //合并数据
    Object.assign(recordData, data);
 
    // 获取照片
    var files = [{
        fileName: snapData.fileName1
    }, {
        fileName: snapData.fileName2
    }, {
        fileName: snapData.fileName3
    }];
    recordData.files = files;
 
    var index = layer.load();
    $.ajax({
        type: "POST",
        url: "../../basic/inout/submit-weight",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(recordData),
        success: function (result) {
            if (result.code != "0000") {
                alertError(result.msg);
            } else {
                notify("数据提交成功", result.data);
            }
            layer.close(index);
        },
        error: function () {
            layer.close(index);
            alertError("提交失败,请重新尝试");
        }
    });
}
 
//显示质检信息
function showCheck() {
    if (!recordData) {
        alertError("没有业务数据信息,执行被拒绝");
        return;
    }
 
    // 获取化验项信息
    flushCheckItem();
 
    layer.open({
        type: 1,
        title: "质检详细",
        offset: ['120px', '100px'],
        area: ['1000px', '520px'],
        shade: 0,
        content: $('#checkDetail'),
        btnAlign: 'c',
        btn: ['取消'],
        yes: function () {
            layer.closeAll();
        },
        closeBtn: 0
    });
}
 
/**
 * 刷新化验结果项
 */
function flushCheckItem() {
 
    curCheckItems = null;
    $.ajax({
        type: "POST",
        url: "../../basic/inout/get-check-item",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(recordData),
        success: function (result) {
            if (result.code != "0000") {
                layer.msg(result.msg);
            } else {
                curCheckItems = result.data;
 
                // 页面渲染检测项
                renderTableCheckItem();
            }
        },
        error: function () {
            layer.msg("后台异常,请重试或者联系管理员!!");
        }
    });
}
 
/**
 * 弹出提醒框
 * @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']});
    }
}
 
/**
 * 渲染表格
 */
function renderTableCheckItem() {
    // 清空数据
    $("#tableCheckItem").empty();
    table.render({
        elem: '#tableCheckItem',
        data: curCheckItems,
        page: false,
        even: true,
        cols: [[{
            field: 'standardName',
            title: '检验项目',
            align: 'center',
            width: '13%'
        }, {
            field: 'value',
            title: '检验值',
            align: 'center',
            width: '9%'
        }, {
            field: 'operaSymbolValue',
            title: '标准值',
            align: 'center',
            width: '10%'
        }, {
            field: 'unit',
            title: '单位',
            align: 'center',
            width: '10%'
        }, {
            field: 'deNum',
            title: '扣重',
            align: 'center',
            width: '9%'
        }, {
            field: 'addNum',
            title: '增重',
            align: 'center',
            width: '9%'
        }, {
            field: 'dePrice',
            title: '扣价',
            align: 'center',
            width: '9%'
        }, {
            field: 'addPrice',
            title: '增价',
            align: 'center',
            width: '9%'
        }, {
            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'
        }]]
    });
 
    $("thead tr").css({
        "border-bottom": "2px solid #53adce",
        "background": "#eff4f6"
    });
}