liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
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
import getStaticResource from "@salesforce/apex/ButtonJsUtility.getStaticResource";
import init from "@salesforce/apex/otherButtonRepairController.init";
import initList from "@salesforce/apex/otherButtonRepairController.initList";
import initSelectProfile from '@salesforce/apex/otherButtonRepairController.initSelectProfile';
import initUserName from '@salesforce/apex/otherButtonRepairController.initUserName';
import queryForEquipments from "@salesforce/apex/otherButtonRepairController.queryForEquipments";
import queryForFindInvalidLicense from "@salesforce/apex/otherButtonRepairController.queryForFindInvalidLicense";
import queryForRds from "@salesforce/apex/otherButtonRepairController.queryForRds";
import queryForReocrds from "@salesforce/apex/otherButtonRepairController.queryForReocrds";
import queryForRepairCount from "@salesforce/apex/otherButtonRepairController.queryForRepairCount";
import queryForUrfAsset from "@salesforce/apex/otherButtonRepairController.queryForUrfAsset";
import queryForUrfSeriesInfo from "@salesforce/apex/otherButtonRepairController.queryForUrfSeriesInfo";
import queryForrecords3 from "@salesforce/apex/otherButtonRepairController.queryForrecords3";
import updateRepair2 from "@salesforce/apex/otherButtonRepairController.updateRepair2";
import CeilingContractRepair from "@salesforce/apex/otherButtonRepairController.CeilingContractRepair";
//import AWSService from "@salesforce/resourceUrl/AWSService";
//import { AWSService } from 'c/piUtils'; //Deloitte-zhj PIPL解密 2023-08-23   //deloitte-zhj 20231123 PIPL还原
import { CloseActionScreenEvent} from "lightning/actions";
import { CurrentPageReference} from "lightning/navigation";
import { ShowToastEvent} from 'lightning/platformShowToastEvent';
import { LightningElement, api, wire} from "lwc";
 
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';        
import lexSendNfm103 from '@salesforce/resourceUrl/lexSendNfm103';        
import {loadStyle} from 'lightning/platformResourceLoader'    
import LightningConfirm from 'lightning/confirm';
 
import IFTradeComplianceAlert2 from '@salesforce/label/c.IFTradeComplianceAlert2'; // sx 贸易合规2期 add
import accSendEmailFW from '@salesforce/apex/buttonAssetCtl.accSendEmailFW';//wyl 贸易合规2期 add
 
export default class LexSendNFM103 extends LightningElement {
  @api recordId;
  dealer;
  numberofEffectiveContract;
  newProductGuaranteTxt;
  onSiteRepair;
  maintenanceContract;
  VMMaintenanceContract;
  FSEState;
  dateReceiptQuestions;
  delayReportReason;
  repairSource;
  quickRepairSign;
  RCCD;
  returnsProductway;
  salesDeptHP;
  isAohuiProduct;
  stateHospital;
  assetOwner;
  deliveredProductId;
  FSEApplyForRepairTime;
  maintenanceContractId;
  URFLimitSerial;
  status;
  dealerId;
  ifDeadHurt;
  dayLater30;
  recallCorrespondence;
  URFReapir;
  inchargeStaffId;
  DWSign;
  DOJStatus;
  SAPcondition;
  salesOfficeCodeSelection;
  profileId;
  userId;
  AWSDataId;
  userName;
  profileName;
  Id;
  DetailedAddress;
  surplusCount = 0;
  url;
  HPActiveC;
  tradeComplianceStatusFlagFW;
  typeDeveloperName;
  ifTradeComplianceIntercept;
  ifTradeComplianceAlert;
  HospitalC;
  affiliationRC;
  limitPrice;
  //AWSService;//Deloitte-zhj PIPL解密 2023-08-23  //deloitte-zhj 20231123 PIPL还原
  //staticResorceRepair; //Deloitte-zhj PIPL解密 2023-08-23  //deloitte-zhj 20231123 PIPL还原
  records1;
  administrator;
  huyucheng;
  liqiqing;
  guoyang;
  AccountName; // WYL 贸易合规2期 add
  state; // WYL 贸易合规2期 add
  Asset_Model_No; // WYL 贸易合规2期 add
  ProTradeComplianceStatus;// WYL 贸易合规2期 add
  repairLength = 0;
  maintenanceFlag = false;
  @wire(CurrentPageReference)
  getStateParameters(currentPageReference) {
    if (currentPageReference) {
      this.url = currentPageReference.state.backgroundContext;
      const urlValue = currentPageReference.state.recordId;
      if (urlValue) {
        let str = `${urlValue}`;
        this.recordId = str;
      }
    }
  }
 
