自动化立体仓库 - WMS系统
#
zyx
2024-05-31 757a911bb0c49ecc893cccdafce70d2fd46b4e7c
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
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
var initCountVal = 0;
var initAnfmeVal = "-";
var matCodeData = [];
var currLocNo;
var matCodeLayerIdx;
var data = [];
var checkStatus = [];
var dataCheck = [];
var admin;
var printData = [];
var layDate;
function getCol() {
    var cols = [
        {field: 'id', title: 'id', align: 'center',hide:true}
        ,{type: 'checkbox',totalRow:true}
        ,{field:'id', width:80, title: '', sort: true, totalRowText: '合计:',hide: true}
        ,{field: 'pakinTime$', title: '入库时间', align: 'center' , sort:true}
        ,{field: 'matnr', align: 'center',title: '存货编码',hide:true,edit:true}
        ,{field: 'brand', align: 'center',title: '牌号',edit:true}
        ,{field: 'batch', align: 'center',title: '批号',edit:true, width: 150, sort:true}
        ,{field: 'packageNo', align: 'center',title: '包装号',edit:true, sort:true}
        ,{field: 'proDate', align: 'center',title: '生产日期',edit:true, width: 100}
        ,{field: 'weight', align: 'center',title: '重量KG',edit:true,totalRow:true}
        ,{field: 'filmWrap', align: 'center',title: '缠膜',edit:true,hide:true}
        ,{field: 'fingerMelting', align: 'center',title: '熔指,g/10min',edit:true}
        ,{field: 'water', align: 'center',title: '水分,ppm', hide:true,edit:true}
        ,{field: 'fusingPoint', align: 'center',title: '熔点,℃',edit:true}
        ,{field: 'vadf1', align: 'center',title: '挥发段,%', hide:true,edit:true}
        ,{field: 'vadf2', align: 'center',title: '分解段,%', hide:true,edit:true}
        ,{field: 'yellowness', align: 'center',title: '黄度',edit:true}
        ,{field: 'opacity', align: 'center',title: '不透明度,%',edit:true}
        ,{field: 'l', align: 'center',title: 'L*', hide:true,edit:true}
        ,{field: 'a', align: 'center',title: 'a*', hide:true,edit:true}
        ,{field: 'b', align: 'center',title: 'b*', hide:true,edit:true}
        ,{field: 'fillIn', align: 'center',title: '填充,%',hide:true,edit:true}
        ,{field: 'str1', align: 'center',title: '拉伸强度,MPa',hide:true,edit:true}
        ,{field: 'str2', align: 'center',title: '断裂伸长率,%',hide:true,edit:true}
        ,{field: 'str3', align: 'center',title: '缺口冲击,KJ/m2',hide:true,edit:true}
        ,{field: 'str4', align: 'center',title: '维卡,℃',hide:true,edit:true}
        ,{field: 'str5', align: 'center',title: '半结晶时间,min',hide:true,edit:true}
        ,{field: 'str6', align: 'center',title: '结晶度,%',hide:true,edit:true}
        ,{field: 'packageType', align: 'center',title: '包装类型',edit:true}
        ,{field: 'zpalletType', align: 'center',title: '托盘类型',edit:true}
        ,{field: 'massState', align: 'center',title: '质量状态',edit:true}
        ,{field: 'problem', align: 'center',title: '备注',edit:true,hide:true}
        ,{field: 'direction', align: 'center',title: '应用方向',edit:true,hide:true}
        ,{field: 'position', align: 'center',title: '存放位置',edit:true,hide:true}
        ,{field: 'stash', align: 'center',title: '仓库',edit:true,hide:true}
        ,{field: 'locNo', align: 'center',title: '库位',edit:true}
        ,{field: 'owner', align: 'center',title: '主体',edit:true}
        ,{field: 'type', align: 'center',title: '物资类别',hide:true,edit:true}
        ,{field: 'proOrderNo', align: 'center',title: '生产订单编号',hide:true,edit:true}
        ,{field: 'workshop', align: 'center',title: '生产车间',hide:true,edit:true}
        ,{field: 'line', align: 'center',title: '生产线',hide:true,edit:true}
        ,{field: 'weightAnfme', align: 'center',title: '剩余重量(KG)',edit:true,totalRow:true}
        ,{field: 'qtyAnfme', align: 'center',title: '待出库重量(KG)',hide:true}
        ,{field: 'status', align: 'center',title: '状态', templet: setState ,edit:true}
        ,{field: 'stockFreeze', align: 'center',title: '库存冻结', templet: '#stockFreezeTpl'}
        ,{field: 'stockFreezeBy', align: 'center',title: '操作人员',hide:true}
        ,{field: 'stockFreezeDate$', align: 'center',title: '操作日期',hide:true}
        ,{align: 'center', title: '流转明细', toolbar: '#tbLook'}
        ,{field: 'createTime$', title: '创建时间', align: 'center' , sort:true}
        ,{field: 'newBrand', align: 'center',title: '关联牌号',edit:true}
        ,{field: 'newBatch', align: 'center',title: '关联批号',edit:true, width: 150, sort:true}
        ,{field: 'newPackageNo', align: 'center',title: '关联包装号',edit:true, sort:true}
        // ,{field: 'orderNo', align: 'center',title: '单号', hide:true}
        // ,{field: 'pakoutTime', align: 'center',title: '出库时间', hide:true}
        // ,{field: 'orderWeight', align: 'center',title: '重量', hide:true}
        // ,{field: 'handlerBy', align: 'center',title: '经办人', hide:true}
        // ,{field: 'transfer', align: 'center',title: '流转形式', hide:true}
        // ,{field: 'customer', align: 'center',title: '客户名称', hide:true}
        // ,{field: 'allocate', align: 'center',title: '调拨到', hide:true}
        // ,{field: 'memo', align: 'center',title: '备注', hide:true}
    ];
    return cols;
}
 
