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
<!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/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>
    <script src="../../../layuiadmin/PageTitle.js"></script>
    <script src="../../../layuiadmin/grwebapp.js"></script>
    <style type="text/css">
        .layui-form-item .layui-inline {
            margin-right: 0;
        }
 
        html {
            background-color: white;
            color: white;
        }
 
        .layui-table-cell {
            overflow: visible !important;
        }
 
        td .layui-form-select {
            margin-top: -10px;
            margin-left: -15px;
            margin-right: -15px;
        }
 
        .layui-table th, .layui-table td {
            white-space: nowrap; /* 不换行 */
            overflow: hidden; /* 超出内容隐藏 */
            text-overflow: ellipsis; /* 显示省略号 */
        }
    </style>
</head>
<body>
    <div class="layui-fluid" style="padding: 0;">
        <div class="layui-card" style="padding: 15px;">
            <div class="layui-card-body" style="padding: 1px;">
                <form class="layui-form" lay-filter="component-form-group" action="">
                    <div class="layui-card-header">
                        <div class="layui-btn-group">
                            <button type="button" id="add-btn" class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="Saver">保存</button>
                            <button type="button" id="print-btn" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-disabled" lay-submit="" lay-filter="get_Print" disabled>打印</button>
                            <button type="button" id="batchPrint-btn" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-disabled" lay-submit="" lay-filter="get_BatchPrint" disabled>批量打印</button>
                            <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="Exit" style="margin-left:50px !important;">退出</button>
                        </div>
                    </div>
                    <div class="layui-tab" lay-filter="tab-BatchSplit">
                        <h1 style="text-align: center; padding: 10px 0;"><b>流转卡批量拆分</b></h1>
                    </div>
                    <table class="layui-hide" id="mainTable" lay-filter="mainTable" style="margin-top:5px;"></table>
                    <script type="text/html" id="xuhao">
                        {{d.LAY_TABLE_INDEX+1}}
                    </script>
                    <script type="text/html" id="toolbarDemo">
                        <div class="layui-btn-container">
                            <button type="button" class="layui-btn layui-btn-sm" lay-event="btn-CopyLine"><i class="layui-icon layui-icon-form"></i>复制一行</button>
                        </div>
                    </script>
                </form>
            </div>
        </div>
    </div>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script>
        //#region 折叠注释
        //#endregion
        layui.config({
            base: '../../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form', 'laydate', 'table', 'element', 'laydate'], function () {
            //#region 公用变量
            var $ = layui.$
                , admin = layui.admin
                , layer = layui.layer
                , table = layui.table
                , form = layui.form
                , laydate = layui.laydate
                , element = layui.element;
            var sWhere = "";
            var option;
            //#endregion
 
 
            //#region 进入页面即加载
            // 初始化界面
            set_InitGrid();
 
            //获取页面跳转参数
            var params = get_UrlVars();
            if (typeof (params[params[0]]) == "undefined") {
                var OperationType = 1;//操作类型
            } else {
                var OperationType = params[params[0]];//操作类型
                var linterid = params[params[1]];//源单主子id
                var HSouceBillType = params[params[2]];//源单类型
            }
 
            //判断操作类型
            if (OperationType == 1) {//无源单新增
 
            }
            else if (OperationType == 2) {//有源单新增
                get_Display_BatchSplit(linterid)
            }
            else if (OperationType == 3) {//编辑
 
            }
            else {
                layer.alert("未知操作类型!", { icon: 5 });
            }
 
            //#endregion
 
            //#region 头部工具栏事件
            table.on('toolbar(mainTable)', function (obj) {
                var checkStatus = table.checkStatus('mainTable')
                    , data = checkStatus.data;
 
                data[0].HProQty = 0;
                data[0].HSheetQty = Number(data[0].HSheetQty) + Number(1);
 
                switch (obj.event) {
                    case 'btn-CopyLine':
                        if (data.length <= 0) {
                            layer.msg("请选择需要复制的一行!");
                        }
                        else if (data.length > 1) {
                            layer.msg("只能选择复制一行!");
                        }
                        else {
                            //获取新流转卡单号,内码
                            $.ajax({
                                url: GetWEBURL() + "/Web/GetMAXNum_ProcExchange",
                                type: "GET",
                                data: { "HBillType": '3772' },
                                async: false,
                                success: function (d) {
                                    data[0].HInterID = d.data[0].HInterID;
                                    data[0].HBillNo = data[0].HBillNo.substring(0, 13) + '-' + String(Number(data[0].HSheetQty)).padStart(2, '0');
                                }
                            });
                            var copydata = JSON.stringify(data);
 
                            var copydata2 = copydata.substring(1, copydata.length);//去除首行字符'['
                            var copyrow = copydata2.substring(0, copydata2.length - 1);//去除末尾字符']'
                            var HArrIndex = -1;
                            for (var i = 0; i < option.data.length; i++) {
                                if (option.data[i].HICMOInterID == data[0].HICMOInterID && option.data[i].HICMOEntryID == data[0].HICMOEntryID) {
                                    HArrIndex = i;
                                    option.data[i].HSheetQty = Number(option.data[i].HSheetQty) + Number(1);
                                }
                            }
                            if (HArrIndex != -1) {
                                option.data.splice(HArrIndex + 1, 0, JSON.parse(copyrow))
                            }
 
                            //table.cache["mainTable"].push(JSON.parse(copyrow));//将复制的行强转成json追加到表格上
                            //option.data = table.cache["mainTable"];//将数据绑定到data上
                            table.render(option);//将数据渲染到表格上
                        }
                        break;
                }
            });
            //#endregion
 
            //#region 触发事件:包括form.on(){}格式的所有点击事件、选择事件等
            //行内事件
            table.on('tool(mainTable)', function (obj) {
                set_GridCellCheck(obj); //行内快捷键筛选
                set_GridDelete(obj);   //行内删除
 
                var data = obj.data;  //获取当前行的数据                //将obj.data 字符串类型 赋值给data
                if (obj.event == 'HDate') {    //判断接受到的数据字段  id是否为 Hdata
                    var field = $(this).data('field');//获取日期字段
                    laydate.render({
                        elem: this.firstChild        //将日期选择器绑定到触发事件的元素的第一个子元素
                        , show: true                //直接显示       日期选择器,而不是等待用户点击
                        , closeStop: this           // 判断点击日期选择器外部时是否关闭
                        , done: function (nowDate) {    //当日期选择完成时执行的回调函数
                            //时间选择完成,行数据更新
                            data[field] = nowDate;  //data对象中的日期字段
                            obj.update(data);  //更新回调数据
                        }
                    });
                }
            });
 
            //监听单元格编辑  单元格编辑后 变更
            table.on('edit(mainTable)', function (obj) {
                var oldText = $(this).prev().text();
                var value = obj.value //得到修改后的值
                    , data = obj.data //得到所在行所有键值
                    , field = obj.field; //得到字段
 
                switch (field) {
                    case "HProQty":
                        //同步更新表格和缓存对应的值
                        obj.update({
                            HProQty: value
                        });
                        break;
                    default:
                }
                var HICMOQty_useable = data.HUsableQty;//订单剩余可用数量
                var HQty = 0;
                for (let i = 0; i < option.data.length; i++) {
                    if (option.data[i].HICMOInterID == data.HICMOInterID && option.data[i].HICMOEntryID == data.HICMOEntryID) {
                        HQty = Number(HQty) + Number(option.data[i].HProQty)
                    }
                }
                if (HQty > HICMOQty_useable) {
                    layer.alert("生产订单:" + data.HICMOBillNo + ",本次生成流转卡总数:<span style='color: red;'>" + HQty + "</span>,大于订单剩余可生成流转卡数:<span style='color: blue;'>" + HICMOQty_useable + "</span>,请重新输入!");
                    obj.update({
                        HProQty: oldText
                    });
                }
                table.render(option);
            });
 
            //保存按钮
            form.on('submit(Saver)', function (data) {
                if (AllowLoadData(data)) {
                    set_SaveBill(data);
                }
            });
 
            //打印
            form.on('submit(get_Print)', function () {
                get_Print();
            })
 
            //批量打印
            form.on('submit(get_BatchPrint)', function () {
                get_BatchPrint();
            })
 
            //退出按钮
            form.on('submit(Exit)', function () {
                if (params[1] != null) {
                    Pub_Close(1);
                } else if (params[1] == null) {
                    Pub_Close(2);
                }
            })
            //#endregion
 
            //#region 页面方法
            //初始化页面
            function set_InitGrid() {
                option = {
                    elem: '#mainTable'
                    , toolbar: '#toolbarDemo'
                    , limit: 500
                    , height: 500
                    , loading: false
                    , cols: [[ //子表
                        { type: 'checkbox', totalRowText: '合计行' }
                        , { type: 'numbers', title: '序号', width: 100, totalRow: true }
                        , { field: 'HICMOInterID', title: '生产订单内码', width: 100, hide: true }//生产订单内码
                        , { field: 'HICMOEntryID', title: '生产订单子内码', width: 100, hide: true }//生产订单子内码
                        , { field: 'HICMOBillNo', title: '生产订单内码', width: 120 }//生产订单号
                        , { field: 'HWorkShopID', title: '生产车间', width: 100, hide: true }//生产车间内码
                        , { field: 'HMaterID', title: 'HMaterID', width: 100, hide: true }
                        , { field: '物料代码', title: '物料代码', width: 150 }
                        , { field: '物料名称', title: '物料名称', width: 150 }
                        , { field: '规格型号', title: '规格型号', width: 100, hide: true }
                        , { field: 'HQty', title: '订单总数', width: 110 }
                        , { field: 'HFinishQty', title: '已生成流转卡数', width: 130 }
                        , { field: 'HUsableQty', title: '剩余可用数量', width: 130 }
                        , { field: 'HLotcardQty', title: '单张流转卡数', width: 130 }
                        , { field: 'HProQty', title: '流转卡数量', width: 110, edit: 'text' }
                        , { field: 'HBatchNo', title: '批号', width: 110, edit: 'text' }
                        , { field: 'HGroupNumber', title: '班组', width: 110, edit: 'text' }
                        , { field: 'HBatchManager', title: '启用批次', width: 110, hide: true }
                        , { field: 'HRoutingInterID', title: '工艺路线内码', width: 150, hide: true }
                        , { field: 'HRoutingName', title: '工艺路线', width: 170, edit: 'text', event: "HRoutingName" }
                        , { field: 'HSheetQty', title: '拆分流转卡张数', width: 130 }
                        , { field: 'HDate', title: '流转卡日期', width: 120, event: 'HDate' }
                        , { field: 'HInterID', title: '流转卡内码', width: 130, hide: true }
                        , { field: 'HBillNo', title: '流转卡号', width: 170 }
                        , { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 70 }
                    ]]
                }
 
                //初始表格数据
                var rowdata = [{
                    "HICMOInterID": 0, "HICMOEntryID": 0, "HICMOBillNo": "", "HWorkShopID": 0, "HMaterID": 0, "物料代码": ""
                    , "物料名称": "", "规格型号": "", "HQty": 0, "HFinishQty": 0, "HUsableQty": 0, "HLotcardQty": 0
                    , "HProQty": 0, "HRoutingInterID": 0, "HRoutingName": "", "HSheetQty": 0
                    , "HInterID": 0, "HBillNo": "", "HBatchNo": "", "HBatchManager": "", "HGroupNumber": ""
                }];
 
                option.data = rowdata;
                table.render(option);
            }
 
            //批量拆分生产订单生成流转卡
            function get_Display_BatchSplit(linterid) {
                var ajaxLoad = layer.load();
                $.ajax({
                    url: GetWEBURL() + "Sc_ProcessExchangeBill/BatchSpilt",
                    type: "GET",
                    data: { "HInterID": linterid, "user": sessionStorage["HUserName"] },
                    success: function (result) {
                        if (result.code == 1) { // 说明验证成功了,
                            //网格数据赋值
                            var subdata = result.data
                            var rowdata = [];
                            var HInterID = 0;
                            var HBillNo = "";
                            var HSourceInterID = 0;
                            var HSourceEntryID = 0;
                            var k = 01;
                            for (var i = 0; i < subdata.length; i++) {                               
 
                                //首次进入,获取流转卡单号
                                if (i == 0) {
                                    //获取流转卡单号,内码
                                    $.ajax({
                                        url: GetWEBURL() + "/Web/GetMAXNumPDA",
                                        type: "GET",
                                        data: { "HBillType": '3772' },
                                        async: false,
                                        success: function (d) {
                                            HInterID = d.data[0].HInterID;
                                            HBillNo = d.data[0].HBillNo;
                                        }
                                    });
 
                                    HBillNo = HBillNo + '-' + String(k).padStart(2, '0');
                                    HSourceInterID = subdata[i].HICMOInterID;
                                    HSourceEntryID = subdata[i].HICMOEntryID;
                                }
                                else if (HSourceInterID == subdata[i].HICMOInterID && HSourceEntryID == subdata[i].HICMOEntryID) {
                                    //获取流转卡单号,内码
                                    $.ajax({
                                        url: GetWEBURL() + "/Web/GetMAXNum_ProcExchange",
                                        type: "GET",
                                        data: { "HBillType": '3772' },
                                        async: false,
                                        success: function (d) {
                                            HInterID = d.data[0].HInterID;
                                        }
                                    });
                                    HBillNo = HBillNo.substring(0, 13);
                                    k = Number(k) + Number(1);
                                    HBillNo = HBillNo + '-' + String(k).padStart(2, '0');
                                } else if (HSourceInterID != subdata[i].HICMOInterID || HSourceEntryID != subdata[i].HICMOEntryID) {
                                    //获取流转卡单号,内码
                                    $.ajax({
                                        url: GetWEBURL() + "/Web/GetMAXNumPDA",
                                        type: "GET",
                                        data: { "HBillType": '3772' },
                                        async: false,
                                        success: function (d) {
                                            HInterID = d.data[0].HInterID;
                                            HBillNo = d.data[0].HBillNo;
                                        }
                                    });
                                    HBillNo = HBillNo.substring(0, 13);
                                    k = 01;
                                    HBillNo = HBillNo + '-' + String(k).padStart(2, '0');
                                    HSourceInterID = subdata[i].HICMOInterID;
                                    HSourceEntryID = subdata[i].HICMOEntryID;
                                }
 
                              
                                ////获取流转卡单号,内码
                                //$.ajax({
                                //    url: GetWEBURL() + "/Web/GetMAXNumPDA",
                                //    type: "GET",
                                //    data: { "HBillType": '3772' },
                                //    async: false,
                                //    success: function (d) {
                                //        HInterID = d.data[0].HInterID;
                                //        HBillNo = d.data[0].HBillNo;
                                //    }
                                //});
 
                                rowdata.push(
                                    {
                                        "HICMOInterID": subdata[i].HICMOInterID, "HICMOEntryID": subdata[i].HICMOEntryID, "HICMOBillNo": subdata[i].HICMOBillNo
                                        , "HWorkShopID": subdata[i].HWorkShopID, "HMaterID": subdata[i].HMaterID, "物料代码": subdata[i].物料代码
                                        , "物料名称": subdata[i].物料名称
                                        , "规格型号": subdata[i].规格型号, "HQty": subdata[i].HQty, "HFinishQty": subdata[i].HFinishQty
                                        , "HUsableQty": subdata[i].HUsableQty, "HLotcardQty": subdata[i].HLotcardQty, "HProQty": subdata[i].HProQty
                                        , "HRoutingInterID": subdata[i].HRoutingInterID, "HRoutingName": subdata[i].HRoutingName, "HSheetQty": subdata[i].HSheetQty
                                        , "HDate": formatDate(subdata[i].HDate), "HInterID": HInterID, "HBillNo": HBillNo, "HBatchNo": subdata[i].HBatchNo
                                        , "HBatchManager": subdata[i].是否启用批次, "HGroupNumber": ""
                                    }
                                )
                            }
                            var HInterID = 0;
                            var HEntryID = 0;
                            var HRowBackgroundColor = "#E0F5F7";
                            option = {
                                elem: '#mainTable'
                                , toolbar: '#toolbarDemo'
                                , cols: [[ //子表
                                    { type: 'checkbox', totalRowText: '合计行' }
                                    , { type: 'numbers', title: '序号', width: 100, totalRow: true }
                                    , { field: 'HICMOInterID', title: '生产订单内码', width: 100, hide: true }//生产订单内码
                                    , { field: 'HICMOEntryID', title: '生产订单子内码', width: 100, hide: true }//生产订单子内码
                                    , { field: 'HICMOBillNo', title: '生产订单', width: 120 }//生产订单号
                                    , { field: 'HWorkShopID', title: '生产车间内码', width: 100, hide: true }//生产车间内码
                                    , { field: 'HMaterID', title: 'HMaterID', width: 100, hide: true }
                                    , { field: '物料代码', title: '物料代码', width: 150 }
                                    , { field: '物料名称', title: '物料名称', width: 150 }
                                    , { field: '规格型号', title: '规格型号', width: 100, hide: true }
                                    , { field: 'HQty', title: '订单总数', width: 110 }
                                    , { field: 'HFinishQty', title: '已生成流转卡数', width: 130 }
                                    , { field: 'HUsableQty', title: '剩余可用数量', width: 130 }
                                    , { field: 'HLotcardQty', title: '单张流转卡数', width: 130 }
                                    , { field: 'HProQty', title: '流转卡数量', width: 110, edit: 'text' }
                                    , { field: 'HBatchNo', title: '批号', width: 110, edit: 'text' }
                                    , { field: 'HGroupNumber', title: '班组', width: 110, edit: 'text' }
                                    , { field: 'HBatchManager', title: '启用批次', width: 110, hide: true }
                                    , { field: 'HRoutingInterID', title: '工艺路线内码', width: 150, hide: true }
                                    , { field: 'HRoutingName', title: '工艺路线', width: 170, edit: 'text', event: "HRoutingName" }
                                    , { field: 'HSheetQty', title: '拆分流转卡张数', width: 130 }
                                    , { field: 'HDate', title: '流转卡日期', width: 120, event: 'HDate' }
                                    , { field: 'HInterID', title: '流转卡内码', width: 130, hide: true }
                                    , { field: 'HBillNo', title: '流转卡号', width: 170 }
                                    , { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 70 }
                                ]]
                                , data: rowdata
                                , height: 'full-120'
                                , page: true
                                , limits: [50, 200, 500, 5000, 50000]
                                , limit: 200
                                , cellMinWidth: 90
                                , done: function (res, curr, count) {
                                    var that = this.elem.next();
                                    res.data.forEach(function (item, index) {
                                        if (HInterID == 0 && HEntryID == 0) {
                                            HInterID = item.HICMOInterID
                                            HEntryID = item.HICMOEntryID
                                            var tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']").css("background-color", HRowBackgroundColor)
                                        } else if (HInterID == item.HICMOInterID && HEntryID == item.HICMOEntryID) {
                                            var tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']").css("background-color", HRowBackgroundColor)
                                        } else if ((HInterID != item.HICMOInterID || HEntryID != item.HICMOEntryID) && HInterID != 0) {
                                            if (HRowBackgroundColor == "#E0F5F7") {
                                                HRowBackgroundColor = "#E8E5FA"
                                            } else {
                                                HRowBackgroundColor = "#E0F5F7"
                                            }
                                            HInterID = item.HICMOInterID
                                            HEntryID = item.HICMOEntryID
                                            var tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']").css("background-color", HRowBackgroundColor)
                                        }
                                    })
                                }
                            }
                            option.data = rowdata;
                            table.render(option);
 
                            layer.close(ajaxLoad);
                        } else {
                            layer.close(ajaxLoad);
                            layer.alert(result.Message, { icon: 5, btn: ['退出'], time: 100000, offset: 't' });
                        }
                    }, error: function () {
                        layer.close(ajaxLoad);
                        layer.alert("发生错误!", { icon: 5 });
                    }
                });
            }
 
            //#region 保存方法
            function set_SaveBill(data) {
                $('#add-btn').addClass("layui-btn-disabled").attr("disabled", true);//保存按钮禁用
 
                var sSubTable = [];
                for (var i = 0; i < table.cache["mainTable"].length; i++) {
                    if (table.cache["mainTable"][i] != "") {
                        table.cache["mainTable"][i].LAY_TABLE_INDEX = i;
                        sSubTable.push(table.cache["mainTable"][i])
                    }
                    if (table.cache["mainTable"][i].物料名称.indexOf("\"") != -1 || table.cache["mainTable"][i].物料名称.indexOf(";") != -1) {
                        table.cache["mainTable"][i].物料名称 = table.cache["mainTable"][i].物料名称.replace("\"", "”").replace(";", ";")
                    }
                    if (table.cache["mainTable"][i].规格型号.indexOf("\"") != -1 || table.cache["mainTable"][i].规格型号.indexOf(";") != -1) {
                        table.cache["mainTable"][i].规格型号 = table.cache["mainTable"][i].规格型号.replace("\"", "”").replace(";", ";")
                    }
                }
                var sSubStr = JSON.stringify(sSubTable);
                var sMainSub = sSubStr + ";" + sessionStorage["HUserName"];
                var index = layer.load();
 
                $.ajax({
                    type: "POST",
                    url: GetWEBURL() + "/Sc_ProcessExchangeBill/AddBill_BatchSplit", //方法所在页面和方法名
                    async: true,
                    data: { "sMainSub": sMainSub },
                    dataType: "json",
                    success: function (data) {
                        if (data.count == 1) { // 说明验证成功了,
                            layer.msg(data.Message, { icon: 1 });
                            $('#print-btn').removeClass("layui-btn-disabled").attr("disabled", false);//打印按钮启用
                            $('#batchPrint-btn').removeClass("layui-btn-disabled").attr("disabled", false);//批量打印按钮启用
                            layer.close(index);
                        }
                        else {
                            layer.alert(data.Message, { icon: 5 });
                            $('#add-btn').removeClass("layui-btn-disabled").attr("disabled", false);//保存按钮启用
                            layer.close(index);
                        }
                    },
                    error: function (err) {
                        layer.alert("错误:" + err, { icon: 5 });
                        $('#add-btn').removeClass("layui-btn-disabled").attr("disabled", false);//保存按钮启用
                        layer.close(index);
                    }
                });
            }
            //#endregion
 
            //行内F7事件
            function set_GridCellCheck(obj) {
                $(document).off('keydown', ".layui-table-edit").on('keydown', '.layui-table-edit', function (e) {
                    if (event.key == "F7") {
                        //工艺路线
                        if (obj.event == "HRoutingName") {
                            //打开维修项目小窗体
                            layer.open({
                                type: 2
                                , skin: "layui-layer-rim" //加上边框
                                , title: "工艺路线列表"  //标题
                                , closeBtn: 1  //窗体右上角关闭 的 样式
                                , shift: 2 //弹出动画
                                , area: ["90%", "90%"] //窗体大小
                                , maxmin: true //设置最大最小按钮是否显示
                                , content: ['../../计划管理/工艺路线/Gy_RoutingBillList.html?HMaterID=' + obj.data.HMaterID + '&HProID=' + 0, 'yes']
                                , btn: ["确定", "取消"]
                                , btn1: function (index, laero) {
                                    //按钮一  的回调
                                    var iframeWindow = window["layui-layer-iframe" + index];//获取弹框页面
                                    var checkStatus = iframeWindow.layui.table.checkStatus("mainTable");//获取选中的数据
 
                                    if (checkStatus.data.length != 1) {
                                        return layer.msg("请选择一条数据");
                                    }
                                    //更新表格缓存的数据
                                    obj.update({
                                        "HRoutingInterID": checkStatus.data[0].hmainid
                                        , "HRoutingName": checkStatus.data[0].工艺名称
                                    })
                                    layer.close(index);//关闭弹窗
                                }
                            })
                        }
 
                        obj.event = "";
                        return false;
                    }
 
                })
            }
 
            //打印
            function get_Print() {
                var checkStatus = table.checkStatus('mainTable')
                    , data = checkStatus.data;
                if (checkStatus.data.length >= 1) {
                    var HInterID_Arr = [];
 
                    for (var i = 0; i < data.length; i++) {
                        HInterID_Arr.push(data[i].HInterID.toString());
                    }
 
                    layer.open({
                        type: 2
                        , area: ['50%', '50%']
                        , title: '打印模版选择'
                        , shade: 0.6 //遮罩透明度
                        , maxmin: false //允许全屏最小化
                        , anim: 0 //0-6的动画形式,-1不开启
                        , content: ['../../BaseSet/SRM_OpenTmpList.html?linterid=' + HInterID_Arr.toString() + "|" + 0 + '&MyMsg=' + HInterID_Arr.toString() + '&Type=HProcessExchange', 'yes']
                        , resize: false
                    })
                }
                else {
                    layer.msg('请选择要打印的流转卡!');
                }
            }
 
 
            //批量打印
            var time;
            var num = 0;
            function get_BatchPrint() {
                var checkStatus = table.checkStatus('mainTable')
                    , data = checkStatus.data;
 
                if (checkStatus.data.length > 0) {
                    //逻辑删除方法
                    layer.confirm("确认要批量打印吗?", { title: "确认" }, function (index) {
                        time = setInterval(function () {
                            dy_PL(data);
                        }, 2500);
                        //关闭当前frame
                        layer.close(index);
                    })
                }
                else {
                    layer.msg('请选择数据打印!');
                }
            }
 
            function dy_PL(rest) {
                var HInterID = rest[num].HInterID.toString();
                var sWhere = "select cast( b.流水号 as float) 流水号,生产订单号,a.生产数量,a.流转卡数量,a.产品代码,a.单据号,case when ISNULL(a.生产规格,'')='' then a.产品规格 else a.生产规格 end 产品规格,a.产品名称,a.日期,a.单据号,b.工序代码,b.工序名称,a.批号,b.工艺工作中心,b.工艺工艺参数,a.生产车间,b.工段名称,b.生产订单数量 from h_v_Sc_ProcessExchangeBillQuery a left join h_v_Sc_ProcessExchangeBillQuerySub b on a.hmainid=b.hmainid   where b.hmainid in(" + HInterID + ") and b.工序代码 != '9999' order by cast(b.流水号 as int)"
 
                $.ajax({
                    type: "GET",
                    url: GetWEBURL() + "/Gy_SOPBillList/WindowPrintList", //方法所在页面和方法名
                    async: false,
                    data: { "sWhere": sWhere },
                    success: function (data) {
                        if (data.count == 1) { // 说明验证成功了,
 
                            if (data.data.length != 0) {
                                var dataPrint = [];
                                for (var i = 0; i < data.data.length; i++) {
                                    data.data[i]["流水号"] = data.data[i]["流水号"].toFixed(1);
                                    dataPrint.push(data.data[i])
                                }
 
                                var Customer = {
                                    "Table": dataPrint
                                }
 
                                var args = {
                                    type: "print",//打印模式
                                    //type: "preview",//预览模式
                                    showOptionDlg: false, //如果不显示打印对话框而直接打印,将此行注释去掉即可
                                    report: urlAddRandomNo("../../grf/流转卡JSON.grf"),
                                    data: Customer
                                };
 
                                console.log(data.data[0].单据号);
                                //var args = {
                                //    report: urlAddRandomNo("../../grf/cs10.grf"),
                                //    data: Customer
                                //};
                                webapp_ws_ajax_run(args);
 
                                if (rest.length <= num + 1) {
                                    num = 0;
                                    clearInterval(time);
                                } else {
                                    num++;
                                }
 
                            } else {
                                layer.msg("查无数据!");
                            }
 
                        }
                        else {
                            layer.msg(data.Message, { icon: 5 });
                        }
                        layer.closeAll("loading");
                    },
                    error: function (err) {
                        layer.msg("错误:" + err, { icon: 5 });
                    }
                })
 
            }
 
            //表格行内事件删除
            function set_GridDelete(obj) {
                var data = obj.data;
                var rowIndex = $(obj.tr).attr("data-index");
                if (obj.event === 'del') {
                    layer.confirm('真的删除行吗?', function (index) {
                        if (rowIndex === '0') {
                            layer.msg('首行无法删除!!!');
                        } else {
                            var oldData = table.cache["mainTable"];
                            oldData.splice(obj.tr.data('index'), 1)
                            option.data = oldData;//将数据绑定到data上
 
                            for (var i = 0; i < oldData.length; i++) {
                                if (option.data[i].HICMOInterID == data.HICMOInterID && option.data[i].HICMOEntryID == data.HICMOEntryID) {
                                    option.data[i].HSheetQty = Number(option.data[i].HSheetQty) - Number(1);
                                }
                            }
 
                            table.render(option);
                            layer.close(index);
                        }
                    });
                }
            }
 
            //#region 数据校验
            function AllowLoadData(data) {
                var sSubStr = JSON.stringify(table.cache['mainTable']);
 
                if (typeof (sSubStr) != "undefined" && typeof (sSubStr) != "") {
                    sSubStr = JSON.parse(sSubStr);
                    for (var i = 0; i < sSubStr.length; i++) {
                        if (sSubStr[i].HProQty == 0 || sSubStr[i].HProQty == undefined || sSubStr[i].HProQty == null) {
                            layer.msg("明细记录第" + (i + 1) + "行,流转卡数量为0!", { icon: 5, btn: ['确认'], time: 4000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                            return Result = false;
                        }
                        if (sSubStr[i].HRoutingInterID == 0 || sSubStr[i].HRoutingInterID == undefined || sSubStr[i].HRoutingInterID == null) {
                            layer.msg("明细记录第" + (i + 1) + "行,工艺路线未选择!", { icon: 5, btn: ['确认'], time: 4000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                            return Result = false;
                        }
                        if (sSubStr[i].HICMOInterID == 0 || sSubStr[i].HICMOInterID == undefined || sSubStr[i].HICMOInterID == null) {
                            layer.msg("明细记录第" + (i + 1) + "行,生产订单主内码获取异常,请联系管理员处理!", { icon: 5, btn: ['确认'], time: 4000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                            return Result = false;
                        }
                        if (sSubStr[i].HICMOEntryID == 0 || sSubStr[i].HICMOEntryID == undefined || sSubStr[i].HICMOEntryID == null) {
                            layer.msg("明细记录第" + (i + 1) + "行,生产订单主内码获取异常,请联系管理员处理!", { icon: 5, btn: ['确认'], time: 4000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                            return Result = false;
                        }
                        if (sSubStr[i].HBatchManager == "是" && sSubStr[i].HBatchNo == "") {
                            layer.msg("明细记录第" + (i + 1) + "行,物料启用批次管理,请输入批号信息!", { icon: 5, btn: ['确认'], time: 4000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                            return Result = false;
                        }
                    }
                }
 
                return true;
            }
            //#endregion
 
            //#endregion
 
 
            //以上是layui模块
        });
 
    </script>
</body>
</html>