  connectedCallback() {
    // debugger
    Promise.all([            
        loadStyle(this, lwcCSS),
        loadStyle(this, lexSendNfm103)
        // ,
        // loadScript(this, AWSService + '/AWSService.js'),
        // loadScript(this, jqueryurl),
        // loadScript(this, jq + "/dist/jquery.js"),
        // loadScript(this, con),
        // loadScript(this, apex),
        // loadScript(this, common)    
    ]);    
    //this.AWSService = new AWSService();//Deloitte-zhj PIPL解密 2023-08-23   //deloitte-zhj 20231123 PIPL还原
    init({
      recordId: this.recordId
    }).then(result => {
      console.log(result);
 
      var btns = document.getElementsByName("send_nfm103");
      for (var i = 0; i < btns.length; i++) {
        btns[i].disabled = true;
        btns[i].className = 'btnDisabled';
      }
      this.Id = result.Id;
      this.HPActiveC = result.HPActiveC;
      this.DetailedAddress = result.detailedAddress;
      this.dealer = result.DealerC;
      this.numberofEffectiveContract = result.numberofEffectiveContract;
      this.newProductGuaranteTxt = result.newProductGuaranteTxt;
      this.onSiteRepair = result.OnSiteRepairC;
      this.maintenanceContract = result.maintenanceContract;
      this.VMMaintenanceContract = result.VMMaintenanceContract;
      this.FSEState = result.FSEState;
      this.dateReceiptQuestions = result.DateReceiptQuestionsC;
      this.delayReportReason = result.DelayReportReasonC;
      this.repairSource = result.repairSource;
      this.quickRepairSign = result.quickRepairSign;
      this.RCCD = result.RCCD;
      this.returnsProductway = result.ReturnsProductWayC;
      this.salesDeptHP = result.salesDeptHP;
      this.isAohuiProduct = result.isAohuiProduct;
      this.stateHospital = result.stateHospital;
      this.assetOwner = result.assetOwner;
      this.deliveredProductId = result.deliveredProductId;
      this.FSEApplyForRepairTime = result.FSEApplyForRepairTime;
      this.maintenanceContractId = result.maintenanceContractId;
      this.URFLimitSerial = result.URFLimitSerial;
      this.status = result.status;
      this.dealerId = result.dealerId;
      this.ifDeadHurt = result.ifDeadHurtC;
      this.dayLater30 = result.dayLater30;
      this.recallCorrespondence = result.recallCorrespondence;
      this.URFReapir = result.URFReapir;
      this.inchargeStaffId = result.inchargeStaffId;
      this.DWSign = result.DWSign;
      this.DOJStatus = result.DOJStatus;
      this.SAPcondition = result.SAPcondition;
      this.salesOfficeCodeSelection = result.SalesOfficeCodeSelectionC;
      this.profileId = result.profileId;
      this.userId = result.userID;
      this.AWSDataId = result.AWSDataId;
      this.HospitalC = result.HospitalC;
      this.AccountName = result.AccountName;// WYL 贸易合规2期 add 
      this.state = result.state; // WYL 贸易合规2期 add
      this.Asset_Model_No = result.Asset_Model_No; // WYL 贸易合规2期 add
      this.ProTradeComplianceStatus = result.ProTradeComplianceStatus; // WYL 贸易合规2期 add
      this.tradeComplianceStatusFlagFW = result.tradeComplianceStatusFlagFW;
      this.typeDeveloperName = result.typeDeveloperName;
      this.ifTradeComplianceIntercept = result.ifTradeComplianceIntercept;
      this.ifTradeComplianceAlert = result.ifTradeComplianceAlert;
      this.affiliationRC = result.affiliationRC;
      this.limitPrice = result.limitPrice;
      this.records1 = result.sql;
      //this.staticResorceRepair = JSON.parse(result.staticResourceRepair); //Deloitte-zhj PIPL解密 2023-08-23    //deloitte-zhj 20231123 PIPL还原
      initList().then(res => {
        console.log(res,'administrator--->>')
        this.administrator = res.administrator;
        this.huyucheng = res.huyucheng;
        this.liqiqing = res.liqiqing;
        this.guoyang = res.guoyang;
    })
      this.onefunction();
    }).catch(error => {
      console.log(error);
    });
  }
 