function setState(data){
    if(data.status === "待入库"){
        return  "<span style='color: orange'>待入库</span>"
    }else if(data.status === "已入库"){
        return  "<span style='color: blue'>已入库</span>"
    }else if(data.status === "待出库"){
        return  "<span style='color: red'>待出库</span>"
    }else if(data.status === "部分出库"){
        return  "<span style='color: black'>部分出库</span>"
    }else if(data.status === "全部出库"){
        return  "<span style='color: gray'>全部出库</span>"
    }else if(data.status === "暂入库"){
        return  "<span style='color: purple'>暂入库</span>"
    }
}
 
layui.config({
    base: baseUrl + "/static/layui/lay/modules/"
}).use(['table','laydate', 'form', 'admin', 'xmSelect', 'dropdown'], function() {
    var dropdown = layui.dropdown;
    var table = layui.table;
    var $ = layui.jquery;
    var layer = layui.layer;
    laydate = layui.laydate;
    var form = layui.form;
    admin = layui.admin;
 
    // 日期时间范围
    laydate.render({
        elem: '#ID-laydate-range-datetime',
        type: 'datetime',
        range: true
    });
 
 
    // 数据渲染
    tableIns = table.render({
        elem: '#plaDetl',
        headers: {token: localStorage.getItem('token')},
        url: baseUrl+'/pla/list/auth?step=2',
        page: true,
        totalRow: true, // 开启合计行
        height: function(){
            var otherHeight = $('.function-area').outerHeight() + $('#search-box').outerHeight(); // 自定义其他区域的高度
            console.log($(window).height() - otherHeight);
            return $(window).height() - otherHeight - 100; // 返回 number 类型
        },
        //height: 'full',
        limit: 16,
        limits: [16, 50, 100, 200, 500,2000,5000,10000],
        even: true,
        toolbar: '#toolbar',
        cellMinWidth: 50,
        cols: [function(){
            var arr = getCol();
 
            // 初始化筛选状态
            var local = layui.data('table-filter-test'); // 获取对应的本地记录
            layui.each(arr, function(index, item){
                if(item.field in local){
                    item.hide = local[item.field];
                }
            });
            return arr;
        }() ],
        where:{
            type: function() {
                const tabPosition = JSON.parse(sessionStorage.getItem('easyweb-iframe_tempData')).tabPosition
                return tabPosition.match(/\d+$/)[0] === '90646' ? '改性树脂' :
                    (tabPosition.match(/\d+$/)[0] === '90657' ? '纯树脂' : '')
                 }
            },
        request: {
            pageName: 'curr',
            pageSize: 'limit'
        },
        parseData: function (res) {
            return {
                'code': res.code,
                'msg': res.msg,
                'count': res.data.total,
                'data': res.data.records,
            }
        },
        response: {
            statusCode: 200
        },
        done: function(res, curr, count) {
            // 记录筛选状态
            var that = this;
            that.elem.next().on('mousedown', 'input[lay-filter="LAY_TABLE_TOOL_COLS"]+', function(){
                var input = $(this).prev()[0];
                // 此处表名可任意定义
                layui.data('table-filter-test', {
                    key: input.name
                    ,value: input.checked
                })
            });
 
            //$(".lavui-table-grid-down").hide();
            if (res.code === 403) {
                top.location.href = baseUrl+"/";
            }
            tableData = table.cache.locDetl;
            console.log(tableData);
            pageCurr=curr;
            limit();
            form.on('checkbox(tableCheckbox)', function (data) {
                var _index = $(data.elem).attr('table-index')||0;
                if(data.elem.checked){
                    res.data[_index][data.value] = 'Y';
                }else{
                    res.data[_index][data.value] = 'N';
                }
            });
            let headerTop = $('.layui-table-header').offset().top; //获取表格头到文档顶部的距离
            let headerPage = $('.layui-table-page').offset().top; //获取表格底部文档顶部的距离
            $(window).scroll(function () {
                if ((headerTop - $(window).scrollTop()) < 0) { //超过了
                    $('.layui-table-header').addClass('table-header-fixed'); //添加样式,固定住表头
                } else { //没超过
                    $('.layui-table-header').removeClass('table-header-fixed'); //移除样式
                }
            });
        }
    });
 
    // 渲染物料选择
    var matXmSelect = xmSelect.render({
        el: '#mat',
        style: {
            width: '270px',
        },
        autoRow: true,
        toolbar: { show: true },
        filterable: true,
        remoteSearch: true,
        remoteMethod: function(val, cb, show){
            $.ajax({
                url: baseUrl+"/pla/batch/all/get/kv",
                headers: {'token': localStorage.getItem('token')},
                data: {
                    condition: val
                },
                method: 'POST',
                success: function (res) {
                    if (res.code === 200){
                        cb(res.data)
                    } else {
                        cb([]);
                        layer.msg(res.msg, {icon: 2});
                    }
                }
            });
        }
    })
 
    // 复选框事件
    table.on('checkbox(plaDetl)', function(obj){
        // console.log(obj); // 查看对象所有成员
        // console.log(obj.checked); // 当前是否选中状态
        // console.log(obj.data); // 选中行的相关数据
        // console.log(obj.type); // 若触发的是全选,则为:all;若触发的是单选,则为:one
        var checkStatus = table.checkStatus(obj.config.id)
        var selectedNum = checkStatus.data.length;
        var weightAll = 0;
        var weightAnfmeAll = 0;
 
        for (var i in checkStatus.data){
            weightAll += checkStatus.data[i].weight;
            weightAnfmeAll += checkStatus.data[i].weightAnfme;
        }
 
        $('.layui-table-total').find('.laytable-cell-1-0-1').text(selectedNum);
        $('.layui-table-total').find('.laytable-cell-1-0-9').text(weightAll);
        $('.layui-table-total').find('.laytable-cell-1-0-41').text(weightAnfmeAll);
 
    });
 
    // 行单击事件( 双击事件为: rowDouble )
    table.on('row(plaDetl)', function(obj){
 
    });
 
    table.on('tool(plaDetl)', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;
        if (layEvent === 'look') {
            var $a = $(obj.tr).find('a[lay-event="look"]');
            var offset = $a.offset();
            var top = offset.top;
            var left = offset.left;
            layer.open({
                type: 1,
                title: false,
                area: '1200px',
                offset: ['600px', (left - 1200 + $a.outerWidth()) + 'px'],
                shade: .01,
                shadeClose: true,
                fixed: false,
                content: '<table id="lookSSXMTable" lay-filter="lookSSXMTable"></table>',
                success: function (layero) {
                    table.render({
                        elem: '#lookSSXMTable',
                        headers: {token: localStorage.getItem('token')},
                        url: baseUrl+'/plaQty/list/auth',
                        where: {
                            brand: data.brand,
                            batch: data.batch,
                            package_no: data.packageNo
                        },
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'numbers'},
                            {field: 'orderNo', title: '单号'},
                            {field: 'pakoutTime', title: '出库时间'},
                            {field: 'orderWeight', title: '重量'},
                            {field: 'handlerBy', title: '经办人'},
                            {field: 'transfer', title: '流转形式'},
                            {field: 'customer', title: '客户名称'},
                            {field: 'allocate', title: '调拨到'},
                            {field: 'memo', title: '备注'},
                        ]],
                        request: {
                            pageName: 'curr',
                            pageSize: 'limit'
                        },
                        parseData: function (res) {
                            return {
                                'code': res.code,
                                'msg': res.msg,
                                'count': res.data.total,
                                'data': res.data.records
                            }
                        },
                        response: {
                            statusCode: 200
                        },
                        done: function () {
                            $(layero).find('.layui-table-view').css('margin', '0');
                        },
                        size: ''
                    });
                }
            });
        }
 
    })
 
    // 监听头工具栏事件
    table.on('toolbar(plaDetl)', function (obj) {
        var checkStatus = table.checkStatus(obj.config.id)
        printData = checkStatus;
        switch(obj.event) {
            case 'updateData':
                var data = checkStatus.data;
                if (data.length === 0){
                    layer.msg('请选择数据');
                } else {
                    layer.confirm('确定修改'+(data.length===1?'此':data.length)+'条数据吗', function(){
                        $.ajax({
                            url: baseUrl+"/pla/update/auth",
                            headers: {'token': localStorage.getItem('token')},
                            data: JSON.stringify(data),
                            contentType:'application/json;charset=UTF-8',
                            method: 'POST',
                            traditional:true,
                            success: function (res) {
                                if (res.code === 200){
                                    layer.closeAll();
                                    tableReload(false);
                                } else if (res.code === 403){
                                    top.location.href = baseUrl+"/";
                                } else {
                                    layer.msg(res.msg)
                                }
                            }
                        })
                    });
                }
                break;
            case "deleteData":
                var data = checkStatus.data;
                if (data.length === 0){
                    layer.msg('请选择数据');
                } else {
                    layer.confirm('确定删除'+(data.length===1?'此':data.length)+'条数据吗', function(){
                        $.ajax({
                            url: baseUrl+"/pla/delete/auth",
                            headers: {'token': localStorage.getItem('token')},
                            data: JSON.stringify(data),
                            contentType:'application/json;charset=UTF-8',
                            method: 'POST',
                            traditional:true,
                            success: function (res) {
                                if (res.code === 200){
                                    layer.closeAll();
                                    tableReload(false);
                                } else if (res.code === 403){
                                    top.location.href = baseUrl+"/";
                                } else {
                                    layer.msg(res.msg)
                                }
                            }
                        })
                    });
                }
                break;
            case "viladate":
                var data = checkStatus.data;
                if (data.length === 0){
                    layer.msg('请选择数据');
                } else {
                    layer.confirm('确定校验'+(data.length===1?'此':data.length)+'条数据吗', function(){
                        $.ajax({
                            url: baseUrl+"/pla/viladate/auth",
                            headers: {'token': localStorage.getItem('token')},
                            data: JSON.stringify(data),
                            contentType:'application/json;charset=UTF-8',
                            method: 'POST',
                            traditional:true,
                            success: function (res) {
                                if (res.code === 200){
                                    layer.closeAll();
                                    tableReload(false);
                                } else if (res.code === 403){
                                    top.location.href = baseUrl+"/";
                                } else {
                                    layer.msg(res.msg)
                                }
                            }
                        })
                    });
                }
                break;
            case 'freezeData':
                var data = checkStatus.data;
                if (data.length === 0){
                    layer.msg('请选择数据');
                } else {
                    layer.confirm('确定冻结'+(data.length===1?'此':data.length)+'条数据吗', function(){
                        $.ajax({
                            url: baseUrl+"/pla/updateStockFreeze",
                            headers: {'token': localStorage.getItem('token')},
                            data: JSON.stringify(data),
                            contentType:'application/json;charset=UTF-8',
                            method: 'POST',
                            traditional:true,
                            success: function (res) {
                                if (res.code === 200){
                                    layer.closeAll();
                                    tableReload(false);
                                    layer.msg(res.msg,{icon:1})
                                } else if (res.code === 403){
                                    top.location.href = baseUrl+"/";
                                } else {
                                    layer.msg(res.msg,{icon:2})
                                }
                            }
                        })
                    });
                }
                break;
            case 'disFreezeData':
                var data = checkStatus.data;
                if (data.length === 0){
                    layer.msg('请选择数据');
                } else {
                    layer.confirm('确定解除'+(data.length===1?'此':data.length)+'条数据的冻结吗', function(){
                        $.ajax({
                            url: baseUrl+"/pla/updateStockDisFreeze",
                            headers: {'token': localStorage.getItem('token')},
                            data: JSON.stringify(data),
                            contentType:'application/json;charset=UTF-8',
                            method: 'POST',
                            traditional:true,
                            success: function (res) {
                                if (res.code === 200){
                                    layer.closeAll();
                                    tableReload(false);
                                    layer.msg(res.msg,{icon:1})
                                } else if (res.code === 403){
                                    top.location.href = baseUrl+"/";
                                } else {
                                    layer.msg(res.msg,{icon:2})
                                }
                            }
                        })
                    });
                }
                break;
            // 批量打印
            case "btnPrintBatch":
                printMatCodeNos = [];
                var data = checkStatus.data;
                if (data.length === 0){
                    layer.msg('请选择打印数据');
                } else {
                    layer.open({
                        type: 1,
                        area: ['600px', '750px'],
                        title: '批量打印 [数量'+ data.length +']',
                        shadeClose: true,
                        content: $('#printDataDiv'),
                        success: function(layero, index){
                            for (var i = 0; i<data.length;i++) {
                                printMatCodeNos.push(data[i].matnr);
                            }
                        },
                        end: function () {
                        }
                    });
                }
                break;
        }
    })
 
    // 模板选择
    form.on('radio(selectTemplateRadio)', function (data) {
        $('.template-preview').hide();
        $('#template-preview-'+data.value).show();
    });
 
    // 开始打印
    form.on('submit(doPrint)', function (data) {
        var templateNo = data.field.selectTemplate;
        var templateDom = $("#templatePreview"+templateNo);
        var className = templateDom.attr("class");
        layer.closeAll();
        for (let i=0;i<printData.data.length;i++){
            if (className === 'template-barcode') {
                printData.data[i]["barcodeUrl"]=baseUrl+"/mac/code/auth?type=1&param="+(printData.data[i].brand+";"+printData.data[i].batch+";"+printData.data[i].packageNo+";"+printData.data[i].line)
            } else {
                printData.data[i]["barcodeUrl"]=baseUrl+"/mac/code/auth?type=2&param="+(printData.data[i].brand+";"+printData.data[i].batch+";"+printData.data[i].packageNo+";"+printData.data[i].line)
            }
        }
        var tpl = templateDom.html();
        var template = Handlebars.compile(tpl);
        var html = template(printData);
        var box = $("#box");
        box.html(html);box.show();
        box.print({mediaPrint:true});
        box.hide();
        // $.ajax({
        //     url: baseUrl+"/pla/print/auth",
        //     headers: {'token': localStorage.getItem('token')},
        //     data: JSON.stringify(printData.data),
        //     contentType:'application/json;charset=UTF-8',
        //     method: 'POST',
        //     async: false,
        //     success: function (res) {
        //         if (res.code === 200){
        //             layer.closeAll();
        //             for (let i=0;i<res.data.length;i++){
        //                 var templateDom = $("#templatePreview"+templateNo);
        //                 var className = templateDom.attr("class");
        //                 if (className === 'template-barcode') {
        //                     res.data[i]["barcodeUrl"]=baseUrl+"/mac/code/auth?type=1&param="+res.data[i].matnr;
        //                 } else {
        //                     res.data[i]["barcodeUrl"]=baseUrl+"/mac/code/auth?type=2&param="+res.data[i].matnr;
        //                 }
        //             }
        //             var tpl = templateDom.html();
        //             var template = Handlebars.compile(tpl);
        //             var html = template(res);
        //             var box = $("#box");
        //             box.html(html);box.show();
        //             box.print({mediaPrint:true});
        //             box.hide();
        //         } else if (res.code === 403){
        //             top.location.href = baseUrl+"/";
        //         }else {
        //             layer.msg(res.msg)
        //         }
        //     }
        // })
    });
 
    // 搜索栏搜索事件
    form.on('submit(search)', function (data) {
        pageCurr = 1;
        tableReload(false);
    });
 
    // 用来标识搜索重置时,改性树脂和纯树脂从点击事件传过来名称,进行物质类别限定
    let customValue = undefined
    // 重置事件
    form.on('submit(reset)', function (data) {
        customValue = $(this).attr('data-value');
        reset();
    });
 
    function reset() {
        clearFormVal($('#search-box'));
        matCodeData = [];
        tableReload();
 
        // locTips(false);
    }
 
    // 重载表格
    // function tableReload() {
    //     tableIns.reload({data: matCodeData});
    // }
    function tableReload(child) {
        var searchData = {
        };
        $.each($('#search-box [name]').serializeArray(), function() {
            searchData[this.name] = this.value;
        });
        if(customValue !== undefined){
            searchData['type'] = customValue
        }
        if(searchData.select){
            searchData.batch = searchData.select;
            searchData.select = null;
        }
        (child ? parent.tableIns : tableIns).reload({
            where: searchData,
            page: {
                curr: pageCurr
            },
            done: function (res, curr, count) {
                if (res.code === 403) {
                    top.location.href = baseUrl+"/";
                }
                pageCurr=curr;
                if (res.data.length === 0 && count !== 0) {
                    tableIns.reload({
                        where: searchData,
                        page: {
                            curr: pageCurr-1
                        }
                    });
                    pageCurr -= 1;
                }
                limit(child);
            }
        });
    }
 
    $(document).on('click','#updateZpallet',function (){
        debugger;
    })
    $("[name='layTableCheckbox']").click(function(){ // 通过name属性选取元素,并添加点击事件
        alert("Hello World!"); // 在控制台输出提示信息
        debugger
    });
 
 
 
    $(document).on('click','#add', function () {
        var now = dateToStr(new Date())
        var newRow = {ioTime : now};
        data = table.cache.plaDetl;
        data.push(newRow);
        table.reload('plaDetl',{
            data: data
        })
    })
 
    $(document).on('click','#delete', function () {
        let dataNew = [];
        let data = table.cache.plaDetl;
        for(var i=0; i<data.length; i++){
            if(!data[i].LAY_CHECKED){
                dataNew.push(data[i]);
            }
        }
        table.reload('plaDetl',{
            data: dataNew
        })
    })
 
    $(document).on('click','#submit', function () {
        let data = table.cache.plaDetl;
        let dataSave = [];
        let dataOld = [];
        for(var i=0; i<data.length; i++){
            if(data[i].LAY_CHECKED){
                if(!data[i].batch){
                    layer.msg("有未填写字段");
                    return;
                }
                dataSave.push(data[i]);
            }else {
                dataOld.push(data[i]);
            }
        }
        $.ajax({
            url: baseUrl+"/pla/update/auth",
            headers: {'token': localStorage.getItem('token')},
            data: JSON.stringify(dataSave),
            contentType:'application/json;charset=UTF-8',
            method: 'POST',
            async: false,
            success: function (res) {
                if (res.code === 200){
                    layer.msg("提交成功");
                    table.reload('plaDetl',{
                        data: dataOld
                    })
                } else if (res.code === 403){
 
                }else {
                    layer.msg(res.msg, {icon: 2})
                }
            }
        })
    })
 
    $(document).on('click','#rework', function () {
        let data = table.cache.plaDetl;
        let dataSave = [];
        let dataOld = [];
        for(var i=0; i<data.length; i++){
            if(data[i].LAY_CHECKED){
                dataSave.push(data[i]);
            }else {
                dataOld.push(data[i]);
            }
        }
 
        if(!dataSave || dataSave.length < 1){
            layer.msg("未勾选,请先勾选需要重做的库存");
            return;
        }
 
        layer.confirm('确定重做选中的库存吗?', {
            shade: .1,
            skin: 'layui-layer-admin'
        }, function (i) {
            layer.close(i);
            $.ajax({
                url: baseUrl+"/pla/rework/auth",
                headers: {'token': localStorage.getItem('token')},
                data: JSON.stringify(dataSave),
                contentType:'application/json;charset=UTF-8',
                method: 'POST',
                async: false,
                success: function (res) {
                    if (res.code === 200){
                        layer.msg("提交成功");
                        table.reload('productionInfoTable',{
                            data: dataOld
                        })
                    } else if (res.code === 403){
 
                    }else {
                        layer.msg(res.msg, {icon: 2})
                    }
                }
            })
        })
    })
 
    $(document).on('click','#updateZpallet', function () {
        let data = table.cache.plaDetl;
        let dataSave = [];
        let dataOld = [];
        for(var i=0; i<data.length; i++){
            if(data[i].LAY_CHECKED){
                data[i].step = 1;
                dataSave.push(data[i]);
            }else {
                dataOld.push(data[i]);
            }
        }
        dataCheck = dataSave;
 
        if(!dataSave || dataSave.length < 1){
            layer.msg("未勾选,请先勾选需要更改的库存");
            return;
        }
 
        layer.open({
            type: 2,
            title: '换包装/托盘/缠膜',
            maxmin: true,
            area: ['500px', top.detailHeight],
            shadeClose: false,
            content: 'update.html',
            success: function(layero, index){
                layer.getChildFrame('#data-detail-submit-edit', index).hide();
                top.convertDisabled(layer.getChildFrame('#data-detail :input', index), false);
                layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
 
                var iframe = window['layui-layer-iframe' + index];
                iframe.child(dataSave)
            }
        });
    })
 
    $(document).on('click','#sellout', function () {
 
        var data = table.cache.plaDetl;
        var dataSave = [];
        var dataOld = [];
        var brand;
 
        for(var i=0; i<data.length; i++){
            if(data[i].LAY_CHECKED){
                if(data[i].status === "暂入库" || data[i].status === "待入库" || data[i].status === "全部出库"|| data[i].weightAnfme <= data[i].qtyAnfme){
                    layer.msg("选中的明细还未入库或者已全部出库或者没有剩余可出重量,请重新选择");
                    return;
                }
 
                brand = brand ? brand : data[i].brand;
 
                if(brand != data[i].brand){
                    layer.msg("选中的明细中含有多种牌号,请重新选择");
                    return;
                }
                // if(data[i].stockFreeze === 0){
                //     layer.msg("选中的明细中含有冻结的库存,请解冻后操作");
                //     return;
                // }
                dataSave.push(data[i]);
            }else {
                dataOld.push(data[i]);
            }
        }
        dataCheck = dataSave;
 
        if(!dataSave || dataSave.length < 1){
            layer.msg("未勾选,请先勾选需要更改的库存");
            return;
        }
 
        layer.open({
            type: 2,
            title: '出库',
            maxmin: true,
            area: ['800px', top.detailHeight],
            shadeClose: false,
            content: 'sellout.html',
            success: function(layero, index){
                //layer.getChildFrame('#data-detail-submit-edit', index).hide();
                top.convertDisabled(layer.getChildFrame('#data-detail :input', index), false);
                layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
 
                var iframe = window['layui-layer-iframe' + index];
                iframe.child(dataSave)
            }
        });
    })
 
    $(document).on('click','#pickup', function () {
 
        let data = table.cache.plaDetl;
        let dataSave = [];
        let dataOld = [];
        for(var i=0; i<data.length; i++){
            if(data[i].LAY_CHECKED){
                if(data[i].status === "暂入库" || data[i].status === "待入库" || data[i].status === "全部出库"){
                    layer.msg("选中的明细还未入库或者已全部出库,请重新选择");
                    return;
                }
                dataSave.push(data[i]);
            }else {
                dataOld.push(data[i]);
            }
        }
        dataCheck = dataSave;
 
        if(!dataSave || dataSave.length < 1){
            layer.msg("未勾选,请先勾选需要更改的库存");
            return;
        }
        if(dataSave.length > 1){
            layer.msg("请勾选一条库存明细");
            return;
        }
 
        layer.open({
            type: 2,
            title: '卖出',
            maxmin: true,
            area: ['800px', top.detailHeight],
            shadeClose: false,
            content: 'pickup.html',
            success: function(layero, index){
                //layer.getChildFrame('#data-detail-submit-edit', index).hide();
                top.convertDisabled(layer.getChildFrame('#data-detail :input', index), false);
                layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
 
                var iframe = window['layui-layer-iframe' + index];
                iframe.child(dataSave)
            }
        });
    })
 
    $(document).on('click','#returned', function () {
 
        layer.open({
            type: 2,
            title: '退回',
            maxmin: true,
            area: ['800px', '800px'],
            shadeClose: false,
            content: 'returned.html',
            success: function(layero, index){
                layer.getChildFrame('#data-detail-submit-edit', index).hide();
                top.convertDisabled(layer.getChildFrame('#data-detail :input', index), false);
 
            }
        });
    })
    $(document).on('click','#updateOwner', function () {
        let data = table.cache.plaDetl;
        let dataSave = [];
        let dataOld = [];
        for(var i=0; i<data.length; i++){
            if(data[i].LAY_CHECKED){
                data[i].step = 1;
                dataSave.push(data[i]);
            }else {
                dataOld.push(data[i]);
            }
        }
        dataCheck = dataSave;
 
        if(!dataSave || dataSave.length < 1){
            layer.msg("未勾选,请先勾选需要更改的库存");
            return;
        }
 
        layer.open({
            type: 2,
            title: '变更主体',
            maxmin: true,
            area: ['500px', top.detailHeight],
            shadeClose: false,
            content: 'updateOwner.html',
            success: function(layero, index){
                layer.getChildFrame('#data-detail-submit-edit', index).hide();
                top.convertDisabled(layer.getChildFrame('#data-detail :input', index), false);
                layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
 
                var iframe = window['layui-layer-iframe' + index];
                iframe.child(dataSave)
            }
        });
    })
 
})
 
