高章伟
2022-03-18 4bfe21c4b5ddc089ae5a95f4b10f6cff148b690d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
<apex:page Controller="ConsumEquipmentSetShipmentController" showHeader="false" sidebar="false" id="allPage" action="{!init}" >
<head>
    <meta name="format-detection" content="telephone=no"/>
    <meta name="viewport" content="width=device-width,initial-scale=1"/>
</head>
<apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}"/>
<apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/>
<apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"/>
<apex:includeScript value="{!URLFOR($Resource.RelationListPagingCmpJS)}"/>
<apex:includeScript value="/soap/ajax/46.0/connection.js"/>
<apex:includeScript value="/soap/ajax/46.0/apex.js"/>
<apex:stylesheet value="{!URLFOR($Resource.jquery_confirm, 'jquery-confirm.min.css')}"/>
<apex:includeScript value="{!URLFOR($Resource.jquery_confirm, 'jquery-confirm.min.js')}"/>
<style type="text/css">
div#out_Div_L {
  position:relative;
  overflow: hidden;
  float:left;
  width: 30px;
}
.apexp .bPageBlock .pbHeader .btn
{
    padding: 6px;
    font-size: 110%;
    margin-right: 10px;
}
.col_Barcode_F__c
{
    display: none;
}
table.list td input {width: 85%;}
div#in_Div_L {
  position:relative;
  overflow: hidden;
  float:left;
  height: 100px;
  width: 30px;
}
/* add by rentx 2021-10-21 start 设置展示框  */
.col_EquipmentManagementCode__c {display: none;}
.col_Scroll{display: none;}
.dataRow.col_Scroll{display: none;}
.col_ManagementCode__c{display: none;}
 