  async onefunction(){
    await initUserName({
      userId: this.userId
    }).then(result => {
      if (result != null) {
        this.IsLoading = false;
        this.userName = result[0].Name;
      }
    })
 
    await initSelectProfile({
      profileId: this.profileId
    }).then(result => {
      if (result != null) {
        this.IsLoading = false;
        this.profileName = result[0].Name;
      }
    })
    //deloitt-zhj 20231126 PIPL还原 start
    this.nextfunction();
    // let that = this
    // var staticResource;
    // await getStaticResource({
      //   sobj: "Repair__c"
    // }).then(result => {
      //   staticResource = JSON.parse(result);
      //   console.log(staticResource,'staticResource');
      //   // debugger
      //   that.AWSService.query(staticResource.queryUrl,
        //     that.AWSDataId,
        //     function (data) {
          //       console.log('data zhj = ',data);
          //       if (data && data.object) {
            //         that.DetailedAddress = data.object.detailedAddress;
          //       }
    //       that.nextfunction();
      //   },staticResource.token);
    // })
//deloitt-zhj 20231126 PIPL还原 end
  }
 
  async nextfunction() {
    // debugger;
    console.log('nextfunction方法------->>>');
    //贸易合规 you
    var TradeComplianceStatusFlagFW = this.tradeComplianceStatusFlagFW;//贸易合规开关
    var IFTradeComplianceAlert = this.ifTradeComplianceAlert;//贸易合规提醒
    console.log('贸易合规开关------->>>',TradeComplianceStatusFlagFW);
    if (TradeComplianceStatusFlagFW) {
      console.log('this.records1------------->>>',this.records1);
      console.log('this.records1.length------------->>>',this.records1.length);
      if (null != this.records1 && this.records1.length > 0) {
        var flaginacc = false;
        var flagindea = false;
        var flagwaacc = false;
        var flagwadea = false;
        console.log('贸易合规------->>>',this.records1);
        this.records1.forEach(item => {
          var AccDealerBlacklist = item.IFTradeComplianceIntercept__c;//判断客户/经销商是否为黑名单
          var recname = item.RecordType.DeveloperName;
          console.log('AccDealerBlacklist------------->>>>>>',AccDealerBlacklist);
          if(AccDealerBlacklist=='intercept'){
            if(recname =='HP' && this.HospitalC  !=null && this.HospitalC !=''){
              flaginacc = true;
            }
            console.log('this.DealerC------------->>>>>>',this.dealer);
            if (recname == 'Agency' && this.dealer != null && this.dealer != '') {
              flagindea = true;
            }
          }
          if (AccDealerBlacklist == 'WarningList') {
            if (recname == 'HP' && this.HospitalC  !=null && this.HospitalC !='') {
              flagwaacc = true;
            }
            if (recname == 'Agency' && this.dealer != null && this.dealer != '') {
              flagwadea = true;
            }
          }
        });
        console.log('flaginacc------------->>>',flaginacc);
        console.log('flagindea------------->>>',flagindea);
        console.log('flagwaacc------------->>>',flagwaacc);
        console.log('flagwadea------------->>>',flagwadea);
        
        if (flaginacc && flagindea) {
          this.ShowToastEvent('您所选择的医院和经销商存在贸易合规风险,无法新建修理,' + IFTradeComplianceAlert, 'error');
          this.dispatchEvent(new CloseActionScreenEvent());
          this.SendEmailFW(this.AccountName,this.recordId,'1',this.state,null); // wyl 贸易合规2期 add
          return;
        } else if (flaginacc) {
          this.ShowToastEvent('您所选择的医院存在贸易合规风险,无法新建修理,' + IFTradeComplianceAlert, 'error');
          this.SendEmailFW(this.AccountName,this.recordId,'1',this.state,null);// wyl 贸易合规2期 add
          this.dispatchEvent(new CloseActionScreenEvent());
          return;
        } else if (flagindea) {
          this.ShowToastEvent('您所选择的经销商存在贸易合规风险,无法新建修理,' + IFTradeComplianceAlert, 'error');
          this.SendEmailFW(this.AccountName,this.recordId,'1',this.state,null);// wyl 贸易合规2期 add
          this.dispatchEvent(new CloseActionScreenEvent());
          return;
        }
 
 
        // if (flagwaacc && flagwadea) {
        //   if (!this.handleConfirmClick('您所选择的医院和经销商存在贸易合规警示风险,是否继续申请修理,' + IFTradeComplianceAlert)) {
        //     return;
        //   }
        // } else if (flagwaacc) {
        //   if (!this.handleConfirmClick('您所选择的医院存在贸易合规警示风险,是否继续申请修理,' + IFTradeComplianceAlert)) {
        //     return;
        //   }
        // } else if (flagwadea) {
        //   if (!this.handleConfirmClick('您所选择的经销商存在贸易合规警示风险,是否继续申请修理,' + IFTradeComplianceAlert)) {
        //     return;
        //   }
        // }else{
        //   this.nextOnefunction();
        // }
                // sx 贸易合规2期 start
        if((flagwaacc || flagwadea) && this.ProTradeComplianceStatus == '0'){
          this.SendEmailFW(this.AccountName,this.recordId,'8',this.state,this.Asset_Model_No);
          if (!this.handleConfirmClick('您此次申请的业务可能存在贸易合规风险,是否继续申请,' + IFTradeComplianceAlert2 + '(一般需5-10个工作日)')) {
            return;
          } else{
            this.nextOnefunction();
          }
          // sx 贸易合规2期 end
        }else{
          this.nextOnefunction();
        }
      }else{
        this.nextOnefunction();
      }
    }else{
      this.nextOnefunction();
    }
 
    
  }
  // WYL 贸易合规2期 邮件 start
 async SendEmailFW (Hospital,recordId,type,state,Asset_Model_No){
    accSendEmailFW({
      accname:Hospital,
      mcid:recordId,
      type:type,
      state:state,
      Asset_Model_No:Asset_Model_No
      })
    .then(result=>{
      return;
    }).catch(err=>{
      console.log('邮件错误'+error);
    })
 }
  // WYL 贸易合规2期 邮件 end
  async nextOnefunction(){
 
    if (this.HPActiveC == '無効') {
      this.ShowToastEvent("本医院已无效,无法进行申请。", "error");
      this.dispatchEvent(new CloseActionScreenEvent());
      return;
    }
 
    console.log('queryForrecords3------------>>>',queryForrecords3);
    await queryForrecords3({
      dealer: this.dealer
    }).then(result => {
      console.log('queryForrecords3---result------------>>>',result);
      if (result.length > 0) {
        console.log('result[0].FirstParagraph__c------->>>>>>',result[0].FirstParagraph__c);
        if(result[0].FirstParagraph__c){
          if (!this.handleConfirmClick01("该经销商为先款对象,是否继续申请修理?")) {
            return;
          }
        }else{
          console.log('进入----------false>>>>>>>>>');
          this.thirdfunction();
        }
         //20231106  ymh  逻辑添加 end
      }else{
        this.thirdfunction();
      }
    }); 
 
  }
 
