杨乐
2022-01-19 587f10ff735c7e291ae0ab4de68758b503d6cfb3
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
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>工序计划单</title>
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
    <script src="../../../layuiadmin/zgqCustom/zgqCustom.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>
 
    <style>
        .main-btn { /*头部主按钮*/
            padding: 0 2px; /*调整按钮左右空隙大小*/
            height: 30px;
            line-height: 30px;
        }
 
        .btn-title {
            font-size: 16px;
        }
    </style>
</head>
<body>
    <div class="layui-fluid" style="padding: 0;">
        <div class="layui-card" style="padding: 2px;background-color: #efefef;">
            <div class="layui-card-body" style="padding: 1px;">
                <form class="layui-form" action="" lay-filter="formData" style="background-color:white;">
                    <div style="padding: 10px;">
                        <button class="layui-btn layuiadmin-btn-order main-btn" type="button" lay-submit="" lay-filter="btnSearch" id="btnSearch">
                            <i class="layui-icon layui-icon-print layuiadmin-button-btn"><span class="btn-title">预览</span></i>
                        </button>
                        <button class="layui-btn layuiadmin-btn-order main-btn" type="button" lay-submit="" lay-filter="btnSearch" id="btnSearch">
                            <i class="layui-icon layui-icon-add-1 layuiadmin-button-btn"><span class="btn-title">新增</span></i>
                        </button>
                        <button class="layui-btn layuiadmin-btn-order main-btn" type="button" lay-submit="" lay-filter="btnSearch" id="btnSearch">
                            <i class="layui-icon layui-icon-edit layuiadmin-button-btn"><span class="btn-title">修改</span></i>
                        </button>
                        <button class="layui-btn layuiadmin-btn-order main-btn" type="button" lay-submit="" lay-filter="btnSave" id="btnSave">
                            <i class="layui-icon layui-icon-delete layuiadmin-button-btn"><span class="btn-title">保存</span></i>
                        </button>
                    </div>
                    <div class="layui-tab" lay-filter="tab-POStockInBill">
                        <ul class="layui-tab-title" lay-filter="tab-all">
                            <li lay-id="1" style="padding:1px;" class="layui-this">基本信息</li>
                        </ul>
                        <div class="layui-tab-content">
                            <!--基本信息-->
                            <div class="layui-tab-item layui-show">
                                <div class="layui-form-item" style="padding-top: 10px;">
                                    <div class="layui-row">
                                        <div class="layui-inline">
                                            <label class="layui-form-label" style="width: 85px;">单据号</label>
                                            <div class="layui-input-block" style="margin-left: 120px;">
                                                <input type="text" class="layui-input" name="HBillNo" lay-verify="HBillNo" id="HBillNo" style="background-color:#efefef4d;" readonly>
                                                <input type="hidden" name="HInterID" id="HInterID" lay-verify="HInterID">
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label" style="width: 85px;">日期</label>
                                            <div class="layui-input-block" style="margin-left: 120px;">
                                                <input type="date" class="layui-input" lay-verify="HDate" name="HDate" id="HDate" style="padding-left: 32px;">
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label" style="width: 85px;">任务单号</label>
                                            <div class="layui-input-block" style="margin-left: 77px;">
                                                <input type="text" class="layui-input" name="HICMOBillNo" lay-verify="HICMOBillNo" id="HICMOBillNo" style="width: 60%;display: inline-block;">
                                                <!--<input type="hidden" class="layui-input" name="HRepairID" lay-verify="HRepairID" id="HRepairID" value="0">-->
                                                <button class="layui-btn layuiadmin-btn-order" type="button" lay-submit="" lay-filter="" id="" style="padding: 0 10px;float: left;margin-right: 3px;background-color:gainsboro;">
                                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn" style="color:black;"></i>
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-row">
                                        <div class="layui-inline">
                                            <label class="layui-form-label" style="width: 85px;">产品代码</label>
                                            <div class="layui-input-block"style="margin-left: 120px;">
                                                <input type="text" class="layui-input" lay-verify="HMaterNumber" name="HMaterNumber" id="HMaterNumber" style="background-color:#efefef4d;" readonly>
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label" style="width: 85px;">产品</label>
                                            <div class="layui-input-block" style="margin-left: 77px;">
                                                <input type="text" class="layui-input" name="HMaterIDName" lay-verify="HMaterIDName" id="HMaterIDName" style="background-color:#efefef4d;width: 60%;display: inline-block;" readonly>
                                                <input type="hidden" class="layui-input" name="HMaterID" lay-verify="HMaterID" id="HMaterID" value="0">
                                                <button class="layui-btn layuiadmin-btn-order" type="button" lay-submit="" lay-filter="btnHMaterID" id="btnHMaterID" style="padding: 0 10px;float: left;margin-right: 3px;background-color:gainsboro;">
                                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn" style="color:black;"></i>
                                                </button>
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label" style="width: 65px;">规格型号</label>
                                            <div class="layui-input-block" style="margin-left: 100px;">
                                                <input type="text" class="layui-input" lay-verify="HMaterIDNum" name="HMaterIDNum" id="HMaterIDNum" style="background-color:#efefef4d;" readonly>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-row">
                                        <div class="layui-inline">
                                            <label class="layui-form-label" style="width: 85px;">单位代码</label>
                                            <div class="layui-input-block" style="margin-left: 120px;">
                                                <input type="text" class="layui-input" lay-verify="HUnitNumber" name="HUnitNumber" id="HUnitNumber" style="background-color:#efefef4d;" readonly>
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label" style="width: 85px;">单位</label>
                                            <div class="layui-input-block" style="margin-left: 77px;">
                                                <input type="text" class="layui-input" name="HUnitIDName" lay-verify="HUnitIDName" id="HUnitIDName" style="background-color:#efefef4d;width: 60%;display: inline-block;" readonly>
                                                <input type="hidden" class="layui-input" name="HUnitID" lay-verify="HUnitID" id="HUnitID" value="0">
                                                <button class="layui-btn layuiadmin-btn-order" type="button" lay-submit="" lay-filter="btnHUnitID" id="btnHUnitID" style="padding: 0 10px;float: left;margin-right: 3px;background-color:gainsboro;">
                                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn" style="color:black;"></i>
                                                </button>
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label" style="width: 70px;">内部单据号</label>
                                            <div class="layui-input-block" style="margin-left: 100px;">
                                                <input type="text" class="layui-input" lay-verify="HInnerBillNo" name="HInnerBillNo" id="HInnerBillNo">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-row">
                                        <div class="layui-inline">
                                            <label class="layui-form-label" style="width: 85px;">计划开工日期</label>
                                            <div class="layui-input-block" style="margin-left: 120px;">
                                                <input type="date" class="layui-input" lay-verify="HPlanBeginDate" name="HPlanBeginDate" id="HPlanBeginDate" style="padding-left: 32px;">
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label" style="width: 85px;">计划完工日期</label>
                                            <div class="layui-input-block" style="margin-left: 130px;">
                                                <input type="date" class="layui-input" lay-verify="HPlanEndDate" name="HPlanEndDate" id="HPlanEndDate" style="padding-left: 32px;">
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label" style="width: 85px;">生产数量</label>
                                            <div class="layui-input-block" style="margin-left: 120px;">
                                                <input type="text" class="layui-input" lay-verify="HPlanQty" name="HPlanQty" id="HPlanQty">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-row">
                                        <div class="layui-inline" style="width: 56%;">
                                            <label class="layui-form-label" style="width: 85px;">摘要</label>
                                            <div class="layui-input-block" style="margin-left: 120px;">
                                                <input type="text" class="layui-input" name="HExplanation" id="HExplanation" lay-verify="HExplanation" placeholder="请输入内容" onmouseover="this.title=this.value">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-row">
                                        <div class="layui-inline" style="width: 56%;">
                                            <label class="layui-form-label" style="width: 85px;">备注</label>
                                            <div class="layui-input-block" style="margin-left: 120px;">
                                                <input type="hidden" class="layui-input" name="HMaker" id="HMaker" lay-verify="HMaker" value="">
                                                <input type="hidden" class="layui-input" name="HUpDater" id="HUpDater" lay-verify="HUpDater" value="">
                                                <input type="text" class="layui-input" name="HRemark" id="HRemark" lay-verify="HRemark" placeholder="请输入内容" onmouseover="this.title=this.value">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <table class="layui-hide" id="mainTable" lay-filter="mainTable"></table>
                    <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>
                </form>
            </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>
        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
                , element = layui.element;
            //#endregion
 
             //#region 进入页面即加载
 
            var params = getUrlVars();
            var OperationType = params[params[0]]; //从参数中获取 数据类型  添加 保存
            var linterid = params[params[1]]; //从参数中获取 单据内码
            var HSouceBillType = params[params[2]];  //从单据获取 源单类型
            var linteridSub = params[params[3]];  //从参数获取 子表级别
 
            //判断是否新增
            if (linterid == null || linterid == 0) {
                OperationType = 1;
                linteridSub = -1;
                $.ajax({
                    url: GetWEBURL() + "/Web/GetMAXNum",
                    type: "GET",
                    data: { "HBillType": '3715' },
                    success: function (d) {
                        //赋值
                        $("#HInterID").val(d.data[0].HInterID);
                        $("#HBillNo").val(d.data[0].HBillNo);
                    }
                });
            }
            else {//如果修改则走下面 new
                RoadBillMain(linterid, linteridSub);
            }
          
            //初始化界面
            set_ClearBill();
 
            //子表  初始化表格数据
            var option = {
                elem: '#mainTable'
                , toolbar: '#toolbarDemo'
                , limit: 500 //每页默认显示的数量
                , cellMinWidth: 120
                , height: 400
                , cols: [[ //表头
                    { type: 'checkbox', totalRowText: '合计行' }
                    , { type: 'numbers', title: '序号', totalRow: true }
                    , { field: 'HProcNo', title: '工序号', edit: 'text' }
                   
                    , { field: '工序代码', title: '工序代码', edit: 'text', event:"hprocid" }//f7
                    , { field: '工序', title: '工序'}
                    , { field: 'hprocid', title: '工序id', hide: true}// ,hide: true
 
                    , { field: 'HWorkRemark', title: '加工说明', edit: 'text' }
 
                    , { field: '工作中心', title: '工作中心', edit: 'text', event: "HCenterID"  }//f7
                    , { field: 'HCenterID', title: '工作中心id', hide: true}// hide: true
 
                    , { field: '加工车间代码', title: '加工车间代码', edit: 'text', event: "HDeptID"  }//f7
                    , { field: '加工车间', title: '加工车间'}
                    , { field: 'HDeptID', title: '加工车间代码id', hide: true}// hide: true
 
                    , { field: '班组代码', title: '班组代码', edit: 'text', event: "HGroupID"  }//f7
                    , { field: '班组', title: '班组' }
                    , { field: 'HGroupID', title: '班组代码id', hide: true}// hide: true
 
                    , { field: '操作员代码', title: '操作工代码', edit: 'text', event: "HWorkerID"  }//f7
                    , { field: '操作员', title: '操作工' }
                    , { field: 'HWorkerID', title: '操作工代码id', hide: true }// hide: true
 
                    , { field: '生产资源', title: '生产资源', edit: 'text', event: "HSourceID"  }//f7
                    , { field: 'HSourceID', title: '生产资源id', hide: true }// hide: true
 
                    , { field: 'HQty', title: '计划数量', edit: 'text' }
                    , { field: 'HWorkingQty', title: '在制品数量', edit: 'text' }
                    , { field: 'HTimeUnit', title: '时间单位', edit: 'text' }
                    , { field: 'HPlanWorkTimes', title: '计划加工时间', edit: 'text' }
                    , { field: 'hplanbegindate', title: '计划开工时间', edit: 'text' }
                    , { field: 'hplanenddate', title: '计划完工时间', edit: 'text' }
                    , { field: 'HICMOInterID', title: '任务ID', edit: 'text' }
                    , { field: 'HICMOBillNo', title: '任务单号', edit: 'text' }
                    , { field: 'HBeginDayQty', title: '开工余量(天数)', edit: 'text' }
                    , { field: 'HBeginFixQty', title: '开工余量(固数)', edit: 'text' }
                    , { field: 'HFixWorkDays', title: '上道固定天数', edit: 'text' }
                    , { field: 'HTrunWorkDays', title: '上道循环周期', edit: 'text' }
                    , { field: 'HReadyTimes', title: '本道准备时间', edit: 'text' }
                    , { field: 'HReadyTime', title: '准备时间', edit: 'text' }
                    , { field: 'HQueueTime', title: '排队时间', edit: 'text' }
                    , { field: 'HMoveTime', title: '转移时间', edit: 'text' }
                    , { field: 'HSeOrderInterID', title: '销售订单主ID', edit: 'text' }
                    , { field: 'HSeOrderEntryID', title: '销售订单子ID', edit: 'text' }
                    , { field: 'HSeOrderBillNo', title: '销售订单号', edit: 'text' }
                    , { fixed: 'right', title: '操作', toolbar: '#barDemo' }
                ]]
            };
            var rowdata = [{
                "HProcNo": "", "工序代码": "", "工序": "", "hprocid": 0, "HWorkRemark": "",
                "工作中心": "", "HCenterID": 0, "加工车间代码": "", "加工车间": "", "HDeptID": 0,
                "班组代码": "", "班组": "", "HGroupID": 0, "操作员代码": "", "操作员": "",
                "HWorkerID": 0, "生产资源": "", "HSourceID": 0, "HQty": "", "HWorkingQty": "",
                "HTimeUnit": "", "HPlanWorkTimes": "", "hplanbegindate": null, "hplanenddate": null, "HICMOInterID": "",
                "HICMOBillNo": "", "HBeginDayQty": "", "HBeginFixQty": "", "HFixWorkDays": "", "HTrunWorkDays": "",
                "HReadyTimes": "", "HReadyTime": "", "HQueueTime": "", "HMoveTime": "", "HSeOrderInterID": "",
                "HSeOrderEntryID": "", "HSeOrderBillNo": ""
            }];
            option.data = rowdata;
            table.render(option);
 
            //#endregion
 
            //#region  触发事件:包括form.on(){}格式的所有点击事件、选择事件等
 
            //产品按钮
            form.on("submit(btnHMaterID)", function () {
                CheckHMaterID();
            })
 
            //单位按钮
            form.on("submit(btnHUnitID)", function () {
                CheckHUnitID();
            })
 
            //保存提交
            form.on('submit(btnSave)', function (data) {//提交
                //为空验证
                if (AllowLoadData(data)) {
                    set_AddNew(data);
                }
            });
 
            //#region 子表头部触发事件
 
            //头工具栏事件
            table.on('toolbar(mainTable)', function (obj) {
                var checkStatus = table.checkStatus('mainTable')
                    , data = checkStatus.data;
                //新增行表格数据
                var NewRow = {
                    "HProcNo": "", "工序代码": "", "工序": "", "hprocid": 0, "HWorkRemark": "",
                    "工作中心": "", "HCenterID": 0, "加工车间代码": "", "加工车间": "", "HDeptID": 0,
                    "班组代码": "", "班组": "", "HGroupID": 0, "操作员代码": "", "操作员": "",
                    "HWorkerID": 0, "生产资源": "", "HSourceID": 0, "HQty": "", "HWorkingQty": "",
                    "HTimeUnit": "", "HPlanWorkTimes": "", "hplanbegindate": null, "hplanenddate": null, "HICMOInterID": "",
                    "HICMOBillNo": "", "HBeginDayQty": "", "HBeginFixQty": "", "HFixWorkDays": "", "HTrunWorkDays": "",
                    "HReadyTimes": "", "HReadyTime": "", "HQueueTime": "", "HMoveTime": "", "HSeOrderInterID": "",
                    "HSeOrderEntryID": "", "HSeOrderBillNo": ""
                };
                switch (obj.event) {
                    case 'btn-AddLine':
                        table.cache["mainTable"].push(NewRow);
                        option.data = table.cache["mainTable"];
                        table.render(option);
                        break;
                    case 'btn-CopyLine':
                        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);//将数据渲染到表格上
                            //layer.alert(copyrow);
                        }
                        break;
                }
            });
 
            //行内事件
            table.on('tool(mainTable)', function (obj) {
                set_GridDelete(obj);   //行内删除
                set_GridCellCheck(obj); //行内快捷键筛选
            });
 
             //#endregion
 
            //#endregion
 
             //#region 此页面所有的方法
 
            // 初始化界面
            function set_ClearBill() {
                //制单人
                $("#HMaker").val(sessionStorage["HUserName"]);
                //修改人
                $("#HUpDater").val(sessionStorage["HUserName"]);
                //初始化日期
                $("#HPlanBeginDate").val(Format(new Date(), "yyyy-MM-dd"));
                $("#HPlanEndDate").val(Format(new Date(), "yyyy-MM-dd"));
                $("#HDate").val(Format(new Date(), "yyyy-MM-dd"));
            }
 
            //产品选择页面
            function CheckHMaterID() {
                layer.open({
                    type: 2 //弹窗类型
                    , skin: "layui-layer-rim"  //加上边框
                    , title: "物料表" //标题
                    , area: ["90%", "90%"] //大小
                    , shift: 2  //弹出动画
                    , content: ["../../Baseset/基础资料/Gy_MaterialList.html", "yes"]
                    , btn: ["确定", "取消"]
                    , btn1: function (index) {  //按钮一 回调
                        var iframeWindow = window['layui-layer-iframe' + index]; //获取弹窗页面
                        var checkStatus = iframeWindow.layui.table.checkStatus("mainTable"); //获取选中行数据
 
                        if (checkStatus.data.length != 1) {
                            return layer.msg("请选择一条数据");
                        }
 
                        //获取数据
                        $("#HMaterNumber").val(checkStatus.data[0].HNumber);//产品代码
                        $("#HMaterIDName").val(checkStatus.data[0].HName);//产品名称
                        $("#HMaterID").val(checkStatus.data[0].HItemID);//产品id
                        $("#HMaterIDNum").val(checkStatus.data[0].HModel);//产品规格型号
 
                        //关闭页面
                        layer.close(index);
                    }
                })
            }
 
            //单位选择页面
            function CheckHUnitID() {
                layer.open({
                    type: 2  //弹窗类型
                    , skin: "layui-layer-rim"  //加上边框
                    , area: ["90%", "90%"]  //大小
                    , title:"单位列表"  //标题
                    , shift: 2 //弹出动画
                    , content: ["../../Baseset/基础资料/Gy_UnitList.html"]
                    , btn: ["确定", "取消"]
                    , btn1: function (index) {
                        var iframeWindow = window['layui-layer-iframe' + index]  //获取弹框页面
                        var checkStatus = iframeWindow.layui.table.checkStatus('mainTable'); //获取选中行数据
 
                        if (checkStatus.data.length != 1) {
                            return layer.msg("请选择一条数据!");
                        }
                        else {
                            //获取数据
                            $("#HUnitNumber").val(checkStatus.data[0].HNumber);//单位代码
                            $("#HUnitID").val(checkStatus.data[0].HItemID);//单位id
                            $("#HUnitIDName").val(checkStatus.data[0].HName);//单位名称
 
                            //关闭页面
                            layer.close(index);
                        }
                    }
                })
            }
 
            //行内删除
            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();
                            option.data = table.cache["mainTable"];//将数据绑定到data上
                            table.reload(option);
                            layer.close(index);
                        }
                    });
                }
            }
 
            //行内快捷键
            function set_GridCellCheck(obj) {
                $(document).off('keydown', ".layui-table-edit").on('keydown', ".layui-table-edit", function (e) {
                    if (event.key == "F7") {
                        //工序
                        if (obj.event == "hprocid") {
                            layer.open({
                                type: 2 //弹窗类型
                                , skin: "layui-layer-rim" //加上边框
                                , title: "工序表" //标题
                                , closeBtn: 1  //窗体右上角 关闭的样式
                                , shift: 2 //弹出动画
                                , area: ["90%", "90%"] //窗体大小
                                , maxmin: true //设置窗体最大最小按钮是否显示
                                , content: ["../../Baseset/基础资料/Gy_ProcList.html", "yes"]
                                , btn: ["确定", "取消"]
                                , btn1: function (index) {//按钮一 回调
                                    var iframeWindow = window["layui-layer-iframe" + index]; //获取弹窗页面
                                    var checkStatus = iframeWindow.layui.table.checkStatus("mainTable"); //获取选中行数据
 
                                    if (checkStatus.data.length != 1) {
                                        return layer.msg("请选中一条数据!");
                                    }
 
                                    //获取数据/绑定数据
                                    obj.update({
                                        "工序代码": checkStatus.data[0].工序代码
                                        , "工序": checkStatus.data[0].工序
                                        , "hprocid": checkStatus.data[0].HItemID
                                    })
 
                                    //关闭页面
                                    layer.close(index);
                                }
                            })
                        }
                        //工作中心
                        if (obj.event == "HCenterID") {
                            layer.open({
                                type: 2 //弹窗类型
                                , skin: "layui-layer-rim" //加上边框
                                , title: "工作中心表" //标题
                                , closeBtn: 1  //窗体右上角 关闭的样式
                                , shift: 2 //弹出动画
                                , area: ["90%", "90%"] //窗体大小
                                , maxmin: true //设置窗体最大最小按钮是否显示
                                , content: ["../../Baseset/基础资料/Gy_WorkCenterList.html", "yes"]
                                , btn: ["确定", "取消"]
                                , btn1: function (index) {//按钮一 回调
                                    var iframeWindow = window["layui-layer-iframe" + index]; //获取弹窗页面
                                    var checkStatus = iframeWindow.layui.table.checkStatus("mainTable"); //获取选中行数据
 
                                    if (checkStatus.data.length != 1) {
                                        return layer.msg("请选中一条数据!");
                                    }
 
                                    //获取数据/绑定数据
                                    obj.update({
                                         "工作中心": checkStatus.data[0].工作中心
                                        , "HCenterID": checkStatus.data[0].HItemID
                                    })
 
                                    //关闭页面
                                    layer.close(index);
                                }
                            })
                        }
                        //加工车间
                        if (obj.event == "HDeptID") {
                            layer.open({
                                type: 2 //弹窗类型
                                , skin: "layui-layer-rim" //加上边框
                                , title: "部门表" //标题
                                , closeBtn: 1  //窗体右上角 关闭的样式
                                , shift: 2 //弹出动画
                                , area: ["90%", "90%"] //窗体大小
                                , maxmin: true //设置窗体最大最小按钮是否显示
                                , content: ["../../Baseset/基础资料/Gy_DepartmentList.html", "yes"]
                                , btn: ["确定", "取消"]
                                , btn1: function (index) {//按钮一 回调
                                    var iframeWindow = window["layui-layer-iframe" + index]; //获取弹窗页面
                                    var checkStatus = iframeWindow.layui.table.checkStatus("mainTable"); //获取选中行数据
 
                                    if (checkStatus.data.length != 1) {
                                        return layer.msg("请选中一条数据!");
                                    }
 
                                    //获取数据/绑定数据
                                    obj.update({
                                        "加工车间代码": checkStatus.data[0].HNumber
                                        , "加工车间": checkStatus.data[0].HName
                                        , "HDeptID": checkStatus.data[0].HItemID
                                    })
 
                                    //关闭页面
                                    layer.close(index);
                                }
                            })
                        }
                        //班组
                        if (obj.event == "HGroupID") {
                            layer.open({
                                type: 2 //弹窗类型
                                , skin: "layui-layer-rim" //加上边框
                                , title: "班组表" //标题
                                , closeBtn: 1  //窗体右上角 关闭的样式
                                , shift: 2 //弹出动画
                                , area: ["90%", "90%"] //窗体大小
                                , maxmin: true //设置窗体最大最小按钮是否显示
                                , content: ["../../基础资料/工资基础资料/Gy_Group.html", "yes"]
                                , btn: ["确定", "取消"]
                                , btn1: function (index) {//按钮一 回调
                                    var iframeWindow = window["layui-layer-iframe" + index]; //获取弹窗页面
                                    var checkStatus = iframeWindow.layui.table.checkStatus("mainTable"); //获取选中行数据
 
                                    if (checkStatus.data.length != 1) {
                                        return layer.msg("请选中一条数据!");
                                    }
 
                                    //获取数据/绑定数据
                                    obj.update({
                                        "班组代码": checkStatus.data[0].班组代码
                                        , "班组": checkStatus.data[0].班组名称
                                        , "HGroupID": checkStatus.data[0].HItemID
                                    })
 
                                    //关闭页面
                                    layer.close(index);
                                }
                            })
                        }
                        //操作工
                        if (obj.event == "HWorkerID") {
                            layer.open({
                                type: 2 //弹窗类型
                                , skin: "layui-layer-rim" //加上边框
                                , title: "人员表" //标题
                                , closeBtn: 1  //窗体右上角 关闭的样式
                                , shift: 2 //弹出动画
                                , area: ["90%", "90%"] //窗体大小
                                , maxmin: true //设置窗体最大最小按钮是否显示
                                , content: ["../../Baseset/基础资料/Gy_EmployeeList.html", "yes"]
                                , btn: ["确定", "取消"]
                                , btn1: function (index) {//按钮一 回调
                                    var iframeWindow = window["layui-layer-iframe" + index]; //获取弹窗页面
                                    var checkStatus = iframeWindow.layui.table.checkStatus("mainTable"); //获取选中行数据
 
                                    if (checkStatus.data.length != 1) {
                                        return layer.msg("请选中一条数据!");
                                    }
 
                                    //获取数据/绑定数据
                                    obj.update({
                                        "操作员": checkStatus.data[0].HName
                                        , "操作员代码": checkStatus.data[0].HNumber
                                        , "HWorkerID": checkStatus.data[0].HItemID
                                    })
 
                                    //关闭页面
                                    layer.close(index);
                                }
                            })
                        }
                        //生产资源
                        if (obj.event == "HSourceID") {
                            layer.open({
                                type: 2 //弹窗类型
                                , skin: "layui-layer-rim" //加上边框
                                , title: "生产资源表" //标题
                                , closeBtn: 1  //窗体右上角 关闭的样式
                                , shift: 2 //弹出动画
                                , area: ["90%", "90%"] //窗体大小
                                , maxmin: true //设置窗体最大最小按钮是否显示
                                , content: ["../../基础资料/生产基础资料/Gy_Source.html", "yes"]
                                , btn: ["确定", "取消"]
                                , btn1: function (index) {//按钮一 回调
                                    var iframeWindow = window["layui-layer-iframe" + index]; //获取弹窗页面
                                    var checkStatus = iframeWindow.layui.table.checkStatus("mainTable"); //获取选中行数据
 
                                    if (checkStatus.data.length != 1) {
                                        return layer.msg("请选中一条数据!");
                                    }
 
                                    //获取数据/绑定数据
                                    obj.update({
                                        "生产资源": checkStatus.data[0].生产资源名称
                                        , "HSourceID": checkStatus.data[0].HItemID
                                    })
 
                                    //关闭页面
                                    layer.close(index);
                                }
                            })
                        }
                    }
                })
            }
 
            //保存数据
            function set_AddNew(data) {
                //过滤子表删除之后留下的空数据
                var num = [];
                for (var i = 0; i < table.cache['mainTable'].length; i++) {
                     //给不能为空的数据 赋值(子)
                    if (table.cache['mainTable'][i] != "") {
                        if (table.cache['mainTable'][i].HProcNo == "") {
                            table.cache['mainTable'][i].HProcNo = 0;
                        }
                        if (table.cache['mainTable'][i].HQty == "") {
                            table.cache['mainTable'][i].HQty = 0;
                        }
                        if (table.cache['mainTable'][i].HWorkingQty == "") {
                            table.cache['mainTable'][i].HWorkingQty = 0;
                        }
                        if (table.cache['mainTable'][i].HPlanWorkTimes == "") {
                            table.cache['mainTable'][i].HPlanWorkTimes = 0;
                        }
                        if (table.cache['mainTable'][i].HICMOInterID == "") {
                            table.cache['mainTable'][i].HICMOInterID = 0;
                        }
                        if (table.cache['mainTable'][i].HBeginDayQty == "") {
                            table.cache['mainTable'][i].HBeginDayQty = 0;
                        }
                        if (table.cache['mainTable'][i].HBeginFixQty == "") {
                            table.cache['mainTable'][i].HBeginFixQty = 0;
                        }
                        if (table.cache['mainTable'][i].HFixWorkDays == "") {
                            table.cache['mainTable'][i].HFixWorkDays = 0;
                        }
                        if (table.cache['mainTable'][i].HTrunWorkDays == "") {
                            table.cache['mainTable'][i].HTrunWorkDays = 0;
                        }
                        if (table.cache['mainTable'][i].HReadyTimes == "") {
                            table.cache['mainTable'][i].HReadyTimes = 0;
                        }
                        if (table.cache['mainTable'][i].HReadyTime == "") {
                            table.cache['mainTable'][i].HReadyTime = 0;
                        }
                        if (table.cache['mainTable'][i].HQueueTime == "") {
                            table.cache['mainTable'][i].HQueueTime = 0;
                        }
                        if (table.cache['mainTable'][i].HMoveTime == "") {
                            table.cache['mainTable'][i].HMoveTime = 0;
                        }
                        if (table.cache['mainTable'][i].HSeOrderInterID == "") {
                            table.cache['mainTable'][i].HSeOrderInterID = 0;
                        }
                        if (table.cache['mainTable'][i].HSeOrderEntryID == "") {
                            table.cache['mainTable'][i].HSeOrderEntryID = 0;
                        }
 
                        num.push(table.cache['mainTable'][i]);
                    }
                }
 
                //给不能为空的数据 赋值(主)
                if (data.field.HPlanQty == "") {
                    data.field.HPlanQty = 0
                }
 
 
                var sMainStr = JSON.stringify(data.field);
                var sSubStr = JSON.stringify(num);
                var hentryid = linteridSub;//子表 排序id
                var sMainSub = sMainStr + ';' + sSubStr + ';' + hentryid + ';' + OperationType;
                var index = layer.load();
 
                //console.log(JSON.stringify(table.cache['mainTable'][0]))
                //return false;
                $.ajax({
                    type: "POST",
                    url: GetWEBURL() + "/Sc_ProcessMangement/AddBill",
                    async: true,
                    data: { "sMainSub": sMainSub },
                    dataType: "json",
                    success: function (data) {
                        if (data.count == 1) {
                            layer.close(index);
                            layer.msg("提交成功");
                        }
                        else {
                            layer.close(index);
                            layer.msg(data.Message, { icon: 5, btn: ['确认'], time: 100000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                        }
                    },
                    error: function (err) {
                        layer.close(index);
                        layer.msg("错误:" + err, { icon: 5, btn: ['确认'], time: 100000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                    }
                });
            }
 
            //编辑
            function RoadBillMain(linterid, linteridSub) {
                var sWhere = " and hmainid ='" + linterid + "' and hsubid='" + linteridSub + "' ";
 
                $.ajax({
                    url: GetWEBURL() + '/Sc_ProcessMangement/MES_Sc_ProcessPlanMain_Json',
                    type: "GET",
                    data: { "sWhere": sWhere },
                    success: function (d) {
                        //主表
                        form.val("formData", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
                            "HBillNo": d.data[0].单据号
                            , "HInterID": d.data[0].hmainid
                            , "HDate": Format(new Date(d.data[0].日期), "yyyy-MM-dd")
                            , "HICMOBillNo": d.data[0].任务单号
                            , "HMaterNumber": d.data[0].物料代码
                            , "HMaterIDName": d.data[0].物料名称
                            , "HMaterID": d.data[0].HMaterID
                            , "HMaterIDNum": d.data[0].规格型号
                            , "HUnitNumber": d.data[0].计量单位代码
                            , "HUnitIDName": d.data[0].计量单位
                            , "HUnitID": d.data[0].hunitid
                            , "HInnerBillNo": d.data[0].内部单据号
                            , "HPlanBeginDate": Format(new Date(d.data[0].计划开工日期), "yyyy-MM-dd")
                            , "HPlanEndDate": Format(new Date(d.data[0].计划完工日期), "yyyy-MM-dd")
                            , "HPlanQty": d.data[0].生产数量
                            , "HExplanation": d.data[0].摘要
                            , "HRemark": d.data[0].表头备注
                        });
                        //子表
                        var rowdata = [{
                            "HProcNo": d.data[0].工序号, "工序代码": d.data[0].工序代码, "工序": d.data[0].工序, "hprocid": d.data[0].hprocid, "HWorkRemark": d.data[0].加工说明,
                            "工作中心": d.data[0].工作中心, "HCenterID": d.data[0].HCenterID, "加工车间代码": d.data[0].加工车间代码, "加工车间": d.data[0].加工车间, "HDeptID": d.data[0].HDeptID,
                            "班组代码": d.data[0].班组代码, "班组": d.data[0].班组名称, "HGroupID": d.data[0].HGroupID, "操作员代码": d.data[0].操作员代码, "操作员": d.data[0].操作员,
                            "HWorkerID": d.data[0].HWorkerID, "生产资源": d.data[0].生产资源, "HSourceID": d.data[0].HSourceID, "HQty": d.data[0].计划数量, "HWorkingQty": d.data[0].在制品数量,
                            "HTimeUnit": d.data[0].时间单位, "HPlanWorkTimes": d.data[0].计划加工时间, "hplanbegindate": (Format(new Date(d.data[0].工序计划开工日期), "yyyyMMdd") == "19000101" ? null : Format(new Date(d.data[0].工序计划开工日期), "yyyy-MM-dd")), "hplanenddate": (Format(new Date(d.data[0].工序计划完工日期), "yyyyMMdd") == "19000101" ? null : Format(new Date(d.data[0].工序计划完工日期), "yyyy-MM-dd")), "HICMOInterID": d.data[0].任务单号id,
                            "HICMOBillNo": d.data[0].子任务单号, "HBeginDayQty": d.data[0].开工固天, "HBeginFixQty": d.data[0].开工固数, "HFixWorkDays": d.data[0].上道固定天数, "HTrunWorkDays": d.data[0].上道循环周期,
                            "HReadyTimes": d.data[0].本道准备时间, "HReadyTime": d.data[0].准备时间, "HQueueTime": d.data[0].排队时间, "HMoveTime": d.data[0].转移时间, "HSeOrderInterID": d.data[0].销售订单主ID,
                            "HSeOrderEntryID": d.data[0].销售订单子ID, "HSeOrderBillNo": d.data[0].销售订单号
                        }];
                        option.data = rowdata;
                        table.render(option);
                    }
                })
            }
 
            //数据验证
            function AllowLoadData(data) {
                var HMaterIDName = data.field.HMaterIDName;//产品
                var HUnitIDName = data.field.HUnitIDName;//单位
                if (HMaterIDName == "") {
                    layer.msg("请选择产品!");
                    return false;
                }
                if (HUnitIDName == "") {
                    layer.msg("请选择单位!");
                    return false;
                }
                return true;
            }
 
            //获取参数
            function getUrlVars() {
                var vars = [], hash;
                var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
                for (var i = 0; i < hashes.length; i++) {
                    hash = hashes[i].split('=');
                    vars.push(hash[0]);
                    vars[hash[0]] = hash[1];
                }
                return vars;
            }
            //#endregion
 
        });
    </script>
</body>
</html>