// 关闭动作
$(document).on('click','#data-detail-close', function () {
    parent.layer.closeAll();
});
 
// excel导入模板下载
function excelMouldDownload(){
    layer.load(1, {shade: [0.1,'#fff']});
    location.href = baseUrl + "/pla/excel/import/mould";
    layer.closeAll('loading');
}
 
// excel导入
function importExcel() {
    $("#importExcel").trigger("click");
}
function upload(obj){
    if(!obj.files) {
        return;
    }
    var file = obj.files[0];
    admin.confirm('确认同步 [' + file.name +'] 文件吗?', function (index) {
        layer.load(1, {shade: [0.1,'#fff']});
        var url = baseUrl + "/pla/excel/import/auth";
        var form = new FormData();
        form.append("file", file);
        xhr = new XMLHttpRequest();
        xhr.open("post", url, true); //post方式,url为服务器请求地址,true 该参数规定请求是否异步处理。
        xhr.setRequestHeader('token', localStorage.getItem('token'));
        xhr.onload = uploadComplete; //请求完成
        xhr.onerror =  uploadFailed; //请求失败
        xhr.onloadend = function () { // // 上传完成重置文件流
            layer.closeAll('loading');
            $("#importExcel").val("");
        };
        // xhr.upload.onprogress = progressFunction;//【上传进度调用方法实现】
        xhr.upload.onloadstart = function(){//上传开始执行方法
            ot = new Date().getTime();   //设置上传开始时间
            oloaded = 0;//设置上传开始时,以上传的文件大小为0
        };
        xhr.send(form);
    }, function(index){
        $("#importExcel").val("");
    });
}
function uploadComplete(evt) {
    var res = JSON.parse(evt.target.responseText);
    if(res.code === 200) {
        layer.msg(res.msg, {icon: 1});
        loadTree("");
    } else {
        layer.msg(res.msg, {icon: 2});
    }
}
function uploadFailed(evt) {
    var res = JSON.parse(evt.target.responseText);
    layer.msg(res.msg, {icon: 2});
}
function clearTable(){
 
}