  async thirdfunction(){
    //全国直送流程整期方案 20230607 LY start
      console.log('设备,this.quickRepairSign,this.affiliationRC,this.onSiteRepair-------->>>>>>',this.quickRepairSign,this.affiliationRC,this.onSiteRepair);
      console.log('this.maintenanceContract,this.VMMaintenanceContract -------->>>>>>',this.maintenanceContract,this.VMMaintenanceContract);
      console.log( '判断-------->>>',this.quickRepairSign==false  && this.affiliationRC != 'SHRC' && (this.onSiteRepair == '直送SORC修理' || this.onSiteRepair == '直送OGZ修理') 
      && ((this.maintenanceContract != '' && this.maintenanceContract != null) || (this.VMMaintenanceContract != '' && this.VMMaintenanceContract != null)));
 
      if ( this.quickRepairSign == false && this.affiliationRC == 'SHRC' && this.onSiteRepair == 'RC修理') {
        if (!this.handleConfirmClick02("该设备选择RC修理,请确认是否继续进行?")) {
          return;
        }
      }else if (this.quickRepairSign == false && this.affiliationRC != 'SHRC' && this.onSiteRepair == 'RC修理' 
          && ((this.maintenanceContract != '' && this.maintenanceContract != null) || (this.VMMaintenanceContract != '' && this.VMMaintenanceContract != null))) {
        if (!this.handleConfirmClick02("该设备为维修合同或多年保修对象品,选择RC修理,请确认是否继续进行?")) {
          return;
        }
      }else if ( this.quickRepairSign == false  && this.affiliationRC != 'SHRC' 
      && (this.onSiteRepair == '直送SORC修理' || this.onSiteRepair == '直送OGZ修理') 
      && ((this.maintenanceContract == '' || this.maintenanceContract == null) && (this.VMMaintenanceContract == '' || this.VMMaintenanceContract == null))) { //20231107 ymh  修改判断条件
        if (!this.handleConfirmClick02("该设备为非维修合同或非多年保修对象品,选择直送工厂修理,请确认继续进行?")) {
          return;
        }
      }else{
        this.fourthfunction();
      }
  }
 
 
 
