杨乐
2022-03-15 15738dd04afd3bab1735a93a93fc9295e02d9f72
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
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>条码生成</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
    <script src="../../../layuiadmin/layui/layui.js"></script>
    <script src="../../../layuiadmin/Scripts/json2.js"></script>
    <script src="../../../layuiadmin/Scripts/jquery-1.4.1.js"></script>
    <script src="../../../layuiadmin/Scripts/webConfig.js"></script>
    <script src="../../../layuiadmin/PubCustom.js"></script>
    <script src="../../../layuiadmin/zgqCustom/zgqCustom.js"></script>
    <style type="text/css">
 
        /*begin 此样式用于消除行元素中布局宽度不够的问题*/
        .layui-form-item .layui-inline {
            margin-top: 5px;
            margin-bottom: 5px;
            margin-right: 0px;
        }
        /*end*/
        .layui-table-cell .layui-form-checkbox[lay-skin="primary"] {
            margin-left: 35%;
        }
 
        .layui-input-block {
            margin-left: 0px;
        }
    </style>
</head>
<body>
    <div id="layout1" class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <form id="form0" class="layui-form" lay-filter="component-form-group" action="">
                        <div class="layui-card-header">
                            <div class="layui-input-block">
                                <button type="button" class="layui-btn" id="ToolPrint" lay-submit="" lay-filter="ToolPrint">预览打印</button>
                                <button type="button" class="layui-btn" id="ToolCreate" lay-submit="" lay-filter="ToolCreate">生成</button>
                                <button type="button" class="layui-btn" id="ToolReset" lay-submit="" lay-filter="ToolReset">重置</button>
                                <button type="button" class="layui-btn" id="ToolStock" lay-submit="" lay-filter="ToolStock">库存</button>
                                <button type="button" class="layui-btn" id="ToolSynch" lay-submit="" lay-filter="ToolSynch">同步资料</button>
                                <button type="button" class="layui-btn" id="ToolBatch" lay-submit="" lay-filter="ToolBatch">批次</button>
                                <button type="button" class="layui-btn" id="ToolExit" lay-submit="" lay-filter="ToolExit">退出</button>
                            </div>
                        </div>
 
                        <div class="layui-card-body">
                            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                                <h1 style="text-align:center;"><b>条码生成</b></h1>
                                <div class="layui-tab-content">
                                    <div class="layui-tab-item layui-show">
                                        <div class="layui-form-item">
                                            <div class="layui-inline">
                                                <label class="layui-form-label">组织</label>
                                                <div class="layui-input-inline">
                                                    <select name="HOrgID" id="HOrgID" lay-filter="HOrgID" class="layui-input" value="" style="float:left;width:150px">
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="layui-inline">
                                                <label class="layui-form-label">工厂代码</label>
                                                <div class="layui-input-inline">
                                                    <select name="HWorksNumber" id="HWorksNumber" lay-filter="HWorksNumber" class="layui-input" value="" style="float:left;width:150px">
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="layui-inline">
                                                <label class="layui-form-label">日期</label>
                                                <div class="layui-input-inline">
                                                    <input class="layui-input" name="HDate" id="HDate" autocomplete="off" model="datetime" dateFormat="yyyy-MM-dd" placeholder="yyyy-MM-dd">
                                                </div>
                                            </div>
                                        </div>
                                        <div class="layui-form-item">
                                            <div class="layui-inline">
                                                <label class="layui-form-label">源单类型</label>
                                                <div class="layui-input-inline">
                                                    <select name="HSourceBillType" id="HSourceBillType" lay-filter="HSourceBillType" class="layui-input" value="" style="float:left;width:150px">
                                                        <option value="1">生产订单</option>
                                                        <option value="2">生产汇报单</option>
                                                        <option value="3">采购订单</option>
                                                        <option value="4">收料通知单</option>
                                                        <option value="5">委外订单</option>
                                                        <option value="6">退货通知单</option>
                                                        <option value="7">其他入库单</option>
                                                        <option value="8">直接调拨单</option>
                                                        <option value="9">采购退料单</option>
                                                        <option value="10">生产退料单</option>
                                                        <option value="11">组装拆卸单</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="layui-inline">
                                                <label class="layui-form-label">选单号<label style="color:red"> * </label></label>
                                                <div class="layui-input-inline">
                                                    <input type="text" name="HSourceBillNo" id="HSourceBillNo" readonly class="layui-input" value="" style="float:left;width:150px;">
                                                    <button type="button" lay-submit="" class="layui-btn" lay-filter="HSourceBillNoList" style="width:40px;">
                                                        <i class="layui-icon layui-icon-search layuiadmin-button-btn" style="margin-left:-9px;"></i>
                                                    </button>
                                                </div>
                                            </div>
                                            <div class="layui-inline">
                                                <label class="layui-form-label">条码类型</label>
                                                <div class="layui-input-inline">
                                                    <select name="HBarCodeType" id="HBarCodeType" lay-filter="HBarCodeType" class="layui-input" value="" style="float:left;width:150px">
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
 
                                    </div>
                                </div>
                            </div>
                        </div>
 
                        <div class="layui-tab layui-tab-card" lay-filter="tab-TabTest">
                            <ul class="layui-tab-title">
                                <li lay-id="1" class="layui-this">物料信息</li>
                                <li lay-id="2">条码信息</li>
                                <li lay-id="3">档案列表</li>
                            </ul>
                            <div class="layui-tab-content">
                                <div class="layui-tab-item layui-show">
                                    <table class="layui-hide" id="mainTable" lay-filter="mainTable"></table>
                                </div>
                                <div class="layui-tab-item">
                                    <table class="layui-hide" id="mainTable1" lay-filter="mainTable1"></table>
                                </div>
                                <div class="layui-tab-item">
                                    <table class="layui-hide" id="mainTable2" lay-filter="mainTable2"></table>
                                </div>
                            </div>
                        </div>
 
                        <script type="text/html" id="toolbarDemo">
                            <div class="layui-btn-container">
 
                                <button type="button" class="layui-btn layui-btn-sm" lay-event="btn-AddLine"><i class="layui-icon layui-icon-form"></i>增加一行</button>
                                <button type="button" class="layui-btn layui-btn-sm" lay-event="btn-CopyLine"><i class="layui-icon layui-icon-form"></i>复制一行</button>
 
                            </div>
                        </script>
                        <script type="text/html" id="xuhao">
                            {{d.LAY_TABLE_INDEX+1}}
                        </script>
                        <script type="text/html" id="switchTpl">
                            <!-- 这里的 checked 的状态只是演示 -->
                            <input type="checkbox" name="checkbox" value="{{d.HGiveAwayFlag}}" lay-skin="primary" lay-filter="HGiveAwayFlag" {{ d.HGiveAwayFlag == 1 ? 'checked' : '' }}>
                        </script>
                        <script type="text/html" id="switchTp2">
                            <!-- 这里的 checked 的状态只是演示 -->
                            <input type="checkbox" name="checkbox" lay-skin="primary" lay-filter="HGiveAwayFlag1">
                        </script>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <script type="text/html" id="barDemo">
        <!--<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>-->
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script>
        //获取参数
        var params = get_UrlVars();
        if (typeof (params[params[0]]) == "undefined") {
            var OperationType = 1;//操作类型
            var closeType = 2;  //关闭类型
        } else {
            debugger;
            var OperationType = params[params[0]];//操作类型
            var linterid = params[params[1]];//源单id
            var HSouceBillType = params[params[2]];//源单类型
            var closeType = params[params[3]];  //关闭类型
        }
 
 
        layui.config({
            base: '../../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form', 'laydate', 'table', 'element'], function () {
            //#region 公共变量
            var $ = layui.$
                , admin = layui.admin
                , layer = layui.layer
                , table = layui.table
                , form = layui.form
                , laydate = layui.laydate
                , element = layui.element;
            //查询条件
            var option = [];
            var option1 = [];
            var option2 = [];
            var sWhere = "";
            var sBillType = "3801";
            //#endregion
         
            //#region 进入页面既加载
            //初始化表单插件
            set_InitFrom();
            //加载组织数据
            set_HOrg();
            //加载工厂代码数据
            set_HWorksNumber();
            //加载条码类型数据
            set_HBarCodeType();
            //初始化表格
            set_InitGrid();
            set_CountGrid();
            set_InitGrid2();
            //判断操作类型
            if (OperationType == 1) {//无源新增
                //初始基本信息赋值
                $("#HDate").val(Format(new Date(), "yyyy-MM-dd hh:mm:ss"));      //单据日期
                set_AddFNew();
                set_AddFNew1();
                set_AddFNew2();
            }
            else if (OperationType == 3) {//编辑
                set_EditFromGrid(linterid);
            }
            else {
                layer.alert("未知操作类型!", { icon: 5 });
            }
            //#endregion
 
            //#region 点击事件,包括on和form事件
            //头工具栏
            table.on('toolbar(mainTable)', function (obj) {
                var checkStatus = table.checkStatus('mainTable')
                    , data = checkStatus.data;;
                var AddRow = table.cache['mainTable'];
                var NewRow = { "HMaterID": 0, "HMaterCode": "", "HMaterName": "", "HMaterSpec": "", "HBatchNo": "", "HUnitID": 0, "HUnitNumber": "", "HUnitName": "", "HDesignLife": 0, "HLeaveLife": 0, "HUseLife": 0, "HQtyMust": 0, "HQty": 0, "HPrice": 0, "HMoney": 0, "HWHID": 0, "HWHCode": "", "HWHName": "", "HSPID": 0, "HSPCode": "", "HSPName": "", "HStockOrgID": sessionStorage["OrganizationID"], "HRemark": "" };
                console.log(NewRow);
                switch (obj.event) {
                    //新增一行
                    case 'btn-AddLine': btnAddLine(NewRow);
                        break;
                    //复制一行
                    case 'btn-CopyLine': btnCopyLine(data);
                        break;
                }
            });
            //行内事件
            table.on('tool(mainTable)', function (obj) {
                set_GridDelete(obj);   //行内删除
                set_GridCellCheck(obj); //行内快捷键筛选
            });
 
            //监听单元格编辑  单元格编辑后 变更
            table.on('edit(mainTable)', function (obj) {
                // 单元格编辑之前的值
                var oldText = $(this).prev().text();
                var value = obj.value //得到修改后的值
                    , data = obj.data //得到所在行所有键值
                    , field = obj.field; //得到字段
                //layer.msg('[ID: ' + data.id + '] ' + field + ' 字段更改为:' + value);
 
                switch (field) {
                    case "HQty":  //数量
                        value = isNaN(value) ? 0 : value;
                        var HMinQty = isNaN(data.HMinQty) ? 0 : data.HMinQty;
                        if (HMinQty == 0) {
                            //同步更新表格和缓存对应的值
                            obj.update({
                                HQty: value,                                   //数量
                                HBQty: 0,                                      //箱数=数量/最小包装数量
                            });
                        }
                        else
                        {
                            //同步更新表格和缓存对应的值
                            obj.update({
                                HQty: value,                                   //数量
                                HBQty: Math.ceil(value / HMinQty),             //箱数=数量/最小包装数量
                            });
                        }
                        break;
                    case "HMinQty":  //最小包装数量
                        value = isNaN(value) ? 0 : value;
                        var HQty = isNaN(data.HQty) ? 0 : data.HQty;
                        if (HQty == 0) //除数为0 
                        {
                            //同步更新表格和缓存对应的值
                            obj.update({
                                HMinQty: value,                                //最小包装数量
                                HBQty: 0,                                      //箱数=数量/最小包装数量
                            });
                        }
                        else {
                            //同步更新表格和缓存对应的值
                            obj.update({
                                HMinQty: value,                                //最小包装数量
                                HBQty: Math.ceil(HQty / value),                //箱数=数量/最小包装数量
                            });
                        }
                      
                        break;
                    default:
                }
            });
 
            //下拉框事件选择触发
            form.on('select(HSourceBillType)', function (data) {
                $("#HSourceBillNo").val("");
            });
 
            function getSupType() {
                var type = $("#HSourceBillType").val();
                switch (type) {
                    case '1':
                        return "生产订单";
                        break;
                    case '2':
                        return "生产汇报单";
                        break;
                    case '3':
                        return "采购订单";
                        break;
                    case '4':
                        return "收料通知单";
                        break;
                    case '5':
                        return "委外订单";
                        break;
                }
            }
 
            //表头信息源单信息弹窗
            form.on('submit(HSourceBillNoList)', function () {
                if ($("#HSourceBillType").val() == 0 || $("#HSourceBillType").val() == null) {
                    return layer.msg('请选择单据类型');
                }
                //获取组织ID
                var SetHOrgID = $("#HOrgID").find("option:selected").val();
                //页面层-自定义
                var url = '../../PublicPage/HSourceReportHtml.html?OperationType=3&linterid=' + SetHOrgID + '&HSouceBillType=' + getSupType() + '';
                url = encodeURI(url);
                //alert(url);
                layer.open({
                    type: 2,
                    skin: 'layui-layer-rim', //加上边框
                    title: '' + getSupType() + '列表',
                    closeBtn: 1,
                    shift: 2,
                    area: ['95%', '80%'],
                    maxmin: true,
                    content: [url, 'yes'],
                    btn: ['确定', '取消']
                    , btn1: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index]  //获取弹框页面
                        var checkStatus = iframeWindow.layui.table.checkStatus('layTable');//获取table的elem:"#test"
                        if (checkStatus.data.length === 0) {
                            return layer.msg('请选择单据数据');
                        }
                        var list = [];
                        var BillSelect = [];
                        for (var i = 0; i < checkStatus.data.length; i++) {
                            if (checkStatus.data[i].部门 != "" && checkStatus.data[i].部门 != null) {
                                list.push(checkStatus.data[i].部门)
                            }
                            BillSelect.push({ BillType: checkStatus.data[i].HBillType, BillTitle: getSupType(), BillNo: checkStatus.data[i].单据号, "BillMainID": checkStatus.data[i].HMainID, "BillSubID": checkStatus.data[i].HSubID, "SPID": 0, "BatchNo": "", "HAuxPropID": 0 });
                        }
                        if (isAllEqual(list))  //不允许选择不同部门
                        {
                            //获取选中数据
                            var GrdSelectData = JSON.stringify(BillSelect);
                            //获取选择的源单类型
                            var HSourceBillType = $("#HSourceBillType").find("option:selected").html();
                            //获取选择的条码类型
                            var HBarCodeType = $("#HBarCodeType").find("option:selected").html();
                            //获取当前登录人员
                            var UserName = sessionStorage["HUserName"];
                            var Str = GrdSelectData + ";" + HSourceBillType + ";" + HBarCodeType + ";" + UserName;
                            //通过选择的源单主子内码查找详细信息
                            $.ajax({
                                type: "post",
                                url: GetWEBURL() + "/Sc_BarCode/SelectReportFromBillList",
                                //contentType: 'application/json',
                                async: true,
                                dataType: "json",
                                data: { "msg": Str },
                                //traditional: true,
                                success: function (result) {
                                    if (result.count == 1) { // 说明验证成功了,
                                        table.reload('mainTable', {
                                            data: result.list // 调用table.reload 重新渲染显示加载追加了数据的表格
                                        });
                                        //关闭当前frame
                                        layer.close(index);
                                    }
                                }
                            })
                        }
                        else {
                            layer.msg("不允许选择不同的部门数据!", { time: 1 * 2000, icon: 5 });
                        }
 
                    }
                    , btn2: function (index, layero) {
                        //按钮【按钮二】的回调
                        //return false 开启该代码可禁止点击该按钮关闭
                    },
                    end: function () {
 
                    },
                    success: function (layero, index) {
 
                    }
                });
            });
 
            function isAllEqual(array) {
                if (array.length > 0) {
                    return !array.some(function (value, index) {
                        return value !== array[0];
                    });
                } else {
                    return true;
                }
            }
 
            //打印
            form.on('submit(ToolPrint)', function (data) {
                get_PrintReport();
            })
 
            //条码生成
            form.on('submit(ToolCreate)', function (data) {
                var sSubStr = JSON.stringify(table.cache['mainTable']);
                //物料明细信息不为空判断
                if (!AllowLoadData(sSubStr))//数据验证
                {
                    return false;
                }
                //获取选择的组织
                var HOrgType = $("#HOrgID").find("option:selected").html();
                //获取选择的工厂代码
                var CampanyName = $("#HWorksNumber").find("option:selected").html();
                if (CampanyName == "" || CampanyName == null)
                {
                    CampanyName = "xxx";
                }
                //获取选择的源单类型
                var HSourceBillType = $("#HSourceBillType").find("option:selected").html();
                //获取选择的条码类型
                var HSelectBarCodeType = $("#HBarCodeType").find("option:selected").html();
                //获取当前登录人员
                //var UserName = sessionStorage["HUserName"];
                var UserName = "Admin";
                var sMainSub = sSubStr + ';' + HOrgType + ';' + HSourceBillType + ';' + HSelectBarCodeType + ';' + CampanyName + ';' + UserName;
                SaveBarCodeCreate(sMainSub);
            })
 
            //退出
            form.on('submit(ToolExit)', function (data) {
                if (linterid == undefined) {
                    //关闭页签
                    Pub_Close(2);
                }
                else {
                    //关闭页签
                    Pub_Close(1);
                }
            });
 
            //#endregion
 
            //#region 此页面所有方法
            //初始化表单插件
            function set_InitFrom() {
                laydate.render({
                    elem: '#HDate'
                });
            }
 
            //获取组织
            function set_HOrg() {
                //获取登录页组织列
                var Organization = '';
                $.ajax({
                    type: "get",
                    url: GetWEBURL() + "/Web/GetOrganizations",
                    success: function (result) {
                        if (result.count == 1) { // 说明验证成功了,
                            var data = result.data;
                            for (var i = 0; i < data.length; i++) {
                                Organization += '<option  style="color:blue;" value="' + data[i].ID + '">' + data[i].Name + '</option>';
                            }
                            $("#HOrgID").append(Organization);
                            form.render('select');
                        }
                        $('#HOrgID').find("option[value=" + result.data[0].ID + "]").attr("selected", true);
                        form.render('select') //再次渲染
                        layer.closeAll("loading");
                    }
                })
            }
            //获取工厂代码
            function set_HWorksNumber() {
                //获取工厂代码
                var Organization = '';
                $.ajax({
                    type: "get",
                    url: GetWEBURL() + "/Sc_BarCode/GetHWorksNumberBill",
                    success: function (result) {
                        if (result.count == 1) { // 说明验证成功了,
                            var data = result.list;
                            for (var i = 0; i < data.length; i++) {
                                Organization += '<option  style="color:blue;" value="' + i + '">' + data[i] + '</option>';
                            }
                            $("#HWorksNumber").append(Organization);
                            form.render('select');
                            if (result.list[0] != "" && result.list[0] != null) {
                                $('#HWorksNumber').find("option[value=" + result.list[0] + "]").attr("selected", true);
                                form.render('select') //再次渲染
                            }
                        }
                        layer.closeAll("loading");
                    }
                })
            }
            //获取条码类型
            function set_HBarCodeType() {
                //获取条码类型代码
                var Organization = '';
                $.ajax({
                    type: "get",
                    url: GetWEBURL() + "/Sc_BarCode/GetHBarCodeTypeBill",
                    success: function (result) {
                        if (result.count == 1) { // 说明验证成功了,
                            var data = result.list;
                            for (var i = 0; i < data.length; i++) {
                                Organization += '<option  style="color:blue;" value="' + i + '">' + data[i] + '</option>';
                            }
                            $("#HBarCodeType").append(Organization);
                            form.render('select');
                        }
                        $('#HBarCodeType').find("option[value=" + result.list[0] + "]").attr("selected", true);
                        form.render('select') //再次渲染
                        layer.closeAll("loading");
                    }
                })
            }
 
            //初始化物料信息表格
            function set_InitGrid() {
                columns = [
                    { type: 'checkbox', fixed: 'left' }
                    , { templet: '#xuhao', title: '序号', sort: true, fixed: 'left', event: "qwe", width: 100 }
                    , { field: 'HMainID', title: '源单主内码',  width: 100, hide: true }
                    , { field: 'HSubID', title: '源单子内码',  width: 100, hide: true }
                    , { field: 'HBillNo', title: '源单单号', width: 200 }
                    , { field: 'HMaterID', title: '物料ID',  width: 100, hide: true }
                    , { field: 'HMaterNumber', title: '物料代码', edit: 'text', event: 'HMaterNumber', width: 200 }
                    , { field: 'HMaterName', title: '物料名称',  width: 200 }
                    , { field: 'HMaterModel', title: '规格型号', width: 200 }
                    , { field: 'HAuxPropID', title: '辅助属性ID',  width: 100, hide: true }
                    , { field: 'HAuxPropNumber', title: '辅助属性代码', edit: 'text', event: 'HAuxPropNumber', width: 100 }
                    , { field: 'HAuxPropName', title: '辅助属性名称',  width: 100 }
                    , { field: 'HUnitID', title: '计量单位ID', width: 100, hide: true }
                    , { field: 'HUnitNumber', title: '计量单位代码', edit: 'text', event: 'HUnitNumber', width: 100 }
                    , { field: 'HUnitName', title: '计量单位',width: 100 }
                    , { field: 'HBatchNo', title: '批号', edit: 'text', width: 100 }
                    , { field: 'HGiveAwayFlag', title: '是否赠品', width: 100, templet: '#switchTpl', unresize: false }
                    , { field: 'HQty', title: '数量', edit: 'text', width: 100 }
                    , { field: 'HMinQty', title: '最小包装数', edit: 'text', width: 100 }
                    , { field: 'HBQty', title: '箱数', width: 100 }
                    , { field: 'HPackQty', title: '外箱数', edit: 'text', width: 100 }
                    , { field: 'HDate', title: '进料日期',  width: 100 }
                    , { field: 'HCusID', title: '客户ID',  width: 100, hide: true }
                    , { field: 'HCusNumber', title: '客户代码', edit: 'text', event: 'HCusNumber', width: 120 }
                    , { field: 'HCusName', title: '客户名称', width: 120 }
                    , { field: 'HSeOrderBillNo', title: '销售订单号', width: 200 }
                    , { field: 'HRemark', title: '备注', edit: 'text', width: 100 }
                    , { fixed: 'right', title: '操作', toolbar: '#barDemo' }
                ];
                option = {
                    id: 'mainTable'
                    , elem: '#mainTable'
                    , toolbar: '#toolbarDemo'
                    , page: false
                    , cellMinWidth: 120
                    , height: 650
                    , cols: [columns]
                    , limit: 500 //每页默认显示的数量
                    , done: function (res, curr, count) {
                    }
                };
            }
            //初始条码信息表格
            function set_CountGrid() {
                //表头
                columns = [
                    { type: 'checkbox', fixed: 'left' }
                    , { templet: '#xuhao', title: '序号', sort: true, fixed: 'left', event: "qwe", width: 100 }
                    , { field: 'HBarCode2', title: '条码编号', width: 100 }
                    , { field: 'HMaterNumber2', title: '物料代码', width: 100 }
                    , { field: 'HMaterName2', title: '物料名称', width: 100 }
                    , { field: 'HMaterModel2', title: '规格型号', width: 100 }
                    , { field: 'HAuxPropNumber2', title: '辅助属性代码', width: 100 }
                    , { field: 'HAuxPropName2', title: '辅助属性', event: 'HWHCode', width: 120 }
                    , { field: 'HGiveAwayFlag2', title: '是否赠品', width: 120, templet: '#switchTpl', unresize: false }
                    , { field: 'HUnitCode2', title: '计量单位代码', width: 120 }
                    , { field: 'HUnitName2', title: '计量单位', width: 120 }
                    , { field: 'HQty2', title: '数量', width: 120 }
                    , { field: 'HDate2', title: '进料日期', width: 120 }
                    , { field: 'HCusNumber2', title: '客户代码', width: 120 }
                    , { field: 'HCusName2', title: '客户', width: 120 }
                    , { field: 'HSourceBillNo2', title: '源单单号', width: 120 }
                    , { field: 'HSeOrderBillNo2', title: '销售订单号', width: 120 }
                    , { field: 'HRemark2', title: '备注', width: 120 }
                    , { field: 'HMTONo2', title: '计划跟踪号', width: 120 }
                    , { field: 'HShowDate2', title: '日期', width: 100 }
                    , { field: 'HInnerBillNo2', title: '内部采购订单号', width: 100 }
                    , { field: 'HMaker2', title: '制单人', width: 100 }
                ];
                option1 = {
                    id: 'mainTable1'
                    , elem: '#mainTable1'
                    , height: 500
                    , page: false
                    , limit: 500
                    , cellMinWidth: 120
                    , height: 650
                    , cols: [columns]
                    , done: function (res, curr, count) {
                    }
                };
            }
            //初始化档案列表信息表格
            function set_InitGrid2() {
                //表头
                columns = [
                    { type: 'checkbox', fixed: 'left' }
                    , { templet: '#xuhao', title: '序号', sort: true, fixed: 'left', event: "qwe", width: 100 }
                    , { field: 'HItemID', title: 'HItemID', width: 100, hide: true }
                    , { field: 'hmainid', title: 'hmainid', width: 100, hide: true }
                    , { field: 'hsubid', title: 'hsubid', width: 100, hide: true }
                    , { field: 'HinterID', title: 'HinterID', width: 100, hide: true }
                    , { field: '条码类型', title: '条码类型', width: 100 }
                    , { field: '条码编号', title: '条码编号', width: 120 }
                    , { field: 'HMaterID', title: '物料ID', width: 100, hide: true }
                    , { field: '物料代码', title: '物料代码', width: 120 }
                    , { field: '物料名称', title: '物料名称', width: 120 }
                    , { field: '规格型号', title: '规格型号', width: 120 }
                    , { field: 'HUnitID', title: '计量单位ID', width: 100, hide: true }
                    , { field: '计量单位代码', title: '计量单位代码', width: 120 }
                    , { field: '计量单位', title: '计量单位', width: 120 }
                    , { field: 'HAuxPropID', title: '辅助属性ID', width: 100, hide: true }
                    , { field: '辅助属性代码', title: '辅助属性代码', width: 120 }
                    , { field: '辅助属性', title: '辅助属性', width: 120 }
                    , { field: '批号', title: '批号', width: 120 }
                    , { field: '数量', title: '数量', width: 100 }
                    , { field: '源单单号', title: '源单单号', width: 120 }
                    , { field: '计划跟踪号', title: '计划跟踪号', width: 120 }
                    , { field: '是否赠品', title: '是否赠品', width: 100 }
                    , { field: 'DeptID', title: '车间ID', width: 100, hide: true }
                    , { field: '车间', title: '车间', width: 120 }
                    , { field: 'HSupID', title: '供应商ID', width: 100, hide: true }
                    , { field: '供应商代码', title: '供应商代码', width: 120 }
                    , { field: '供应商', title: '供应商', width: 120 }
                    , { field: '客户条码编号', title: '客户条码编号', width: 120 }
                    , { field: '客户型号', title: '客户型号', width: 120 }
                    , { field: '往来单位', title: '往来单位', width: 120 }
                    , { field: '销售订单号', title: '销售订单号', width: 120 }
                    , { field: '销售订单行号', title: '销售订单行号', width: 120 }
                    , { field: '托号', title: '托号', width: 120 }
                    , { field: '总托数', title: '总托数', width: 100 }
                    , { field: '条码日期', title: '条码日期', width: 120 }
                    , { field: '生产入库日期', title: '生产入库日期', width: 120 }
                    , { field: '生产入库单号', title: '生产入库单号', width: 120 }
                    , { field: '生产入库次数', title: '生产入库次数', width: 100 }
                    , { field: '销售出库日期', title: '销售出库日期', width: 120 }
                    , { field: '销售出库单号', title: '销售出库单号', width: 120 }
                    , { field: '销售出库次数', title: '销售出库次数', width: 100 }
                    , { field: '作废标记', title: '作废标记', width: 100 }
                    , { field: '作废人', title: '作废人', width: 100 }
                    , { field: '备注', title: '备注', width: 120 }
                    , { field: '制作人', title: '制作人', width: 100 }
                    , { field: '日期', title: '日期', width: 120 }
                    , { field: '计划完工日期', title: '计划完工日期', width: 120 }
                    , { field: '打印次数', title: '打印次数', width: 100 }
                    , { field: 'HSTOCKORGID', title: 'HSTOCKORGID', width: 100, hide: true }
                    , { field: '生成组织', title: '生成组织', width: 120 }
                ];
                option2 = {
                    id: 'mainTable2'
                    , elem: '#mainTable2'
                    , height: 500
                    , page: false
                    , limit: 500
                    , cellMinWidth: 120
                    , height: 650
                    , cols: [columns]
                    , done: function (res, curr, count) {
                    }
                };
            }
            //无源单新增
            function set_AddFNew() {
                option.data = [{
                    "HMainID": 0, "HSubID": 0, "HBillNo": "", "HMaterID": 0, "HMaterNumber": "", "HMaterName": "", "HMaterModel": ""
                    , "HAuxPropID": 0, "HAuxPropNumber": "", "HAuxPropName": "", "HUnitID": 0, "HUnitNumber": "", "HUnitName": "", "HBatchNo": "", "HGiveAwayFlag": 0
                    , "HQty": 0, "HMinQty": 0, "HBQty": 0, "HPackQty": 0, "HDate": "", "HCusID": 0, "HCusNumber": "", "HCusName": "", "HSeOrderBillNo": "", "HRemark": ""
                }];
                table.render(option);
            }
 
            function set_AddFNew1() {
                option1.data = [{
                    "HBarCode": "", "HMaterNumber": "", "HMaterName": "", "HMaterModel": "", "HAuxPropNumber": "", "HAuxPropName": ""
                    , "HGiveAwayFlag": "", "HUnitCode": "", "HUnitName": "", "HQty": 0, "HDate": "", "HCusNumber": "", "HCusName": ""
                    , "HSourceBillNo": "", "HSeOrderBillNo": "", "HRemark": "", "HMTONo": "", "HShowDate": "", "HInnerBillNo": "", "HMaker": ""
                }];
                table.render(option1);
            }
 
            function set_AddFNew2() {
                option2.data = [];
                table.render(option2);
            }
 
            //日期格式化
            function formatDate(date) {
                var d = new Date(date),
                    month = '' + (d.getMonth() + 1),
                    day = '' + d.getDate(),
                    year = d.getFullYear();
 
                if (month.length < 2) month = '0' + month;
                if (day.length < 2) day = '0' + day;
 
                return [year, month, day].join('-');
            }
            //增加一行
            function btnAddLine(NewRow) {
                //var tableBak = table.cache["mainTable"]; //获取之前编辑过的表格数据
                //buttonArr = [];//清空数组
                //for (var i = 0; i < tableBak.length; i++) {
                //    buttonArr.push(tableBak[i]);  //将之前的数据存储
                //}
                //buttonArr.push(NewRow);  //在尾部加一行
                //table.reload("mainTable", {
                //    data: buttonArr    //将数据重新载入表格
                //})
                //table.cache["mainTable"].push(AddRow[rows]);
                table.cache["mainTable"].push(NewRow);
                option.data = table.cache["mainTable"];
                table.render(option);
                rows++;
                layer.msg('增加一行按钮!')
            }
            //复制一行
            function btnCopyLine(data) {
                var copydata = JSON.stringify(data);
                if (data.length <= 0) {
                    layer.msg("请选择需要复制的一行!");
                }
                else if (data.length > 1) {
                    layer.msg("只能选择复制一行!");
                }
                else {
                    var copydata2 = copydata.substring(1, copydata.length);//去除首行字符'['
                    var copyrow = copydata2.substring(0, copydata2.length - 1);//去除末尾字符']'
                    table.cache["mainTable"].push(JSON.parse(copyrow));//将复制的行强转成json追加到表格上
                    option.data = table.cache["mainTable"];//将数据绑定到data上
                    table.render(option);//将数据渲染到表格上
                }
            }
            // 表格行内事件删除
            function set_GridDelete(obj) {
                var data = obj.data;
                var rowIndex = $(obj.tr).attr("data-index");
                if (obj.event === 'del') {
                    layer.confirm('真的删除行么', function (index) {
                        console.log("索引为:" + rowIndex);
                        if (rowIndex === '0') {
                            layer.msg('首行无法删除!!!');
                        } else {
                            //obj.del();
                            //layer.close(index);
                            var oldData = table.cache["mainTable"];
                            oldData.splice(obj.tr.data('index'), 1);
                            table.reload('mainTable', { data: oldData });
                            layer.close(index);
                        }
                    });
                }
            }
            //表格行内事件快捷键筛选
            function set_GridCellCheck(obj) {
                $(document).off('keydown', ".layui-table-edit").on('keydown', '.layui-table-edit', function (e) {
                    if (event.key == "F7") {
                        //模具信息  如果在模具代码列 按F7
                        if (obj.event === 'HMaterNumber')  //模具信息  如果在模具代码列 按F7
                        {
                            //页面层-自定义  //F7选择模具
                            layer.open({
                                type: 2,
                                skin: 'layui-layer-rim', //加上边框
                                title: '物料列表',
                                closeBtn: 1,
                                shift: 2,
                                area: ['80%', '80%'],
                                maxmin: true,
                                content: ['../../PublicPage/PartInformation.html', 'yes'],
                                btn: ['确定', '取消']
                                , btn1: function (index, layero) {
 
                                    //按钮【按钮一】的回调
                                    var iframeWindow = window['layui-layer-iframe' + index]  //获取弹框页面
                                    var checkStatus = iframeWindow.layui.table.checkStatus('mainTable');//获取table的elem:"#test"
                                    if (checkStatus.data.length === 0) {
                                        return layer.msg('请选择数据');
                                    }
                                    //console.log(obj.data);
                                    //同步更新表格和缓存对应的值
                                    obj.update({
                                        HMaterID: checkStatus.data[0].HItemID,
                                        HMaterNumber: checkStatus.data[0].HNumber,
                                        HMaterName: checkStatus.data[0].HName,
                                        HMaterModel: checkStatus.data[0].HModel
                                    });
 
                                    layer.close(layer.index); //它获取的始终是最新弹出的某个层,值是由layer内部动态递增计算的
                                }
                                , btn2: function (index, layero) {
                                    //按钮【按钮二】的回调
                                    //return false 开启该代码可禁止点击该按钮关闭
                                },
                                end: function () {
 
                                }
                            });
                        }
                        //辅助属性信息
                        if (obj.event === 'HAuxPropNumber')  //辅助属性信息
                        {
                            //页面层-自定义
                            layer.open({
                                type: 2,
                                skin: 'layui-layer-rim', //加上边框
                                title: '辅助属性列表',
                                closeBtn: 1,
                                shift: 2,
                                area: ['80%', '80%'],
                                maxmin: true,
                                content: ['../../PublicPage/PropertyInformation.html', 'yes'],
                                btn: ['确定', '取消']
                                , btn1: function (index, layero) {
 
                                    //按钮【按钮一】的回调
                                    var iframeWindow = window['layui-layer-iframe' + index]  //获取弹框页面
                                    var checkStatus = iframeWindow.layui.table.checkStatus('mainTable');//获取table的elem:"#test"
                                    if (checkStatus.data.length === 0) {
                                        return layer.msg('请选择数据');
                                    }
 
                                    //同步更新表格和缓存对应的值
                                    obj.update({
                                        HAuxPropID: checkStatus.data[0].HItemID,
                                        HAuxPropNumber: checkStatus.data[0].HNumber,
                                        HAuxPropName: checkStatus.data[0].HName,
                                    });
 
                                    layer.close(layer.index); //它获取的始终是最新弹出的某个层,值是由layer内部动态递增计算的
                                }
                                , btn2: function (index, layero) {
                                    //按钮【按钮二】的回调
                                    //return false 开启该代码可禁止点击该按钮关闭
                                },
                                end: function () {
 
                                }
                            });
                        }
 
                        //计量单位代码
                        if (obj.event === 'HUnitNumber')  //计量单位代码
                        {
                            //页面层-自定义
                            layer.open({
                                type: 2,
                                skin: 'layui-layer-rim', //加上边框
                                title: '计量单位列表',
                                closeBtn: 1,
                                shift: 2,
                                area: ['80%', '80%'],
                                maxmin: true,
                                content: ['../../PublicPage/UnitInformation.html', 'yes'],
                                btn: ['确定', '取消']
                                , btn1: function (index, layero) {
 
                                    //按钮【按钮一】的回调
                                    var iframeWindow = window['layui-layer-iframe' + index]  //获取弹框页面
                                    var checkStatus = iframeWindow.layui.table.checkStatus('mainTable');//获取table的elem:"#test"
                                    if (checkStatus.data.length === 0) {
                                        return layer.msg('请选择数据');
                                    }
 
                                    //同步更新表格和缓存对应的值
                                    obj.update({
                                        HUnitID: checkStatus.data[0].HItemID,
                                        HUnitNumber: checkStatus.data[0].HNumber,
                                        HUnitName: checkStatus.data[0].HName,
                                    });
 
                                    layer.close(layer.index); //它获取的始终是最新弹出的某个层,值是由layer内部动态递增计算的
                                }
                                , btn2: function (index, layero) {
                                    //按钮【按钮二】的回调
                                    //return false 开启该代码可禁止点击该按钮关闭
                                },
                                end: function () {
 
                                }
                            });
                        }
                        //客户代码
                        if (obj.event === 'HCusNumber')  //客户代码
                        {
                            //页面层-自定义
                            layer.open({
                                type: 2,
                                skin: 'layui-layer-rim', //加上边框
                                title: '客户列表',
                                closeBtn: 1,
                                shift: 2,
                                area: ['80%', '80%'],
                                maxmin: true,
                                content: ['../../PublicPage/CustomerInformation.html', 'yes'],
                                btn: ['确定', '取消']
                                , btn1: function (index, layero) {
 
                                    //按钮【按钮一】的回调
                                    var iframeWindow = window['layui-layer-iframe' + index]  //获取弹框页面
                                    var checkStatus = iframeWindow.layui.table.checkStatus('mainTable');//获取table的elem:"#test"
                                    if (checkStatus.data.length === 0) {
                                        return layer.msg('请选择数据');
                                    }
 
                                    //同步更新表格和缓存对应的值
                                    obj.update({
                                        HCusID: checkStatus.data[0].HItemID,
                                        HCusNumber: checkStatus.data[0].HNumber,
                                        HCusName: checkStatus.data[0].HName
                                    });
                                    layer.close(layer.index); //它获取的始终是最新弹出的某个层,值是由layer内部动态递增计算的
                                }
                                , btn2: function (index, layero) {
                                    //按钮【按钮二】的回调
                                    //return false 开启该代码可禁止点击该按钮关闭
                                },
                                end: function () {
 
                                }
                            });
                        }
                        obj.event = "";
                        return false;
                    }
                })
            }
            //?
            function f_alert(sMsg) {
                layer.alert(sMsg, { icon: 5 });
 
            }
 
            //条码生成
            function SaveBarCodeCreate(sMainSub, CampanyName) {
                $.ajax(
                    {
                        type: "POST",
                        url: GetWEBURL() + "/Sc_BarCode/Sub_SaveBill", //方法所在页面和方法名
                        async: true,
                        data: { "msg": sMainSub, "CampanyName": CampanyName },
                        dataType: "json",
                        success: function (result) {
                            if (result.count == 1) { // 说明验证成功了,
                                table.reload('mainTable1', {
                                    data: result.list // 调用table.reload 重新渲染显示加载追加了数据的表格
                                });
                                //生成成功跳转到条码信息标签页
                                element.tabChange('tab-TabTest', '2'); 
                                //加载档案列表
                                table.reload('mainTable2', {
                                    data: result.data // 调用table.reload 重新渲染显示加载追加了数据的表格
                                });
                            }
                            else {
                                layer.alert(result.Message, { icon: 5 });
                            }
                            layer.closeAll("loading");
                        },
                        error: function (err) {
                            layer.alert(err.Message, { icon: 5 });
                        }
                    });
            }
 
            //条码打印
            function get_PrintReport() {
                var checkStatus = table.checkStatus('mainTable2')
                    , data = checkStatus.data;
                if (checkStatus.data.length>0) {
                    var rows = '';
                    for (var i = 0; i < data.length; i++) {
                        rows += data[i].HItemID.toString() + ',';
                    }
                    rows = rows.substring(rows.length - 1, 0);
                    layer.open({
                        type: 2
                        , area: ['50%', '50%']
                        , title: '打印模版选择'
                        , shade: 0.6 //遮罩透明度
                        , maxmin: false //允许全屏最小化
                        , anim: 0 //0-6的动画形式,-1不开启
                        , content: ['../../BaseSet/SRM_OpenTmpList.html?linterid=' + rows + '&MyMsg=' + rows + '&Type=HGy_BarCodeBill', 'yes']
                        , resize: false
                    })
                }
                else {
                    layer.msg('请选择要打印的条码数据!');
                }
            }
 
            //非空验证
            function AllowLoadData(sSubStr) {
                var Result = true;
                if (typeof (sSubStr) == "undefined" || sSubStr == "") {
                    layer.msg("没有物料明细记录", { icon: 5, btn: ['确认'], time: 2000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                    return Result = false;
                }
                if (typeof (sSubStr) != "undefined" && typeof (sSubStr) != "") {
                    sSubStr = JSON.parse(sSubStr);
                    for (var i = 0; i < sSubStr.length; i++) {
                        if (sSubStr[i].HMainID == "") {
                            layer.msg("明细记录第" + (i + 1) + "行,源单信息为空!", { icon: 5, btn: ['确认'], time: 2000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                            return Result = false;
                        }
                        if (sSubStr[i].HMaterID == "") {
                            layer.msg("明细记录第" + (i + 1) + "行,物料信息为空!", { icon: 5, btn: ['确认'], time: 2000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                            return Result = false;
                        }
                        if (sSubStr[i].HQty == "") {
                            layer.msg("明细记录第" + (i + 1) + "行,数量为空!", { icon: 5, btn: ['确认'], time: 2000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                            return Result = false;
                        }
                    }
                }
                else {
                    return Result = true;
                }
                return Result;
            }
 
            //#endregion
 
 
        });
    </script>
</body>
</html>