FUYU
2023-12-13 4488f711dbc01a8db6753907cae2ef4021dede68
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
import { LightningElement,api, track, wire } from 'lwc';
import getUserId from '@salesforce/apex/RentalApplyControllerLWT.getUserId';
import getProfileId from '@salesforce/apex/RentalApplyControllerLWT.getProfileId';
import init from '@salesforce/apex/RentalApplyControllerLWT.initFromCancelSubmitButton';
import selectRentalApplyEquipmentSetDetailByRacId from '@salesforce/apex/RentalApplyControllerLWT.selectRentalApplyEquipmentSetDetailByRacId';
import selectQISReportById from '@salesforce/apex/RentalApplyControllerLWT.selectQISReportById';
import selectRepairById from '@salesforce/apex/RentalApplyControllerLWT.selectRepairById';
import selectCampaignById from '@salesforce/apex/RentalApplyControllerLWT.selectCampaignById';
import selectRentalApplyEquipmentSetByRacId from '@salesforce/apex/RentalApplyControllerLWT.selectRentalApplyEquipmentSetByRacId';
import selectRentalApplyById from '@salesforce/apex/RentalApplyControllerLWT.selectRentalApplyById';
import selectUserById from '@salesforce/apex/RentalApplyControllerLWT.selectUserById';
import selectQISreportById2 from '@salesforce/apex/RentalApplyControllerLWT.selectQISreportById2';
import setSObjectShare from '@salesforce/apex/RentalApplyControllerLWT.setSObjectShare';
import updateRentalApplyC from '@salesforce/apex/RentalApplyControllerLWT.updateRentalApplyC';
import {CurrentPageReference} from 'lightning/navigation';
import { CloseActionScreenEvent } from 'lightning/actions';
import STATUS_PROCESS_STATE from '@salesforce/label/c.StatusProcessState';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import LightningConfirm from 'lightning/confirm';
import Id from '@salesforce/user/Id';
export default class rentalApplyLWT extends LightningElement {
 
    contactFirstName = 'Yan';
    contactLastName = 'Khang';
    opportunityName = 'Possible deal';
    clickedButtonLabel;
 