  async fourthfunction(){
    console.log(3);
    var today = new Date();
    today.setHours(0);
    var dateReceiptQuestions = Date.parse(this.dateReceiptQuestions);
    var dates = (today - dateReceiptQuestions) / (24 * 60 * 60 * 1000);
    if (this.profileName != this.administrator && this.userName != this.huyucheng && this.userName != this.liqiqing &&
      this.userName != this.guoyang && this.delayReportReason == undefined && dates > "1" && this.repairSource != "QIS转修理") {
      this.ShowToastEvent("申请修理时SAP修理申请日超过问题联络收到日1天,必须填写问超时报告的理由", "error");
      this.dispatchEvent(new CloseActionScreenEvent());
      return;
    }
    if (this.returnsProductway == undefined) {
      if (!this.handleConfirmClick03("返品方式为空,是否继续申请修理!")) {
        return;
      }
    }else{
      this.fifthfunction();
    }
   
  }
 
  async fifthfunction(){
    console.log(6);
    if (this.assetOwner != "Olympus") {
      if (this.DetailedAddress != undefined) {
        //deloitte-zhj 20231123 PIPL还原 start
        if (!this.handleConfirmClick04("当前直返收货地址为:" + this.DetailedAddress +",您确认不修改了吗?")) {
              return;
            }
          // //Deloitte-zhj PIPL解密 2023-08-23 start
        // let that = this;
        // // debugger;
        // this.AWSService.query(this.staticResorceRepair.queryUrl, this.AWSDataId, function (data) {
        //   console.log('queryLeadFromAWSIFS data = ',data);
        //   if (data.object) {
        //     that.DetailedAddress = data.object['detailedAddress'];
        //     if (!that.handleConfirmClick04("当前直返收货地址为:" + that.DetailedAddress +",您确认不修改了吗?")) {
        //       return;
        //     }
        //   }else{
        //     that.DetailedAddress = data.object['detailedAddress'];
        //     if (!that.handleConfirmClick04("当前直返收货地址为:" + that.DetailedAddress +",您确认不修改了吗?")) {
        //       return;
        //     }
        //   }
        // }, this.staticResorceRepair.token)
        // //Deloitte-zhj PIPL解密 2023-08-23 end
//deloitte-zhj 20231123 PIPL还原 end
      } else {
        this.ShowToastEvent('当前修理没有录入直返收货的详细地址,不能申请修理!', "error");
        this.dispatchEvent(new CloseActionScreenEvent());
        return;
      }
      
    } else {
      this.sixthfunction();
    }
  }
 