.modal 
{
    display:none;
    position: fixed; /* Stay in place */
    z-index: 10; /* Sit on top */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
/* Modal Content/Box */
.modal-content 
{
    background-color: #fefefe;
    margin: auto;
    margin-top: 100px;
    padding: 20px;
    border: 1px solid #888;
    width: 50%; /* Could be more or less, depending on screen size */
}
.bPageBlock .pbTitle
{
    width: 0%;
}
/* add by rentx 2021-10-21 start 设置展示框 */
 
.close {
    color: #aaaaaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
}
.close:hover,
.close:focus {
    color: #000;
    text-decoration: none;
          
}
</style>
<script type="text/javascript">
    sforce.connection.sessionId = "{!$Api.Session_ID}";
    var JANCODEMap = {};
</script>
<!-- add by rentx 2021-10-19 start 耗材追溯 -码枪扫描之后弹出框 -->
<div id="myModal1" class="modal">
    <!-- Modal content -->
    <div class="modal-content">
        <!-- <span class="close" onclick="stopScan()">&times;</span> -->
        <input type="hidden" id="havCode"  value="" />
        <button onclick="stopScan(0)" >保存</button>
        <button onclick="stopScan(1)" >取消</button>
        <button onclick="qrsacn(2);return false;" >ipad扫描袋子条形码</button>
        <table style="width:85%" >
            <tr><th>当前设备信息</th></tr>
            <tr>  <td align="right">备品配套明细型号</td>  <td><span id="xinghao"/></td>  </tr>
            <tr>  <td align="right">机身编号</td>         <td><span id="bianhao"/></td>  </tr>
            <tr>  <td align="right">管理编码</td>         <td><span id="bianma" value=""/></td>  </tr>
            <tr>
                <td onclick="document.getElementById('xiaomaCode').focus();return false" align="right">码枪扫描袋子条形码</td>
                <td> <input id="xiaomaCode" onkeypress="return checkXiaoMa(event)" autofocus="autofocus" /> </td>
            </tr>
        </table>
        <br/>
        <table id="detailTb" style="width:85%" >
            <tr><th>管理编码</th><th>备品管理码</th><th>操作</th></tr>
            <!-- <tr><td>XXX</td><td>001</td><td> <button value="删除" /></td></tr> -->
        </table>
 
    </div>
</div>
<!-- add by rentx 2021-10-19 end 耗材追溯 -码枪扫描之后弹出框 -->
<!-- add by qiuyj 2021-11-30 start  pc端扫码支持-->
<div id="myModal2" class="modal">
  <!-- Modal content -->
  <div class="modal-content" style="width:200px">
    <span class="close" onclick="stopScan()">&times;</span>
    <p>扫描中</p>
        <p>Code:<input type="text" id="qrcode"/></p>
    <video playsinline="true" id="preview" style="width: 100%;z-index: 11;transform: scaleX(-1);margin-top: 10px;"></video>
    扫码履历:
    <ul id="scanedqr" style="list-style-type: none; text-align: center;padding: 0;width: 100%; height: 100px; overflow: auto">
    </ul>
  </div>
</div>
<!-- add by qiuyj 2021-11-30 end pc端扫码支持-->
<apex:form id="allForm">
    <!-- update         wangweipeng            2022/01/28                 start -->
    <!-- <apex:inputHidden value="{!done_flg}" id="done_flg"/> -->
    <!-- update         wangweipeng            2022/01/28                 start -->
    <apex:outputPanel id="pageallPanel">
        <apex:pageBlock id="searchBlock" tabStyle="Report">
            <apex:pageBlockButtons location="top">
                <apex:commandButton action="{!save}" onclick="blockme();" value="保存" rerender="allForm" oncomplete="unblockUI();checkMessage();checEventFrame()" />
                <apex:commandButton action="{!cancel}" value="取消" rerender="allForm" oncomplete="checEventFrame()"/>
                <apex:commandButton onclick="qrsacn(0);return false;" value="扫一扫耗材" rerender="allForm"/>
                <apex:commandButton onclick="qrsacn(1);return false;" value="扫一扫物流单" rerender="allForm"/>
                <apex:commandButton onclick="blockme();" action="{!send}" value="发货" rerender="message" oncomplete="unblockUI();checkMessage();checEventFrame()"/>
                <!-- add     wangweipeng          2021/01/10      /apex/ConsumTrialPDF?id={!parentId}     ConsumEquipmentSetShipmentPDF   start -->
                <apex:commandButton onclick="window.open('ConsumTrialPDF?id={!parentId}');" value="试用表" rerender="allForm"/>
                <!--<a href="openSafri/apex/ConsumTrialPDF?id={!parentId}">试用表</a> -->
                <!-- add     wangweipeng          2021/01/10             end -->
                <!-- add by rentx 2021-10-21 start 新增码枪扫描 -->
                <apex:commandButton onclick="document.getElementById('maqCode').focus();return false" id="maqCodeBtn"  value="码枪扫描:" style="padding: 6px;font-size: 110%;margin-right: 1px;"/>
                <input  autofocus="autofocus" id="maqCode" name="maqCode" style="padding:6px" onkeypress="return onKeyPress(event)" /> 
                 <!-- autofocus="autofocus" -->
                <!-- add by rentx 2021-10-21 end 新增码枪扫描 -->
 
            </apex:pageBlockButtons>
          
             <table>
                <tr>
                    
                    <td width="20px"/>
                    <td width="35%">
                      <apex:outputLabel for="applyNo" value="申请单号:" />
                      <apex:outputText id="applyNo" value="{!c_apply_no}"/>
                    </td>
                    <td width="10px"></td>
                    <td width="30%">
                      <apex:outputLabel for="keyword" value="型号:" />
                      <apex:inputText id="keyword" value="{!keyword}"/>
                    </td>
                    <td width="10px"></td>
                    <td width="35%">
                      <apex:outputLabel for="keywordDate" value="有效期至:" />
                      <apex:inputText id="keywordDate" value="{!keywordDate}" size="12" onfocus="DatePicker.pickDate(true, '{!$Component.keywordDate}', false)" />
                      <apex:commandButton style="margin-left: 20px; padding: 6px;font-size: 110%;" value="检索" action="{!searchOpp}" onclick="blockme();" rerender="allForm" oncomplete="unblockUI();checEventFrame()"/>
                      <div style="display:none;">
                        <apex:inputField value="{!slip.Shippment_loaner_time__c}" /> 
                      </div>
                    </td>
                </tr>
                <tr>
                    <td width="20px"/>
                    <td >
                      <apex:outputLabel for="slipNo" value="发货-运输单号:" />
                      <apex:inputField id="slipNo" value="{!slip.Name}"/>
                     <!-- <apex:commandButton action="{!searchSlip}" value="检索" style="padding: 6px;font-size: 110%;" rerender="allForm" oncomplete="checEventFrame()"/> -->
                     <apex:commandButton action="{!searchSlip}" value="检索" style="padding: 6px;font-size: 110%;" rerender="searchBlock" oncomplete="checEventFrame()"/>
                    </td>
                    <td width="10px"></td>
                    <td >
                      <apex:outputLabel for="deliveryType" value="发货-运输单种类:" />
                      <span><apex:inputField required="false" id="deliveryType" value="{!slip.DeliveryType__c}"/></span>
                    </td>
                    <td width="10px"></td>
                    <td>
                      <apex:outputLabel for="distributorMethod" value="发货-运输方式:" />
                      <apex:inputField required="false" id="distributorMethod" value="{!slip.Distributor_method__c}"/>
                    </td>
                </tr>
                <tr>
                    <td width="20px"/>
                    <td >
                      <apex:outputLabel for="deliveryCompany" value="发货-物流公司:" />
                      <apex:inputField required="false" id="deliveryCompany" value="{!slip.DeliveryCompany__c}"/>
                    </td>
                    <td width="10px"></td>
                    <td >
                      <apex:outputLabel for="whStaff" value="发货-担当者:" style="float:left;"/>
                      <apex:inputField required="false" id="whStaff" value="{!slip.Wh_Staff__c}" style="float:left;"/>
                    </td>
                    <td width="10px"></td>
                    <td>
                      <apex:outputLabel for="combinePack" value="发货-合包信息:" />
                      <apex:inputField required="false" id="combinePack" value="{!slip.Combine_Pack__c}"/>
                    </td>
                </tr>
            </table>
            
            <div style="clear:both;"></div>
 
            <apex:outputPanel id="message">
                <!-- add         wangweipeng            2022/01/28                 start -->
                <apex:inputHidden value="{!done_flg}" id="done_flg"/>
                <!-- add         wangweipeng            2022/01/28                 end -->
                <apex:pageMessages />
            </apex:outputPanel>
        </apex:pageBlock>
        <c:RelationListPagingCmp id="cmpid" pgController="{!this}" hasCheckbox="true" />
        <apex:outputPanel id="checEventFrame">
            <script>
                function checEventFrame() {
                    //var aaa=j$(escapeVfId('allPage:allForm:cmpid:cmpinnerid:dataBlock:oppTable:2:j_id162:9:j_id169')).val();
                    //    alert('checEventFrame==='+aaa);
                    j$('select[name$="deliveryType"]').val('发货');
                    j$('select[name$="deliveryType"]').prop('disabled', true);
 
                    // j$('select[name$="distributorMethod"]').children('option[value="空运"]').remove();
                    j$('select[name$="deliveryCompany"]').children('option[value="莱比特"],option[value="嘉里大通"]').remove();
                }
                checEventFrame();
 
                var tbwidth = j$('#tableHeader').css('width');
                tbwidth = parseInt(tbwidth.slice(0, -2)) - 76;
                j$('#tableHeader').css('width', tbwidth+'px');
                j$('#tableData').css('width', tbwidth+'px');
 
                j$("#tableData input[type=text]").on('change', function() {
                    let rownum = j$(this)[0].id.match(/oppTable\:(\d*)/)[1];
                    alert('====rownum=='+rownum);
                    j$('input[name$="oppTable_L:'+rownum+':rowCheck"]').prop('checked', true).trigger("change");
                })
 
                if (j$('.messageText').text().indexOf('取得了') != -1) {
                    if ('{!changeMessage}' == '取消') {
                        j$('.messageText').text('取消成功')
                    } else {
                        j$('.messageText').text('取得了 {!changeMessage} 条数据')
                    }
                }
                //20220215 字段集中的输入框变成只读,不能直接变成span,否则后台取不到值
               //j$("#tableData input[type=text]").attr("readonly",true);  先隐藏掉
               //j$("#tableData input[type=text]").attr("disabled","disabled");
            </script>
        </apex:outputPanel>
    </apex:outputPanel>
</apex:form>
<script type="text/javascript">
      
        
 
        
 
    // add by rentx 2021-10-19 start 耗材追溯 -码枪扫码之后展示弹出框
    //之前是   扫到耗材之后 自动勾选置顶并定位到对应的发货件数输入框
    //现在需要 扫到耗材之后 自动勾选置顶并定位到对应的发货件数输入框 并弹出界面 光标自动定位到"码枪扫描袋子条形码"
    var numObj;     //发货件数的 obj
    var rowObj;     //明细行的obj
    var checkObj;     //复选框的obj
    var flag = '';  //该变量会有"cancelConsumables"(取消耗材) 和 "saveConsumables"(保存耗材)
    //扫码弹出框之后 扫小码的操作 -- 
    //1.添加一行
    function addRow(nowcode,bianma) {
        //获取table 并且添加 值需要带过来或者查一下
        //管理编码暂定
        j$("#detailTb").append("<tr><td>"+bianma+"</td><td>"+nowcode+"</td><td> <button onclick=\"delRow(j$(this))\">删除 </button> </td></tr>");
        //清空输入框
        j$( '#xiaomaCode' ).val("");
 
    }
    //2.删除当前行
    function delRow(tr) {
        //获取待删除的行 删掉
        j$(tr).parent().parent().remove();
    }
    //3.扫码枪 扫完小码之后
    function checkXiaoMa(e) {
        var keyCode = null;
        if(e.which)
            keyCode = e.which;
        else if(e.keyCode)
            keyCode = e.keyCode;
        //检测到回车事件(弹出框里的回车事件) ↓↓↓↓ 执行以下代码
        if(keyCode == 13) {
            //拿到当前输入code
            var nowCode = j$( '#xiaomaCode' ).val();
            //判断这个小码是否为 delConsumables(删除耗材) 如果是 存该信息到flag中
            if (nowCode == 'delConsumables') {
                this.flag = 'delConsumables';
                j$( '#xiaomaCode' ).val("");
                return false;
            }
            //判断这个小码是否为 saveConsumables(保存耗材) 如果是 保存
            if (nowCode == 'saveConsumables') {
                //相当于点击保存按钮
                stopScan(0);
                j$( '#xiaomaCode' ).val("");
                return false;
            }
            //判断这个小码是否为 cancelConsumables(取消耗材) 如果是 取消
            if (nowCode == 'cancelConsumables') {
                //相当于点击取消按钮
                stopScan(1);
                j$( '#xiaomaCode' ).val("");
                return false;
            }
            //判断这个小码code 是否符合要求 1:长度是否正确 2:是否重复输入 3:输入的是否为3位数字
           // var regNeg = /^[1-9]+[0-9]*]*$/; // 负整数
            //z<0||!(/^\d+$/.test(z))
            // && nowCode>=0 && (/^\d+$/.test(nowCode))
            if(nowCode != null && nowCode.length == 3 && !isNaN(nowCode)){
                //获取扫描过的小码
                var tableId = document.getElementById("detailTb"); 
                if(tableId.rows.length > 0){
                    var str = '';
                    for(var i=1;i<tableId.rows.length;i++) { 
                        if(nowCode == tableId.rows[i].cells[1].innerHTML){
                            if (this.flag == 'delConsumables') {
                                //删除这一行
                                tableId.rows[i].remove();
                                this.flag = '';
                            }else{
                                alert('小码已存在');
                            }
                            //清空输入框
                            j$( '#xiaomaCode' ).val("");
                            return false;
                        }
                    }  
                }
                //能走到这说明待删除的小码不存在于明细列表 所以要给出提示
                if (this.flag == 'delConsumables') {
                    alert('删除的小码已删除或未扫描过');
                    j$( '#xiaomaCode' ).val("");
                    this.flag = '';
                    return false;
                }
                var bianma = document.getElementById("bianma").innerHTML;
                addRow(nowCode,bianma);
            }else{
                //清空输入框
                j$( '#xiaomaCode' ).val("");
                alert('当前小码不正确')
            }
            return false;
        }
        return true;
    }
    //4.扫码后对码的校验
    function onKeyPress(e) {
        var keyCode = null;
    
        if(e.which)
            keyCode = e.which;
        else if(e.keyCode)
            keyCode = e.keyCode;
        if(keyCode == 13) {
            //拿到当前输入code
            var nowCode = j$( '#maqCode' ).val();
            filljsQR(nowCode);
            nowCode = '';
            return false;
        }
        return true;
    }
    //5.为弹出框里的信息赋值 并且展示弹出框  
    function showTb(leftobj,paobj,rightObj,scanType,content250) {
        checkObj = leftobj;
        numObj = rightObj;
        rowObj = paobj;
        var a = paobj[0].children[0].innerText; //备品配套明细型号 
        var b = paobj[0].children[3].innerText; //机身编号
        //var c = paobj[0].children[10].innerText; //取得管理编码,判断管理编码是否为空  span框这样取
        var c = paobj[0].children[10].children[0].value; //大码  输入框这样取
        var maqCode = j$( '#maqCode' ).val();
        // alert('maqiang'+maqCode);
        // alert('scanType=='+scanType+'==管理编码'+c+'=='+content250);
        // //如果管理编码为空并且码枪扫描的输入值不是盒,提示;
        // //(c == '' || c == undefined) &&  yc 
        // if (maqCode !='' && maqCode !=undefined && maqCode.substring(maqCode.length - 8,maqCode.length - 5) != '250') {
        //     alert('请先扫盒!');
        //     j$("#maqCode").val("");
        //     j$("#maqCode").focus();
        //     return;
        // }
        // //scanType=0 说明是ipad扫描的
        // if( scanType != undefined && scanType == 0){
        //     alert('000');
        //     if( content250 !='' && content250 !=undefined && content250.substring(content250.length - 8,content250.length - 5) != '250'){
        //       alert('请先扫盒!');
        //       j$("#maqCode").focus();
        //       return;
        //     }
        // }
         
        //update     wangweipeng             2022/02/21             start
        // if (c == '') {
        //判断当前输入是盒
        var bianma;
        if (maqCode !='' && maqCode !=undefined && maqCode.substring(maqCode.length - 8,maqCode.length - 5) == '250') {
            //设置管理编码
            bianma = maqCode.substring(maqCode.length -5,maqCode.length);
            //弹出框的管理编码赋值
            document.getElementById("bianma").innerHTML = bianma;    
            //给明细行赋管理编码
            //paobj[0].children[10].children[0].value = bianma; 
            c = bianma;
        }else if(content250 !='' && content250 !=undefined && content250.substring(content250.length - 8,content250.length - 5) == '250'){
             //设置管理编码
            bianma = content250.substring(content250.length -5,content250.length);
            //弹出框的管理编码赋值
            document.getElementById("bianma").innerHTML = bianma;    
            //给明细行赋管理编码
            //paobj[0].children[10].children[0].value = bianma; 
            c = bianma;
 
        }
        //判断当前扫描是否换盒了
        if(c != null && c != '' && c != undefined){
            //获取当前设备的管理编码,注意可能是一个、多个或空
            var oldbianma = paobj[0].children[10].children[0].value;
            if(oldbianma != null && oldbianma != '' && oldbianma != undefined){
                var oldbianmaArray = oldbianma.split(',');
                var bianmaFlag = true;
                for(var i = 0; i < oldbianmaArray.length; i++){
                    if(oldbianmaArray[i] != '' && oldbianmaArray[i].indexOf(c) == 0){
                        bianmaFlag = false;
                    }
                }
                if(bianmaFlag){
                    if(confirm('已换盒,确认继续吗?')){
 
                    }else{
                        leftobj.prop('checked', false);
                        j$("#maqCode").val("");
                        stopScan();
                        return;
                    }
                }
            }
        }
 
        /*moveToTop(leftobj);
        leftobj.prop('checked', true).trigger("change");
        moveToTop(rightObj);*/
 
        //update     wangweipeng             2022/02/21             end
        
        //删除缓存
        var tableId = document.getElementById("detailTb"); 
        if(tableId.rows.length > 0){
            var rownum = tableId.rows.length ;
            for (i=1;i<rownum;i++) {
                tableId.deleteRow(i);
                rownum=rownum-1;
                i=i-1;
            } 
        }
        //删除缓存 end
        document.getElementById("xinghao").innerHTML = a;   //备品配套明细型号
        document.getElementById("bianhao").innerHTML = b;   //机身编号
 
        //alert('===c=='+paobj[0].children[10].children[0].innerText);
 
        // document.getElementById("bianma").innerHTML = ;    //管理编码
        //判断小码 并取得数据库中已存在的小码 注:已存在的用","拼接 
        // var code = paobj[0].children[9].children[0].innerText;
 
        var code = paobj[0].children[9].children[0].value;  //.innerText; 
        var hecode = paobj[0].children[10].children[0].value;  //.innerText; 
        //alert('xiaoma'+code);
        if (code != null && code.length > 0) {
            //向弹出框里添加明细行
            var arr = code.split(',');
            var hearr = hecode.split(',');
            //update by    wangweipeng    2022/02/21     start
            //按照复选框的顺序来展示
            for (var i = 0; i < arr.length ; i++) {
                if(c == hearr[i]){
                    addRow(arr[i],c);
                }
            }
            /*for (var i = arr.length - 1; i >= 0; i--) {
                if(c == hearr[i]){
                    addRow(arr[i],c);
                }
            }*/
            //update by    wangweipeng    2022/02/21     end
        }
        //j$(".modal").show();
        j$("#myModal1").show();
        //使用定时器设置光标定位因为如果是弹出选择本部的框之后再设置 会定位不到
        setTimeout(function(){j$("#xiaomaCode").focus();},1000);
        // j$("#xiaomaCode").focus();
        return;
        // j$("#maqCodeBtn").click();
    }
    //6.关闭弹框
    function stopScan(numflag) {
        //numflag= 1 关闭输入框,清空码枪输入的值,光标自动定位到码枪输入
        //j$(".modal").hide();
        j$("#myModal1").hide();
        scanType = null;
        j$("#maqCode").focus();
        if(numflag == 0 ){
            //用户点击保存 1.设置数量到发货件数上   2.设置小码到明细的备品管理码上
            if(numObj != null){
                //update        wangweipeng            2022/02/21                   start
                /*//update            wangweipeng                2022/01/12               start
                //把发货件数字段设置为只读
                //numObj.val(j$("#detailTb").find("tr").length-1)
                for(var i = 0;i < numObj.length;i++){
                    numObj[i].innerText = j$("#detailTb").find("tr").length-1;
                }
                //update            wangweipeng                2022/01/12               end
                
                if (rowObj != null) {
                    //取得所有小码 放到备品管理码上
                    var tableId = document.getElementById("detailTb"); 
                    if(tableId.rows.length > 0){
                        var str = '';
                        for(var i=1;i<tableId.rows.length;i++) { 
                            str += tableId.rows[i].cells[1].innerHTML + ',';
                        }  
                        var resultVar = str.substring(0,str.length-1);
                        // rowObj[0].children[9].children[0].innerText = resultVar; 
                        rowObj[0].children[9].children[0].value = resultVar; 
                        //给明细行赋管理编码
                        //rowObj[0].children[10].children[0].value = tableId.rows[1].cells[0].innerHTML;
                    }
                }*/
                
                if(rowObj != null){
                    //获取当前扫的盒
                    var newHe = document.getElementById("bianma").innerHTML;
                    //取得所有小码 放到备品管理码上
                    //注意:有两种情况,如果此次扫的小米的盒是已经扫过的,那么直接加就行,如果此次的盒没有扫过,而原来也有已经扫过的盒,那么就需要特殊处理
                    var tableId = document.getElementById("detailTb"); 
                    var str = '';
                    var str1 = '';
                    var numstr = 0;
                    var he = rowObj[0].children[10].children[0].value;
                    var xiaoma = rowObj[0].children[9].children[0].value;
                    if(tableId.rows.length > 0){//判断此次扫的盒是否有小码
                        //首先判断当前明细原来是否已经扫过码
                        //如果没扫过 那么在原来的 备品管理码、管理编码和发货件数的值上都需要加上此次扫的小码
                        //如果扫过,那么需要把原来此盒的小码都改成此次扫的小码
                        if(he != null && he != '' && he != undefined && xiaoma != null && xiaoma != '' && xiaoma != undefined){
                            var linshistr = '';//临时小码值
                            var linshistr1 = '';//临时盒的值
                            var oldheArray = he.split(',');//获取原来的所有盒
                            var oldxiaomaArray = xiaoma.split(',');//获取原来的所有小码
                            //循环原来明细的盒
                            for(var i = 0;i < oldheArray.length;i++){
                                if(oldheArray[i] != null && oldheArray[i] != '' && oldheArray[i] != undefined){
                                    var oldHe = '';//临时状态变量,1:值不变,2:删除当前小码和盒,3:当前盒等于原来盒,但是当前小码没有变化,值还是不变
                                    //判断原来的盒和现在操作的盒是否相等
                                    if(oldheArray[i] == newHe){
                                        //如果原来的盒等于当前操作的盒,那么接着判断小码情况
                                        //循环弹出框的小码
                                        for(var j=1;j<tableId.rows.length;j++) {
                                            //原来的小码等于当前扫的小码,那么值不需要改变
                                            if(oldxiaomaArray[i] == tableId.rows[j].cells[1].innerHTML){
                                                oldHe = '3';
                                            }
                                        }
                                    }else{
                                        //如果原来的盒不等于当前操作的盒,那么不需要做变化,值把现在循环的盒放到临时变量里面
                                        linshistr += oldxiaomaArray[i] + ',';
                                        linshistr1 += oldheArray[i] + ',';
                                    }
                                    if(oldHe == '3'){
                                        linshistr += oldxiaomaArray[i] + ',';
                                        linshistr1 += oldheArray[i] + ',';
                                    }
                                }
                            }
                            str = linshistr;
                            str1 = linshistr1;
                            //由于以上的操作只能找到原来的盒和小码是否删除,那么一下的操作就是把最新操作的盒和小码追加到字符串的最后面
                            //循环弹出框的小码
                            for(var j=1;j<tableId.rows.length;j++) {
                                var vFlag = true;//临时变量,用于判断是否需要追加
                                for(var o = 0;o < linshistr.split(',').length ; o++){
                                    if(linshistr.split(',')[o] != '' && linshistr.split(',')[o] != null){
                                        //判断是否有相等的盒
                                        if(linshistr1.split(',')[o] == newHe){
                                            //判断小码是否一样,如果一样,那么不需要追加
                                            if(linshistr.split(',')[o] == tableId.rows[j].cells[1].innerHTML){
                                               vFlag = false; 
                                            }
                                        }
                                    }
                                }
                                if(vFlag){
                                    //追加新的盒和小码
                                    str += tableId.rows[j].cells[1].innerHTML + ',';
                                    str1 += newHe + ',';
                                }
                            }
                            if(str != '' && str1 != null){
                                str = str.substring(0,str.length-1);
                                str1 = str1.substring(0,str1.length-1);
                            }
 
                            numstr = str == '' ? null : str.split(',').length;
 
                        }else{//如果明细原来没有扫过码,那么直接追加就行
                            for(var i=1;i<tableId.rows.length;i++) { 
                                str += tableId.rows[i].cells[1].innerHTML + ',';
                                str1 += document.getElementById("bianma").innerHTML + ',';//盒
                            }  
                            if(str != '' && str1 != null){
                                str = str.substring(0,str.length-1);
                                str1 = str1.substring(0,str1.length-1);
                            }
                            numstr = j$("#detailTb").find("tr").length-1;//发货件数
 
                        }
                    }else{
                        //如果没有小码,那么判断原来的是否有小码和盒,如果原来也没有,那么什么也不用做
                        //如果原来有,那么找到等于当前盒的所有小码,都删除掉
                        if(he != null && he != '' && he != undefined && xiaoma != null && xiaoma != '' && xiaoma != undefined){
                            var oldheArray = he.split(',');
                            var oldxiaomaArray = xiaoma.split(',');
                            for(var i = 0;i < oldheArray.length;i++){
                                if(oldheArray[i] != newHe){
                                    str += oldxiaomaArray[i] + ',';
                                    str1 += oldheArray[i] + ',';
                                }
                            }
 
                            if(str != '' && str1 != null){
                                str = str.substring(0,str.length-1);
                                str1 = str1.substring(0,str1.length-1);
                            }
 
                            numstr = str == '' ? null : str.split(',').length;//发货件数
                        }
                    }
                    if(str == '' && he == '' && xiaoma == ''){
                        checkObj.prop('checked', false);
                    }else{
                        moveToTop(checkObj);
                        checkObj.prop('checked', true).trigger("change");
                        moveToTop(numObj);
                    }
 
                    rowObj[0].children[9].children[0].value = str; //备品管理码
                    rowObj[0].children[10].children[0].value = str1;//管理编码
                    numObj[0].innerText = numstr;//发货件数
                }
                //update        wangweipeng            2022/02/21                   end
            }
        }else if(numflag == 1){
            //如果为true,那么证明选择的是取消按钮,那么需要把第一行的复选框去掉
            checkObj.prop('checked', false);
        }
        var maqCode = j$( '#maqCode' ).val();
        //alert('==='+j$( '#maqCode' ).val());
        //if (maqCode !='' && maqCode !=undefined){
            j$("#maqCode").val("");
            j$("#maqCode").focus();
            setTimeout(function(){j$("#maqCode").focus();},300);
        //}
    }
    // <!-- add by qiuyj 2021-11-30 start  pc端扫码支持-->
    j$(document).ready(function(){
        j$( '#qrcode' ).unbind();
        j$( '#qrcode' ).keypress( function ( e ) {
            if ( e.which == 13 ) {
                filljsQR(j$( '#qrcode' ).val());
                j$("#scanedqr").append("<li>"+j$( '#qrcode' ).val()+"</li>");
                j$("#scanedqr").animate({ scrollTop: j$("#scanedqr").prop("scrollHeight")}, 1000);
                j$('#myModal2').hide();
                return false;
            }
        });
        setTimeout(function(){j$("#maqCode").focus();},300);
 
    });
    // add by qiuyj 2021-11-30 end  pc端扫码支持
    // add by rentx 2021-10-19 end 耗材追溯 -码枪扫码之后展示弹出框 
 
    // j$(document).ready(function(){
    //     j$('select[name$="deliveryType"]').val('发货');
    //     j$('select[name$="deliveryType"]').prop('disabled', true)
    //     // j$( '#qrcode' ).unbind();
    //     // j$( '#qrcode' ).keypress( function ( e ) {
    //     //     if ( e.which == 13 ) {
    //     //         filljsQR(j$( '#qrcode' ).val());
    //     //         return false;
    //     //     }
    //     // });
    // });
    // add by youc 2021-12-01 start 
    //ipad扫完小码之后
    function checkipadXiaoMa(ipadnowCode) {
        //判断这个小码是否为 delConsumables(删除耗材) 如果是 存该信息到flag中
        if (ipadnowCode == 'delConsumables') {
            this.flag = 'delConsumables';
            return false;
        }
        //判断这个小码是否为 saveConsumables(保存耗材) 如果是 保存
        if (ipadnowCode == 'saveConsumables') {
            //相当于点击保存按钮
            stopScan(0);
            return false;
        }
        //判断这个小码是否为 cancelConsumables(取消耗材) 如果是 取消
        if (ipadnowCode == 'cancelConsumables') {
            //相当于点击取消按钮
            stopScan(1);
            return false;
        }
        //判断这个小码code 是否符合要求 1:长度是否正确 2:是否重复输入 3:输入的是否为3位数字
        if(ipadnowCode != null && ipadnowCode.length == 3 && !isNaN(ipadnowCode)){
            //获取扫描过的小码
            var tableId = document.getElementById("detailTb"); 
            if(tableId.rows.length > 0){
                var str = '';
                for(var i=1;i<tableId.rows.length;i++) { 
                    if(ipadnowCode == tableId.rows[i].cells[1].innerHTML){
                        if (this.flag == 'delConsumables') {
                            //删除这一行
                            tableId.rows[i].remove();
                            this.flag = '';
                        }else{
                            alert('小码已存在');
                        }
                        return false;
                    }
                }  
            }
            //能走到这说明待删除的小码不存在于明细列表 所以要给出提示
            if (this.flag == 'delConsumables') {
                alert('删除的小码已删除或未扫描过');
                this.flag = '';
                return false;
            }
            var bianma = document.getElementById("bianma").innerHTML;
            addRow(ipadnowCode,bianma);
        }else{
            //清空输入框
            alert('当前小码不正确')
            return false;
        }
        
    return true;
    }
    function checkMessage() {
        //var aaa=j$(escapeVfId('allPage:allForm:cmpid:cmpinnerid:dataBlock:oppTable:2:j_id162:9:j_id169')).val();
        //alert('checkMessage==='+aaa);
        //update     wangweipeng             2022/01/28           start
        //if (j$(escapeVfId('allPage:allForm:done_flg')).val() == 'true') {
        if (j$(escapeVfId('allPage:allForm:searchBlock:done_flg')).val() == 'true') {
        //update     wangweipeng             2022/01/28           end
            alert("保存成功");
        }
    }
 
    var standalone = window.navigator.standalone,
            userAgent = window.navigator.userAgent.toLowerCase(),
            safari = /safari/.test( userAgent ),
            ios = /iphone|ipod|ipad/.test( userAgent );
    var scanType;
    function filljsQR(content) {
        try{
        if (scanType == 1) {
            j$("input[name$='slipNo']").val(content);
            scanType = null;
        }else if(scanType == 2){//add by youc 2021-12-01 弹出框中ipad扫描小码
            checkipadXiaoMa(content);
            scanType = null;
        } else {
            
                 var tracingCode = content.substr(-8);//截取后8位
                //add by youc 2021-11-29 start
                var content250 = content;//为了获取ipad端扫码的值
                if (tracingCode.indexOf('250') == 0) {//后8位看是否包含250 
                    content = content.slice(0, -8);
                }
 
                let rownum = [];
                var $Col_Scroll = j$(".dataRow.col_Scroll");
                j$(".col_Barcode_F__c span").each(function(index) {
                    if (j$(this).text() && (content.indexOf(j$(this).text()) == 0)) {
                        rownum.push(this.id.match(/oppTable\:(\d*)/)[1]);
                         console.log('1---'+rownum);
                        return;
                    }
                    var JANCODE = content.substr(3, 12);
                    var GTINCODE = content.substr(3, 12);
                    // var yyyyMMdd = "20" + content.substr(18, 6);
                    // 到2100年 就需要下面的logic了
                    // var now = new Date();
                    // var current_yyyyMMdd = now.getFullYear()
                    //         + ("0" + (now.getMonth() + 1)).slice(-2)
                    //         + ("0" + now.getDate()).slice(-2);
                    // var currentYear = new Date().getFullYear();
                    // var yyyyMMdd = Math.floor(currentYear / 100) + content.substr(18, 6);
                    // if (yyyyMMdd < currentYear) yyyyMMdd = yyyyMMdd + 1000000;   // 使用期限 应该是未来的日期
                    var result = extractDateSerial(content);
                    var yyyyMMdd = result['yyyyMMdd'];
                    var serial = result['serial'];
 
                    if (JANCODEMap[JANCODE]) {
                    } else {
                        var query = "Select ProductCode From Product2 WHERE JANCODE__c LIKE '" + JANCODE + "%' OR Device_GTIN_2_13_F__c = '" + GTINCODE + "' LIMIT 1";
                        var records = sforce.connection.query(query).getArray('records');
                        if (records.length > 0) {
                            JANCODEMap[JANCODE] = records[0].ProductCode;
                        }
                    }
                    if (JANCODEMap[JANCODE]) {
                        var content2 = JANCODEMap[JANCODE] + ":" + serial + "(" + yyyyMMdd + ")";
                        var $prdSerialNo = $Col_Scroll.find("input[name=Product_Serial_No_F__c]");
                        if ($prdSerialNo[index].value.startsWith(content2)) {
                            if(this.id != undefined){
                                rownum.push(this.id.match(/oppTable\:(\d*)/)[1]);
                                 console.log('2---'+rownum);
                                return;
                            }
                        }
                    }
                })
                //add by youc 2021-11-30 start
                //如果管理编码为空并且码枪扫描的输入值不是盒,提示;
                var maqiang = j$( '#maqCode' ).val();
                if (content250 !='' && content250 !=undefined && content250.substring(content250.length - 8,content250.length - 5) != '250') {
                    alert('请先扫盒!');
                     if(maqiang !='' && maqiang !=undefined){
                         j$("#maqCode").val("");
                         j$("#maqCode").focus();
                     }
                    return;
                //add by youc 2021-11-30 end
                }else if (rownum.length == 0) {
                    alert('扫描的耗材不存在!')
                    //add by rentx 2021-10-22 start 删除输入框内容 并光标自动定位到输入框
                      if(maqiang !='' && maqiang !=undefined){
                         j$("#maqCode").val("");
                         j$("#maqCode").focus();
                     }
                   return;
                    //add by rentx 2021-10-22 end 删除输入框内容 并光标自动定位到输入框
 
                } else if (rownum.length > 1) {
                    let optStr = "";
                    rownum.forEach(function (rn) {
                        j$(".col_Salesdepartment__c").each(function () {
                            if (j$(this).children()[0] && j$(this).children()[0].id.indexOf('oppTable:'+rn+':') !== -1) {
                                optStr += '<option value="'+rn+'">'+j$(this).text()+'</option>';
                                return;
                            }
                        })
                    })
                    j$.confirm({
                        title: '扫描的耗材有复数存在',
                        boxWidth: '50%',
                        useBootstrap: false,
                        content: '' +
                          '<form action="" class="formName">' +
                          '<div style="overflow: hidden;">' +
                          '<label for="salesDept">请选择所在地区(本部):</label>' +
                          '<select id="salesDept" name="salesDept">'+optStr+'</select>' +
                          '</div>' +
                          '</form>',
                        buttons: {
                            formSubmit: {
                                text: '确认',
                                btnClass: 'btn-blue',
                                action: function () {
                                    var rn = this.$content.find('#salesDept').val();
                                    var leftobj = j$("input[name$='oppTable_L:"+rn+":rowCheck']:not(:disabled)")
                                   // moveToTop(leftobj);
                                   // leftobj.prop('checked', true).trigger("change");
                    
                                    j$(".col_Inspection_Cnt_Jia__c").each(function () {
                                        if (j$(this).children()[0] && j$(this).children()[0].id.indexOf('oppTable:'+rn+':') !== -1) {
                                            // j$(this).find("input").attr('autofocus', 'autofocus');
                                            //update            wangweipeng                2022/01/12               start
                                            //由于把发货件数从输入流改成只读,所以这里需要改变
                                            //var rightObj = j$(this).find("input:not(:disabled)");
                                            var rightObj = j$(this).find("span");
                                            //update            wangweipeng                2022/01/12               end
                                           // moveToTop(rightObj);
                                           // rightObj.focus();
                                            //add by rentx 2021-10-26 start 
                                            //paobj所在明细行, rightObj 发货件数输入框
                                            var paobj = j$(this).parent();
                                            showTb(leftobj,paobj,rightObj,scanType,content250);
                                            //add by rentx 2021-10-26 end 
                                            return;
                                        }
                                    })
                                }
                            },
                            cancel: {
                                text: '取消',
                                //add by rentx 2021-10-27 start 耗材追溯 --发货
                                action: function () {
                                     if(maqiang !='' && maqiang !=undefined){
                                         j$("#maqCode").val("");
                                         j$("#maqCode").focus();
                                     }
                                }
                                //add by rentx 2021-10-27 end 耗材追溯 --发货
                            }
                        }
                    });
                } else {
                    var leftobj = j$("input[name$='oppTable_L:"+rownum[0]+":rowCheck']:not(:disabled)")
                    //置顶,复选框勾选 发货件数输入框定位 20211126 yc  移到判断之后再确认
                    //moveToTop(leftobj);
                    //leftobj.prop('checked', true).trigger("change");
                    j$(".col_Inspection_Cnt_Jia__c").each(function () {
                        if (j$(this).children()[0] && j$(this).children()[0].id.indexOf('oppTable:'+rownum[0]+':') !== -1) {
                            // j$(this).find("input").attr('autofocus', 'autofocus');
                            //update            wangweipeng                2022/01/12               start
                            //由于把发货件数字段设置为只读,所以这里需要改变
                            //var rightObj = j$(this).find("input:not(:disabled)");
                            var rightObj = j$(this).find("span");
                            //update            wangweipeng                2022/01/12               end
                            
                            //moveToTop(rightObj);
                            //rightObj.focus();  发货件数输入框定位
                            //展示弹出框 add by rentx 2021-10-21 start
                            var paobj = j$(this).parent()
                            //paobj所在明细行, rightObj 发货件数输入框
                            showTb(leftobj,paobj,rightObj,scanType,content250);
                            //展示弹出框 add by rentx 2021-10-21 end
                            return;
                        }
                    })
                }
            }  
        } catch (e) {
                alert("发生异常:" + e);
                console.log("发生异常:" + e);
            }
    } 
 
    function extractDateSerial(content){
        var yyyyMMdd = '';
        var noJancodeContent = content.slice(16);
        var n1 = noJancodeContent.search(/17\d{6}/);
        var n2 = noJancodeContent.slice(8).search(/17\d{6}/);
        var m1 = noJancodeContent.search(/11\d{6}/);
        var m2 = noJancodeContent.slice(8).search(/11\d{6}/);
 
        var k = 0;
        if(n1 % 8 == 0){
            yyyyMMdd = '20'+noJancodeContent.substr(n1+2,6);
            k += 1;
        }
        else if(n2 == 0) {
            yyyyMMdd = '20'+noJancodeContent.substr(8+2,6);
            k += 1;
        }
        if(m1 % 8 == 0 || m2 == 0){
            k += 1;
        }
        var serial = noJancodeContent.slice(k*8+2);
        var y = yyyyMMdd.substring(0, 4);
        var m = yyyyMMdd.substring(4, 6);
        var d = yyyyMMdd.substring(6);
        // 00表示月末
        if(d == '00'){
            d = '' + (new Date(y, m, d)).getDate();
        }
        yyyyMMdd = y + m + d;
        return {'yyyyMMdd':yyyyMMdd, 'serial':serial};
    }
    function moveToTop(obj) {
        let row = obj.parents("tr:first");
        let toprow = row.parent().children('tr:first');
        if (!row.is(toprow))
            row.insertBefore(toprow);
    }
    
    function qrsacn(stype) {
        scanType = stype;
        if (!standalone && !safari && ios) {
            window.location.href="sfqr://scan";
        } else {
           // add by qiuyj 2021-11-30 start  pc端扫码支持-->
           j$("#myModal2").show();
            j$("#qrcode").focus();
            //add by qiuyj 2021-11-30 end  pc端扫码支持-->
             //alert('扫描条形码请使用App');
             
        }
    }
 
 
 
    
</script>
</apex:page>