    @api recordId;
    @track StatusProcessState=STATUS_PROCESS_STATE;
    Rental_Apply__c;
    Status__c;
    Id;
    Yi_loaner_arranged__c;
    RA_Status__c;
    IsLoading=true;
    demo_purpose2__c;
    Follow_UP_Opp__c;
    Statu_Achievements__c;
    Statu_Achievements_ID__c;
    Request_shipping_day__c;
    Demo_purpose1__c;
    Repair__c;
    RecordTypeId;
    SupplementCreated__c;
    OPDPlan__c;
    Campaign__c;
    QIS_number__c;
    RepairId__c;
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference){
        console.log("进入页面");
        console.log(currentPageReference);
        if(currentPageReference){
            const urvalue=currentPageReference.state.recordId;
            if(urvalue){
                let str=`${urvalue}`;
                console.log('str');
                console.log(str);
                this.recordId=str;
            }
        }
    }
 
 
    async connectedCallback(){
        console.log(this.recordId);
        await init({recordId:this.recordId}).then(result=>{
            console.log(result);
            if(result!=null){
                this.Rental_Apply__c=result;
                this.Status__c=result.Status__c;
                this.Yi_loaner_arranged__c=result.Yi_loaner_arranged__c;
                this.Id=result.Id;
                this.RA_Status__c=result.RA_Status__c;
                // this.Rental_Apply__c.demo_purpose2__c=result.DemoPurpose2C;
                // this..Follow_UP_Opp__c=result.FollowUPOppC;
                // this.Rental_Apply__c.Statu_Achievements__c=result.StatuAchievementsC;
                // this.Rental_Apply__c.Statu_Achievements_ID__c=result.StatuAchievementsIDC;
                // this.Rental_Apply__c.Request_shipping_day__c=result.RequestShippingDayC;
                // this.Rental_Apply__c.Demo_purpose1__c=result.DemoPurpose1C;
                // this.Rental_Apply__c.Repair__c=result.RepairC;
                // this.Rental_Apply__c.RecordTypeId=result.RecordTypeId;
                // this.Rental_Apply__c.SupplementCreated__c=result.SupplementCreatedC;
                // this.Rental_Apply__c.OPDPlan__c=result.OPDPlanC;
                // this.Rental_Apply__c.Campaign__c=result.CampaignC;
                // this.Rental_Apply__c.QIS_number__c=result.QISNumberC;
                
                this.sumit().then(res=>{
                    console.log("关闭窗口");
                    this.IsLoading=false;
                    this.dispatchEvent(new CloseActionScreenEvent());
                }).catch(err=>{
                    console.log("error:");
                    console.log(err.message);
                    const event = new ShowToastEvent({
                        title: '提示信息',
                        message:"操作失败,提示信息:"+err.message,
                    });
                    this.dispatchEvent(event);
                    //alert("操作失败,提示信息:"+err.message);
                });
                console.log("end");
            }
        }).catch(err=>{
            console.log("error:");
            console.log(err.message);
            console.log("报错结束");
        }).finally(()=>{
            console.log("finally");
            
        });
        
    }
 
 
    async sumit(){
        let buttons = document.getElementsByName('submit_approval_process'.toLowerCase());
        for (let i=0; i<buttons.length; i++) {
            buttons[i].className = "btnDisabled";
            buttons[i].disabled = true;
        }
        //kk
 
        const result = await LightningConfirm.open({
            message: "一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?",
            variant: 'headerless',
            label: 'this is the aria-label value',
            // setting theme would have no effect
        });
        if (result==false) {
            return;
        }
        //1540 you 试用(无询价)目的的备品申请单,不能关联询价信息!
        if(this.Rental_Apply__c.demo_purpose2__c == '试用(无询价)' && this.Rental_Apply__c.Follow_UP_Opp__c !=null && this.Rental_Apply__c.Follow_UP_Opp__c != ''){
            //alert('试用(无询价)目的的备品申请单,不能关联询价信息!');
            const event = new ShowToastEvent({
                title: '提示信息',
                message:'试用(无询价)目的的备品申请单,不能关联询价信息!',
            });
            this.dispatchEvent(event);    
            return;
        }
        // 已购待货的申请单审批时,需要check注残的状态
        if (this.Rental_Apply__c.Statu_Achievements__c!=null&&this.Rental_Apply__c.Statu_Achievements__c!='') {
 
            let SaID=this.Rental_Apply__c.Statu_Achievements_ID__c;
            let rtn = sforce.apex.execute("RentalApplyWebService","RentalApplyCheckForSAoneEle",{SaID:SaID});
            if(rtn!='Fin'){
                //alert(rtn);
                const event = new ShowToastEvent({
                    title: '提示信息',
                    message:rtn,
                });
                this.dispatchEvent(event);    
                return;
            }
        }
        // 希望到货日不能早于申请提交日-0418追加
        let d=new Date();
        if (this.Rental_Apply__c.Request_shipping_day__c < d ) {
            //alert('希望到货日不能早于申请提交日');
            const event = new ShowToastEvent({
                title: '提示信息',
                message:'希望到货日不能早于申请提交日',
            });
            this.dispatchEvent(event);    
            return;
        }
        let raesdList = new Array();
        await selectRentalApplyEquipmentSetDetailByRacId({recordId:this.recordId}).then(result=>{
            console.log(result);
            if(result!=null){
                raesdList=result;
                let modelSet = new Set();
                let stoppedSet = new Set();
                for(let i=0;i<raesdList.length;i++){
                    modelSet.add(raesdList[i].Fixture_Model_No_F__c);
                    if('false' == raesdList[i].Product_Status_Flag_F__c
                    && (this.Rental_Apply__c.demo_purpose2__c == '试用(有询价)' || this.Rental_Apply__c.demo_purpose2__c == '试用(无询价)')){
                        stoppedSet.add(raesdList[i].Fixture_Model_No_F__c);
                    }
                }
                if(stoppedSet.size> 0) {
                    //alert( Array.from(stoppedSet).join(',') + ' 产品注册证状态为停止,不可申请');
                    const event = new ShowToastEvent({
                        title: '提示信息',
                        message:Array.from(stoppedSet).join(',') + ' 产品注册证状态为停止,不可申请',
                    });    
                    this.dispatchEvent(event);                    
                    return;
                }
            }
        }).catch(err=>{
            console.log("select1 error:");
            console.log(err.message);
            console.log("报错结束");
        }).finally(()=>{
        });
 
 
 
        if(this.Rental_Apply__c.demo_purpose2__c == '索赔QIS'){
            let DeliveryGood = new Array();
            await selectQISReportById({recordId:this.Rental_Apply__c.QIS_number__c}).then(result=>{
                console.log(result);
                DeliveryGood=result;    
            }).catch(err=>{
                console.log("select1 error:");
                console.log(err.message);
            }).finally(()=>{
            });
            console.log(DeliveryGood);    
            let records= DeliveryGood;
            if(records.length == 0 || !modelSet.has(records[0].nonyushohin__r.Product2.Fixture_Model_No_T__c)){
                //alert('申请的型号必须与QIS申请型号一致');
                const event = new ShowToastEvent({
                    title: '提示信息',
                    message:'申请的型号必须与QIS申请型号一致',
                });    
                this.dispatchEvent(event);    
                return;
            }
        }
        if(this.Rental_Apply__c.Repair__c==null){
            console.log("Repair__c为空")
        }else{
            if( this.Rental_Apply__c.Repair__c != ''){
                console.log("hhh7.1.1");
                let DeliveryGood ;
                let records;
                await selectRepairById({recordId:this.Rental_Apply__c.Repair__c}).then(result=>{
                    console.log(result);
                    DeliveryGood=result;    
                    records=result;
                }).catch(err=>{
                    console.log("select1 error:");
                    console.log(err.message);
                }).finally(()=>{
                });
                if(records==null||records.length==0){
                    console.log("records为空");
                }else{
                    if(this.Rental_Apply__c.Demo_purpose1__c == '维修代用' && this.Rental_Apply__c.demo_purpose2__c != '索赔QIS') {
                        if(!modelSet.has(records[0].Delivered_Product__r.Product2.Fixture_Model_No_T__c)){
                            //alert('申请的型号必须与送修的型号一致');
                            const event = new ShowToastEvent({
                                title: '提示信息',
                                message:'申请的型号必须与送修的型号一致',
                            });                
                            this.dispatchEvent(event);                    
                            return;
                        }
                    }
                    if(this.Rental_Apply__c.Demo_purpose1__c==null){
                        console.log("Demo_purpose1__c为空");
                    }else if(this.Rental_Apply__c.Demo_purpose1__c == '维修代用' && this.Rental_Apply__c.demo_purpose2__c == '一般用户' ){
                        if (records[0].Repair_Estimated_date_formula__c == null) {
                            //alert('一般维修无报价日,不可借用备品');
                            const event = new ShowToastEvent({
                                title: '提示信息',
                                message:'一般维修无报价日,不可借用备品',
                            });            
                            this.dispatchEvent(event);                        
                            return;
                        }
 
                        else if (records[0].Repair_Estimated_date_formula__c < '2019-07-01' && records[0].Agreed_Date__c == null) {
                            //alert('报价日在2019/7/1之前且户同意日为空,不可借用备品');
                            const event = new ShowToastEvent({
                                title: '提示信息',
                                message:'报价日在2019/7/1之前且户同意日为空,不可借用备品',
                            });        
                            this.dispatchEvent(event);                            
                            return;
                        }
                        //20210608 ljh SFDC-C3CCN4 start
                        if(records[0].Repair_Rank__c == '' || records[0].Repair_Rank__c == null){
                            //alert('报价等级为空不能申请备品');
                            const event = new ShowToastEvent({
                                title: '提示信息',
                                message:'报价等级为空不能申请备品',
                            });        
                            this.dispatchEvent(event);                                
                            return;
                        }else{
                            if(records[0].DW_Sign_Txt__c == 'false' && records[0].Repair_Rank__c == 'DW'){
                                //alert('DW报价等级下此型号不符合备品申请借用条件');
                                const event = new ShowToastEvent({
                                    title: '提示信息',
                                    message:'DW报价等级下此型号不符合备品申请借用条件',
                                });        
                                this.dispatchEvent(event);                                
                                return;
                            }
                            if(records[0].Repair_Rank__c == 'D1'
                                ||records[0].Repair_Rank__c == 'D2'
                                ||records[0].Repair_Rank__c == 'D3'
                                ||records[0].Repair_Rank__c == 'E2'){
                                //alert('报价等级不符合备品申请借用条件');
                                const event = new ShowToastEvent({
                                    title: '提示信息',
                                    message:'报价等级不符合备品申请借用条件',
                                });        
                                this.dispatchEvent(event);    
                                return;
                            }
                        }
                    //20210608 ljh SFDC-C3CCN4 end
                    }
                    if(this.Rental_Apply__c.Demo_purpose1__c ==null){
                        console.log("Demo_purpose1__c为空");
                    }else if(this.Rental_Apply__c.Demo_purpose1__c == '维修代用' && this.Rental_Apply__c.demo_purpose2__c == '市场多年保修' ){
                        if (records[0].FSE_ApplyForRepair_Day__c == null) {
                            // alert('市场多年保修,没有[FSE修理申请日],不可借用备品');
                            const event = new ShowToastEvent({
                                title: '提示信息',
                                message:'市场多年保修,没有[FSE修理申请日],不可借用备品',
                            });        
                            this.dispatchEvent(event);    
                            return;
                        }
                    }
                    if(this.Rental_Apply__c.Demo_purpose1__c == '维修代用' && this.Rental_Apply__c.demo_purpose2__c == '故障排查' ){
                        if (records[0].FSE_ApplyForRepair_Day__c == null) {
                            //alert('故障排查,没有[FSE修理申请日],不可借用备品');
                            const event = new ShowToastEvent({
                                title: '提示信息',
                                message:'市场多年保修,没有[FSE修理申请日],不可借用备品',
                            });        
                            this.dispatchEvent(event);                                
                            return;
                        }
                        if(records[0].Repair_Ordered_Date__c != null) {
                            //alert('故障排查,[4.修理品RC受理日]必须为空');
                            const event = new ShowToastEvent({
                                title: '提示信息',
                                message:'市场多年保修,没有[FSE修理申请日],不可借用备品',
                            });        
                            this.dispatchEvent(event);                                
                            return;
                        }
                        if(records[0].IfCheckFixture__c == 'false'){
                            //alert('不满足故障排查目的');
                            const event = new ShowToastEvent({
                                title: '提示信息',
                                message:'市场多年保修,没有[FSE修理申请日],不可借用备品',
                            });        
                            this.dispatchEvent(event);                                
                            return;
                        }
                    }
                    let profileId="";
                    await getProfileId().then(result=>{
                        console.log(result);
                        profileId=result;    
                    }).catch(err=>{
                        console.log("getProfileId error:");
                        console.log(err.message);
                    }).finally(()=>{
                    });
                    if(this.Rental_Apply__c.RecordTypeId==null){
                        console.log("RecordTypeId为空");
                    }else if (this.Rental_Apply__c.RecordTypeId != "01210000000RHIn"
                        && profileId != '00e10000000Y3o5'
                        && records[0].NewProductGuaranteeObject__c == '8: 市场多年保修'
                        && this.Rental_Apply__c.demo_purpose2__c != '市场多年保修') {
                        //alert('无偿区别标志为8: 市场多年保修,必须选择市场多年保修。');
                        const event = new ShowToastEvent({
                            title: '提示信息',
                            message:'市场多年保修,没有[FSE修理申请日],不可借用备品',
                        });        
                        this.dispatchEvent(event);                        
                    }
                    if(records[0].Repair_Final_Inspection_Date__c != null){
                        //alert('存在修理最终检测日,不可借用备品');
                            const event = new ShowToastEvent({
                                title: '提示信息',
                                message:'市场多年保修,没有[FSE修理申请日],不可借用备品',
                            });        
                            this.dispatchEvent(event);                            
                        return;
                    }
                    if(records[0].Repair_Shipped_Date__c != null){
                        //alert('存在RC修理返送日,不可借用备品');
                            const event = new ShowToastEvent({
                                title: '提示信息',
                                message:'市场多年保修,没有[FSE修理申请日],不可借用备品',
                            });        
                            this.dispatchEvent(event);                            
                        return;
                    }
                    if(records[0].Status1__c =='0.删除' ||records[0].Status1__c =='0.取消' ||records[0].Status1__c =='5.完毕' ){
                        //alert('修理已经结束,不能申请备品');
                            const event = new ShowToastEvent({
                                title: '提示信息',
                                message:'市场多年保修,没有[FSE修理申请日],不可借用备品',
                            });        
                            this.dispatchEvent(event);                            
                        return;
                    }
                    if ( this.Rental_Apply__c.demo_purpose2__c == '再修理' && records[0].ReRepairObject_F__c == 'false') {
                        //alert('不属于再受理参考对象,不可借用备品');
                            const event = new ShowToastEvent({
                                title: '提示信息',
                                message:'市场多年保修,没有[FSE修理申请日],不可借用备品',
                            });        
                            this.dispatchEvent(event);                            
                        return;
                    }
                    if (this.Rental_Apply__c.RecordTypeId != '01210000000RHIn'
                        && this.Rental_Apply__c.demo_purpose2__c != '保修用户'
                        && this.Rental_Apply__c.demo_purpose2__c != '市场多年保修'
                        && records[0].Number_of_EffectiveContract__c == '有' ) {
                        //alert('有维修合同,必须选择保修用户.');
                            const event = new ShowToastEvent({
                                title: '提示信息',
                                message:'市场多年保修,没有[FSE修理申请日],不可借用备品',
                            });        
                            this.dispatchEvent(event);    
                        return;
                    }
                    let AssetModelNo = records[0].Delivered_Product__r.Product2.Asset_Model_No__c;
                    if (this.Rental_Apply__c.RecordTypeId != '01210000000RHIn' && records[0].Number_of_EffectiveContract__c == '无'
                        && (records[0].NewProductGuaranteeObject__c == '2: 服务多年保修'
                        && (AssetModelNo == 'LTF-190-10-3D' || AssetModelNo == 'LTF-S190-5' || AssetModelNo == 'CYF-VHA' || AssetModelNo == 'CYF-VA2' || AssetModelNo == 'CYF-5A'|| AssetModelNo == 'LTF-S190-10'|| AssetModelNo == 'OER-AW'|| AssetModelNo == 'URF-V'|| AssetModelNo == 'URF-V2'|| AssetModelNo == 'URF-P6'))
                        && this.Rental_Apply__c.demo_purpose2__c != '保修用户' ) {
                        //alert('此设备型号多年保修,请选择保修用户.');
                            const event = new ShowToastEvent({
                                title: '提示信息',
                                message:'市场多年保修,没有[FSE修理申请日],不可借用备品',
                            });        
                            this.dispatchEvent(event);                        
                        return;
                    }
 
                    if (this.Rental_Apply__c.RecordTypeId != '01210000000RHIn'
                        && records[0].NewProductGuaranteeObject__c == '2: 服务多年保修'
                        && (AssetModelNo == 'CV-V1' || AssetModelNo == 'CV-V1(A)' || AssetModelNo == 'CV-V1(B)' || AssetModelNo == 'GIF-LV1' || AssetModelNo == 'CF-LV1L' || AssetModelNo == 'CF-LV1I' || AssetModelNo == 'MAJ-1910')
                        && (this.Rental_Apply__c.demo_purpose2__c == '一般用户' || this.Rental_Apply__c.demo_purpose2__c == '再修理')
                        ) {
                            //alert('奥辉设备,保修期内不提供备品.');
                            const event = new ShowToastEvent({
                                title: '提示信息',
                                message:'市场多年保修,没有[FSE修理申请日],不可借用备品',
                            });        
                            this.dispatchEvent(event);                            
                            return;
                    }
                }
                
            }
        } 
 
        if(this.Rental_Apply__c.SupplementCreated__c==null){
            console.log("SupplementCreated__c为空");
        }else if (this.Rental_Apply__c.SupplementCreated__c == '1' && this.Rental_Apply__c.OPDPlan__c != '') {
            let raId = this.Id;
            //kk
            let raesCountCheck = sforce.apex.execute("OpdPlanWebService", "raesCountCheck", {rentalApplyId: raId});
            if(raesCountCheck != 'OK'){
                //alert(raesCountCheck);
                const event = new ShowToastEvent({
                    title: '提示信息',
                    message:raesCountCheck,
                });        
                this.dispatchEvent(event);                    
                return;
            }
        }
        console.log("hhh10");
        if(this.Rental_Apply__c.Campaign__c==null){
            console.log("Campaign__c为空");
        }else if( this.Rental_Apply__c.Campaign__c != ''){
            let DeliveryGood = new Array();
            // 20220324 ljh obpm update start
            //kk1
            let statusSting = this.StatusProcessState;
            let statusList = statusSting.split(',');
            // DeliveryGood = sforce.connection.query("select Status, Rental_Apply_Flag__c from Campaign where id ='{!Rental_Apply__c.Campaign__c}'");
            // DeliveryGood = await selectCampaignById(this.Rental_Apply__c.Campaign__c);
            await selectCampaignById({recordId:this.Rental_Apply__c.Campaign__c}).then(result=>{
                console.log(result);
                DeliveryGood=result;    
            }).catch(err=>{
                console.log("selectCampaignById error:");
                console.log(err.message);
            }).finally(()=>{
            });
            // 20220324 ljh obpm update start
            //kk
            let records= DeliveryGood;
 
            let interval = records[0].Status;
            let records_Date = records[0].Rental_Apply_Flag__c;
            if (interval==null ) {
                //alert("请确认学会状态");
                const event = new ShowToastEvent({
                    title: '提示信息',
                    message:"请确认学会状态",
                });        
                this.dispatchEvent(event);                    
                return;
            }
            else if (interval == '草案中') {
                //alert('学会状态为草案中,不能提交');
                const event = new ShowToastEvent({
                    title: '提示信息',
                    message:'学会状态为草案中,不能提交',
                });        
                this.dispatchEvent(event);
                return;
            }
            else if (interval == '申请中') {
                //alert('学会状态为申请中,不能提交');
                const event = new ShowToastEvent({
                    title: '提示信息',
                    message:'学会状态为申请中,不能提交',
                });        
                this.dispatchEvent(event);
                return;
            }
            else if (interval == '已结束') {
                // alert('学会状态为已结束,不能提交');
                const event = new ShowToastEvent({
                    title: '提示信息',
                    message:'学会状态为已结束,不能提交',
                });        
                this.dispatchEvent(event);
                return;
            }
            else if (interval == '已提交报告') {
                // alert('学会状态为已提交报告,不能提交');
                const event = new ShowToastEvent({
                    title: '提示信息',
                    message:'学会状态为已提交报告,不能提交',
                });        
                this.dispatchEvent(event);
                return;
            }
            else if (interval == '取消申请中') {
                // alert('学会状态为取消申请中,不能提交');
                const event = new ShowToastEvent({
                    title: '提示信息',
                    message:'学会状态为取消申请中,不能提交',
                });        
                this.dispatchEvent(event);
                return;
            }
            else if (interval == '取消') {
                // alert('学会状态为取消,不能提交');
                const event = new ShowToastEvent({
                    title: '提示信息',
                    message:'学会状态为取消,不能提交',
                });        
                this.dispatchEvent(event);
                return;
            }
            //kk
            if(this.Rental_Apply__c.Request_shipping_day__c==null){
                // alert("请确认希望到货日期");
                const event = new ShowToastEvent({
                    title: '提示信息',
                    message:"请确认希望到货日期",
                });        
                this.dispatchEvent(event);
                return;
            }else{
                if (d >= this.Rental_Apply__c.Request_shipping_day__c -7) {
                    // alert("必须提前于希望到货日7天以上提交申请");
                    const event = new ShowToastEvent({
                        title: '提示信息',
                        message:"必须提前于希望到货日7天以上提交申请",
                    });        
                    this.dispatchEvent(event);
                    return;
                }
                // 20220324 ljh obpm add start
                if (records != null && records[0].IF_Approved__c == "true" && (records[0].Meeting_Approved_No__c == null || records[0].Meeting_Approved_No__c == "") ) {
                    // alert("没有决裁号的,暂不能出借,请更新裁决信息。");
                    const event = new ShowToastEvent({
                        title: '提示信息',
                        message:"没有决裁号的,暂不能出借,请更新裁决信息。",
                    });        
                    this.dispatchEvent(event);
                    return;
                }
                if (records != null && records[0].IF_Approved__c == "true" && records[0].Meeting_Approved_No__c != "" && statusList.indexOf(records[0].Approved_Status__c) != -1 && records[0].Approved_Status__c != '草稿' ) {
                    // alert("已申请决裁但决裁状态不符合条件。");
                    const event = new ShowToastEvent({
                        title: '提示信息',
                        message:"已申请决裁但决裁状态不符合条件。",
                    });        
                    this.dispatchEvent(event);
                    return;
                }
            }
            
            // 20220324 ljh obpm add end
        }
 
        if (this.Rental_Apply__c.QIS_number__c == null) {
            console.log("QIS_number__c 是空的");
        }else{
            if( this.Rental_Apply__c.QIS_number__c != ''){
                let DeliveryGood = new Array();
                // DeliveryGood =await selectQISreportById2(this.Rental_Apply__c.QIS_ID_Line__c);
                await selectQISreportById2({recordId:this.Rental_Apply__c.QIS_ID_Line__c}).then(result=>{
                    console.log(result);
                    DeliveryGood=result;    
                }).catch(err=>{
                    console.log("selectCampaignById error:");
                    console.log(err.message);
                }).finally(()=>{
                });
                let records= DeliveryGood;
                let interval = records[0].next_action__c;
                if (interval == '送回') {
                    // alert("QIS 已送回,不能再申请备品了");
                    const event = new ShowToastEvent({
                        title: '提示信息',
                        message:"QIS 已送回,不能再申请备品了",
                    });        
                    this.dispatchEvent(event);
                    return;
                }
            }
        }
        // share
        let userAccess = new Array();
        //kk
        let t=this.Rental_Apply__c.applyUser__c+'_Edit';
        userAccess.push(t);
        let rtn ;
        await setSObjectShare({sobjectName:'Rental_Apply__Share',rowCause:'ApplyUserShare__c',parentId:this.Rental_Apply__c.Id,userAccess:userAccess,ownerId:this.Rental_Apply__c.OwnerId}).then(result=>{
            console.log(result);
            rtn=result;    
        }).catch(err=>{
            console.log("setSObjectShare error:");
            console.log(err.message);
        }).finally(()=>{
        });
 
        if(rtn==null){
            // alert("rtn为空");
            const event = new ShowToastEvent({
                title: '提示信息',
                message:"rtn为空",
            });        
            this.dispatchEvent(event);
            return;
        }else{
            if (rtn != 'OK') {
                // alert(rtn);
                const event = new ShowToastEvent({
                    title: '提示信息',
                    message:rtn,
                });        
                this.dispatchEvent(event);
                return;
            }    
        }
        if(this.Rental_Apply__c.Status__c == null){
            // alert('请备品申请状态确认,不能为空');
            const event = new ShowToastEvent({
                title: '提示信息',
                message:'请备品申请状态确认,不能为空',
            });        
            this.dispatchEvent(event);
            return;
        }else{
            if (this.Rental_Apply__c.Status__c == '填写完毕' ||
                this.Rental_Apply__c.Status__c == '申请中' ||
                this.Rental_Apply__c.Status__c == '已批准' ||
                //现在申请书的Status__c已经没有引当完了状态。所以这里不需要判断
                //'{!Rental_Apply__c.Status__c}' == '引当完了' ||
                this.Rental_Apply__c.Status__c == '已出库指示' ||
                this.Rental_Apply__c.Status__c == '删除' ||
                this.Rental_Apply__c.Status__c == '取消' ) {
                    // alert('请备品申请状态确认,已经提交过的申请,不能重复提交');
                    const event = new ShowToastEvent({
                        title: 'Get Help',
                        message:'请备品申请状态确认,已经提交过的申请,不能重复提交'
                    });
                    this.dispatchEvent(event);
                    return;
            }
        }
            // 没有明细的一览check
        let raesList = new Array();
        // raesList = selectRentalApplyEquipmentSetByRacId(this.recordId);
        await selectRentalApplyEquipmentSetByRacId({recordId:this.recordId}).then(result=>{
            console.log(result);
            raesList=result;    
        }).catch(err=>{
            console.log("selectCampaignById error:");
            console.log(err.message);
        }).finally(()=>{
        });
        let records= raesList;
 
        if(records.length > 0){
            // alert('有没有明细的借出备品配套一览,不能提交');
            const event = new ShowToastEvent({
                title: '提示信息',
                message:'有没有明细的借出备品配套一览,不能提交',
            });        
            this.dispatchEvent(event);
            return;
        }
        
        let racs ;
        await selectRentalApplyById({recordId:this.recordId}).then(result=>{
            console.log(result);
            racs=result;    
        }).catch(err=>{
            console.log("selectCampaignById error:");
            console.log(err.message);
        }).finally(()=>{
        });
        let racNew = racs[0];
        let id=this.Rental_Apply__c.Id;
        let Status__c="填写完毕";
        let userId;
        await getUserId().then(result=>{
            console.log(result);
            userId=result;    
        }).catch(err=>{
            console.log("selectCampaignById error:");
            console.log(err.message);
        }).finally(()=>{
        });
        let manageUsers;
        await selectUserById({recordId:userId}).then(result=>{
            console.log(result);
            manageUsers=result;    
        }).catch(err=>{
            console.log("selectCampaignById error:");
            console.log(err.message);
        }).finally(()=>{
        });
        let SalesManagerSubmit__c;
        let OPDManagerApprover__c;
        let BuchangApprovalManagerSalesSubmit__c;
        let OPDBuchangApprover__c;
        if(manageUsers[0].JingliEquipmentManager__c != null){
            SalesManagerSubmit__c = manageUsers[0].JingliEquipmentManager__r.Name;
        // 20220930 ljh SWAG-CJR8S7 start
            if(racNew.OPDPlan__c != null){
                OPDManagerApprover__c = SalesManagerSubmit__c == racNew.OPDPlan__r.SalesManager_Txt__c?SalesManagerSubmit__c:' ';
            }
        // 20220930 ljh SWAG-CJR8S7 end
        }
        if(manageUsers[0].Buzhang_Equipment_Manager__c != null){
            BuchangApprovalManagerSalesSubmit__c = manageUsers[0].Buzhang_Equipment_Manager__r.Name; //2022-07-22 zyh
        // 20220930 ljh SWAG-CJR8S7 start
            if(racNew.OPDPlan__c != null){
                OPDBuchangApprover__c = BuchangApprovalManagerSalesSubmit__c == racNew.OPDPlan__r.BuchangApprovalManagerSales_Txt__c?BuchangApprovalManagerSalesSubmit__c:' ';
            }
        // 20220930 ljh SWAG-CJR8S7 end
        }
        let resultt;
        await updateRentalApplyC({
            recordId:id,
            SalesManagerSubmitC:SalesManagerSubmit__c,
            StatusC:Status__c,
            OPDManagerApproverC:OPDManagerApprover__c,
            BuchangApprovalManagerSalesSubmitC:BuchangApprovalManagerSalesSubmit__c,
            OPDBuchangApproverC:OPDBuchangApprover__c
        }).then(res=>{
            console.log(res);
            if(res!=null&&res.success==false){
                resultt=res;
                let messages ="";
                messages=resultt.errors[0].split(',')[1];
                if (messages!=null&&messages!="") {
                    console.log("hhh26");
                    // alert("操作失败,提示信息:"+messages);
                    const event = new ShowToastEvent({
                        title: '提示信息',
                        message:"操作失败,提示信息:"+messages,
                    });        
                    this.dispatchEvent(event);
                    return;
                }
            }
        }).catch(err=>{
            console.log("updateRentalApplyC error:");
            console.log(err.message);
        }).finally(()=>{
            console.log("finally");
            console.log(resultt);
        });
 
        this.dispatchEvent(new CloseActionScreenEvent());
    };
 
    getConnectDMLErrorMessages (results) {
        console.log("in 1");
        console.log(results);
        let messages = [];
        let    i = 0;
        let    len = results.length;
        let    r;
        console.log("in 1.1");
        for (; i < len; i++) {
            console.log("in 1.2");
            r = results[i];
            console.log("in 1.3");
            if (r.success==false) {
                console.log("in 1.4");
                messages = messages.concat(this.getConnectDMLMessagesOfAResult(r));
            }
        }
        console.log("in 1");
        console.log("1结果");
        console.log(messages);
        return messages;
    };
    getConnectDMLMessagesOfAResult(res) {
        console.log("in 2");
        console.log(res);
        let messages = [];
        let    errors = res.errors;
        let    i = 0;
        let    len = errors.length;
        let    e;
        for (; i < len; i++) {
            e = errors[i];
            console.log("in 2.1");
            messages.push(e + " " + this.getConnectDMLErrorFields(errors));
            console.log("3结果");
            console.log(this.getConnectDMLErrorFields(errors));
            console.log("in 2.2");
        }
        console.log("in 2");
        console.log("2结果");
        console.log(messages);
        return messages;
    };
    
    getConnectDMLErrorFields (error) {
        console.log("in 3");
        console.log(error);
        let fields = error;
        if (fields.length > 0) {
            console.log("in 3");
            return "[" + fields + ",]"
        } 
        else {
            console.log("in 3");
            return "";
        }
    };
}