  async sixthfunction() {
    console.log(7);
    await queryForEquipments({
      deliveredProductId: this.deliveredProductId,
    }).then(equipments => {
      if (equipments != null && equipments.length > 0) {
        var equipment = equipments[0];
        if (equipment.Status == "廃棄") {
          this.ShowToastEvent("设备废弃,不能提交申请!", "error");
          this.dispatchEvent(new CloseActionScreenEvent());
          return;
        }else{
          this.sixthNextOnefunction();
        }
      }else{
        this.sixthNextOnefunction();
      }
    });
  }
 
  async sixthNextOnefunction(){
    console.log(701);
    if (this.FSEApplyForRepairTime != undefined) {
      this.ShowToastEvent("已修理申请,不再修理申请了", "error");
      this.dispatchEvent(new CloseActionScreenEvent());
      return;
    }
 
    console.log(702);
    //计算上限合同进行中的修理 LY 20230117 start
    if (this.limitPrice == true) {
      await CeilingContractRepair({ MaintenanceContractId: this.maintenanceContractId }).then(res => {
        console.log(res, '<===res')
        console.log('res.repairs.length----------->>>', res.repairs.length);
        console.log('res.repairs----------->>>', res.repairs);
        this.repairLength = res.repairs.length;
        console.log('this.repairLength----------->>>', this.repairLength);
        var remainingAmountM = 0;
        
        if(res.maintenanceContract[0].PackageFlag__c){
            remainingAmountM = res.maintenanceContract[0].Remaining_Amount_DB__c;
          }else {
            remainingAmountM = res.maintenanceContract[0].Remaining_Amount__c;
          }
        console.log('remainingAmountM----------->>>',remainingAmountM);
        console.log('this.repairLength----------->>>', this.repairLength);
        if (remainingAmountM <= 0) {
          if (!this.handleConfirmClick05("合同的上限金额已用完,当前修理为合同外修理,是否继续?")) {
            return;
          }
        }else if (this.repairLength > 1 && remainingAmountM <= 150000 && remainingAmountM > 0) {
          this.ShowToastEvent("该设备关联上限合同,目前修理剩余金额小于15万。请等待进行中修理完成后再进行申请", 'error');
          this.dispatchEvent(new CloseActionScreenEvent());
          return;
          //计算上限合同进行中的修理 LY 20230117 end
        }else{
          this.sevenfunction();
        }
      })
    }else{
      this.sevenfunction();
    }
  }
 
  async sevenfunction(){
    console.log(703);
    console.log('this.URFReapir-------->>>>>',this.URFReapir);
    if (this.URFReapir) {
      await queryForUrfAsset({
        maintenanceContractId: this.maintenanceContractId,
        deliveredProductId: this.deliveredProductId,
      }).then(urfAsset => {
        var seriesMaxRepairCount = 0;
        var seriesRepairCount = 0;
        if (urfAsset != null && urfAsset.length > 0) {
          seriesMaxRepairCount = urfAsset[0].Series_MaxRepairCount_F__c;
          seriesRepairCount = urfAsset[0].Series_RepairCount_F__c;
          this.surplusCount = seriesMaxRepairCount - seriesRepairCount;
        }
      });
      console.log(703);
 
      await queryForUrfSeriesInfo({
        URFLimitSerial: this.URFLimitSerial,
      }).then(urfSeriesInfo => {
        var urfSeries = "";
        if (urfSeriesInfo != null && urfSeriesInfo.length > 0) {
          urfSeries = urfSeriesInfo[0].URFLimitSerial__c;
          console.log(704);
          var statusList = new Array()
          statusList.push('00.申请完毕');
          statusList.push('01.分公司受理完毕');
          statusList.push('02.RC受理完毕');
          statusList.push('03.报价检查结束');
          statusList.push('04.报价跟进中');
          queryForRepairCount({
            maintenanceContractId: this.maintenanceContractId,
            status1: statusList,
            URFLimitSerial: urfSeries,
          }).then(repairCount => {
            if (repairCount.length > 1 && this.surplusCount == 1) {
              this.ShowToastEvent("该设备关联限次合同,目前剩余次数小于送修设备。请等待进行中修理完成后再进行申请", "error");
              this.dispatchEvent(new CloseActionScreenEvent());
              return;
            }else{
              this.sevenNextOnefunction();
            }
          });
        }else{
          this.sevenNextOnefunction();
        }
      });
    }else{
      this.sevenNextOnefunction();
    }
    
  }
 
  async sevenNextOnefunction(){
    console.log(705);
 
    if (this.status != "草案中" && this.status != "1.受理完毕(SAP待发送)" && this.status != "4.修理品返送阶段") {
      this.ShowToastEvent("不是草案中不能申请", "error");
      this.dispatchEvent(new CloseActionScreenEvent());
      return;
    } else {
      if (this.dealer != undefined) {
        await queryForFindInvalidLicense({
          dealerId: this.dealerId,
        }).then(findInvalidLicense => {
          console.log(findInvalidLicense);
          if (findInvalidLicense.length > 0) {
            this.ShowToastEvent("经销商三证不在有效期,无法送修", "error");
            this.dispatchEvent(new CloseActionScreenEvent());
            return;
          }else{
            this.eighthfunction();
          }
        });
      }else{
        this.eighthfunction();
      }
    }
  }
 
  async eighthfunction(){
    var flag = true;
    if (this.ifDeadHurt == "有") {
      if (!this.handleConfirmClick06("是否确认AE要提交?")) {
        // flag = false;
        return;
      }
    } else{
      this.ninthfunction();
    }
    
  }
  async ninthfunction(){
    if (this.dayLater30 == "是") {
      // flag = false;
      this.ShowToastEvent("创建后超过30天,不能申请了", "error");
      this.dispatchEvent(new CloseActionScreenEvent());
      return;
    }else{
      this.tenthfunction();
    }
  }
 
  async tenthfunction(){
    if (this.URFReapir == true && this.surplusCount <= 0) {
      if (!this.handleConfirmClick07("合同内大修次数已用完,当前修理为合同外的修理,是否继续?")) {
        // flag = false;
        return;
      }
    } else{
      this.elevenfunction();
    }
  }
 
  async elevenfunction() {
    console.log(9);
    console.log(901);
    await queryForReocrds({
      inchargeStaffId: this.inchargeStaffId,
    }).then(records => {
      if (records != null && records.length > 0) {
        var staff = records[0];
        console.log(staff);
        console.log(902);
        updateRepair2({
          recordId: this.Id,
          staff: staff,
          DWSign: this.DWSign,
          statusc: "1.受理完毕",
          DOJStatus: this.DOJStatus,
          SAPcondition: this.SAPcondition,
          maintenanceFlag:this.maintenanceFlag
        }).then(result => {
          console.log(result);
          console.log(903);
          if (result != '1' ) {
            console.log("updateRepair2----1"+result);
            this.ShowToastEvent(result, "error");
            this.dispatchEvent(new CloseActionScreenEvent());
            return;
          } else {
            if (this.salesOfficeCodeSelection == "成都RC") {
              this.ShowToastEvent("现阶段,成都RC仅受理四川(西藏)内镜、西南全域CV/CLV,其余实物请发至广州RC。", "error");
              this.dispatchEvent(new CloseActionScreenEvent());
              return;
            }
              window.open(this.url, "_self");
          }
          console.log(904);
          queryForRds({
            recordId: this.Id,
          }).then(rds => {
            console.log(rds);
            if (rds != null && rds.length > 0) {
              var repairAft = rds[0];
              if (repairAft.NewProductGuarante_Formula__c != repairAft.ProductGuarante_Create__c) {
                this.ShowToastEvent("该设备保修信息已发生变化,请了解", "error");
                this.dispatchEvent(new CloseActionScreenEvent());
                return;
              }
            }
          });
        }).catch(err=>{
          console.log("updateRepair2----2"+err);
          this.ShowToastEvent(err, "error");
          this.dispatchEvent(new CloseActionScreenEvent());
        });
      } else {
        this.ShowToastEvent("没有找到 修理委托者", "error");
        this.dispatchEvent(new CloseActionScreenEvent());
        return;
      }
    });
 
  }
 
  async handleConfirmClick(msg) {
    const result = await LightningConfirm.open({
      message: msg,
      variant: 'headerless',
      label: 'this is the aria-label value'
    });
    if (!result) {
      this.dispatchEvent(new CloseActionScreenEvent());
      return;
    }else{
      this.nextOnefunction();
    }
  }
 
  async handleConfirmClick01(msg) {
    const result = await LightningConfirm.open({
      message: msg,
      variant: 'headerless',
      label: 'this is the aria-label value'
    });
    if (!result) {
      this.dispatchEvent(new CloseActionScreenEvent());
      return;
    }
    this.thirdfunction();
    
  }
 
  async handleConfirmClick02(msg) {
    const result = await LightningConfirm.open({
      message: msg,
      variant: 'headerless',
    });
    if (!result) {
      this.dispatchEvent(new CloseActionScreenEvent());
      return;
    }
    this.fourthfunction();
  }
 
  async handleConfirmClick03(msg) {
    const result = await LightningConfirm.open({
      message: msg,
      variant: 'headerless',
      label: 'this is the aria-label value'
    });
    if (!result){
      this.dispatchEvent(new CloseActionScreenEvent());
      return;
    }
    this.fifthfunction();
  }
 
  async handleConfirmClick04(msg) {
    const result = await LightningConfirm.open({
      message: msg,
      variant: 'headerless',
      label: 'this is the aria-label value'
    });
    if (!result){
      this.dispatchEvent(new CloseActionScreenEvent());
      return;
    }
    this.sixthfunction();
  }
 
  async handleConfirmClick05(msg) {
    const result = await LightningConfirm.open({
      message: msg,
      variant: 'headerless',
      label: 'this is the aria-label value'
    });
    if (!result) {
      this.dispatchEvent(new CloseActionScreenEvent());
      return;
    }
    this.sevenfunction();
  }
 
  async handleConfirmClick06(msg) {
    const result = await LightningConfirm.open({
      message: msg,
      variant: 'headerless',
      label: 'this is the aria-label value'
    });
    if (!result) {
      this.dispatchEvent(new CloseActionScreenEvent());
      return;
    }else{
      this.ninthfunction();
    }
  }
 
  async handleConfirmClick07(msg) {
    const result = await LightningConfirm.open({
      message: msg,
      variant: 'headerless',
      label: 'this is the aria-label value'
    });
    if (!result) {
      this.dispatchEvent(new CloseActionScreenEvent());
      return;
    }else{
      this.maintenanceFlag = true;
      this.elevenfunction();
    }
  }
 
  async ShowToastEvent(msg, type) {
    if (type == 'success') {
      const event = new ShowToastEvent({
        message: msg,
        variant: type
      });
      this.dispatchEvent(event);
    } else {
      const event = new ShowToastEvent({
        message: msg,
        variant: type,
        mode: 'Sticky'
      });
      this.dispatchEvent(event);
    }
  }
 
  
}