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
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
import { LightningElement, api, track, wire } from "lwc";
import getApprovalHistory from "@salesforce/apex/ApprovalHistoryController.getApprovalHistory";
import submitForApprovalApex from "@salesforce/apex/ApprovalHistoryController.submitForApproval";
import reassignStep from "@salesforce/apex/ApprovalHistoryController.reassignStep";
import processStep from "@salesforce/apex/ApprovalHistoryController.processStep";
import searchUsers from "@salesforce/apex/ApprovalHistoryController.searchUsers";
// import saveRecord from "@salesforce/apex/ApprovalHistoryController.saveRecord";
import { CloseActionScreenEvent } from 'lightning/actions';
import getInitData from "@salesforce/apex/ApprovalHistoryController.getInitData";
import { getRecord } from 'lightning/uiRecordApi';
import ProfileId_SystemAdmin from '@salesforce/label/c.ProfileId_SystemAdmin';
import ProfileId_2J3 from '@salesforce/label/c.ProfileId_2J3';
import USER_ID from '@salesforce/user/Id';
import {
  verifyIfNextApproverWasNeeded,
  hideModal,
  showModal,
  getCommentPropertyFromModal,
  showGetNextApproverModal,
  validateUserLookup,
  setSelectedUser,
  clearModalState,
  displayToast,
  extractErrorMessage,
  modalStates,
  displayToastErrorQuery
} from "./approvalHistoryUtil.js";
import { ShowToastEvent } from "lightning/platformShowToastEvent";
import { refreshApex } from "@salesforce/apex";
 
const ERROR = "error";
const SUCCESS = "success";
const FIELDS = ['ObjectName__c.Id', 'ObjectName__c.Name'];
const columns = [
  {
    label: "步骤名称",
    fieldName: "stepName",
    type: "text",
    typeAttributes: {
      label: {
        fieldName: "stepName"
      }
    }
  },
  {
    label: "日期",
    fieldName: "createdDate",
    type: "date",
    typeAttributes: {
      month: "numeric",
      day: "numeric",
      year: "numeric",
      hour: "numeric",
      minute: "numeric"
    }
  },
  { label: "状态", fieldName: "stepStatus" },
  {
    label: "被分配人",
    fieldName: "OriginalToUrl",
    type: "url",
    typeAttributes: {
      label: {
        fieldName: "OriginalTo"
      }
    }
  },
  {
    label: "实际批准人",
    fieldName: "assignedToUrl",
    type: "url",
    typeAttributes: {
      label: {
        fieldName: "assignedTo"
      }
    }
  },
  { label: "评论", fieldName: "comments" },
];
export default class ApprovalHistory extends LightningElement {
  @api recordId;
  @track isLoading=false;
  @api objectApiName;
  @api showComments; //Determines if the component will show the comments column
  @api allowSubmitForApproval; //determines if the component will allow Submit for Approval functionality
  @track approvalHistory; //approval history to display on page
  @track isShow;//是否展示需要填写的表单
  wiredApprovalHistory; //property used to refreshApex
 
  //modal properties
  currentModalState; //decides which type of modal to display depending on the action happening(approve, reject, recall, etc)
  modalComment; //temporarily stores the value of the comment input field in the modal
  selectedUser; //temporarily stores the selected user from the lookup component in the modal
  //end modal properties
 
  //lookup properties
  lookupErrors = []; //errors related to the lookup component
  isMultiEntry = false;
  initialSelection = [];
  @track obj = {};
  fieldChange(event){
    const { value } = event.detail;
    const { fieldName } = event.target || event.currentTarget;
    let checked = event.target.value||event.currentTarget.value;
    if (value == undefined && checked != undefined) {
        this.obj = {
            ...this.obj,
            [fieldName]: checked
        };
    } else {
        let theValue = value instanceof Array ? value[0] : value;
        if(theValue===undefined){
            theValue = '';
        }
        this.obj = {
            ...this.obj,
            [fieldName]: theValue
        };
    }
    if(this.objectApiName==='Account'&&fieldName=='RejectionReason__c'){
      if(this.obj.RejectionReason__c==='重复'){
        this.AssociatedHospitalDis = false;
      }else{
        this.AssociatedHospitalDis = true;
      }
      if (this.isdealers) {
        this.RejectionReasonDis = true;
        this.AssociatedHospitalDis = true;
        this.InstitutionalTypeDis = true;
        this.HospitalTypeDis = true;
        this.WhetherRiskPassingDis = false;
      }else{
        this.WhetherRiskPassingDis = true;
      } 
    }
    if(this.objectApiName==='Account'&&fieldName=='InstitutionalType__c'){
      if(this.obj.InstitutionalType__c==='非医疗机构'){
        this.HospitalTypeDis = false;
      }else{
        this.HospitalTypeDis = true;
      }
      if (this.isdealers) {
        this.RejectionReasonDis = true;
        this.AssociatedHospitalDis = true;
        this.InstitutionalTypeDis = true;
        this.HospitalTypeDis = true;
        this.WhetherRiskPassingDis = false;
      }else{
        this.WhetherRiskPassingDis = true;
      } 
    }
    if(this.objectApiName==='Account_Delay_Apply__c'&&fieldName=='InstitutionalType__c'){
      if(this.obj.InstitutionalType__c==='非医疗机构'){
        this.HospitalTypeDis = false;
      }else{
        this.HospitalTypeDis = true;
      }
      if (this.isdealers) {
        this.WhetherRiskPassingDis = false;
      }else{
        this.WhetherRiskPassingDis = true;
      } 
    }
  }
  //end lookup properties
  get columns() {
    let tempColumns = columns;
    if(this.showComments){
      tempColumns.push({
        label: "Comments", fieldName: "comments" 
      });
    } 
 
    return tempColumns;
  }
  //url that will display all of the approval process history
  get viewAllUrl() {
    return "/lightning/r/" + this.recordId + "/related/ProcessSteps/view";
  }
  @track isAcc;
  @track isAccApply;
  @track isSolution=false;
  @track isadmin=false;
  @track isdealers;
  @track RejectionReasonDis = true;
  @track AssociatedHospitalDis = true;
  @track inputFieldStyle = 'display: block;';
  @track inputFieldStyleTwo = 'display: block;';
  @track inputFieldStyleThree = 'display: block;';
  @track inputFieldStyleFour = 'display: block;';
  @track InstitutionalTypeDis = true;
  @track HospitalTypeDis = true;
  @track WhetherRiskPassingDis = true;
  nodeName;
  connectedCallback(){
    console.log('connectedCallback');
    console.log(this.objectApiName);
    console.log(this.recordId);
    if(this.objectApiName==='Account'){
      //客户
      this.isAcc = true;
      this.isAccApply = false;
      this.isSolution = false;
    }else if(this.objectApiName==='Account_Delay_Apply__c'){
      //客户变更申请
      this.isAcc = false;
      this.isAccApply = true;
      this.isSolution = false;
    }else{
      //Solution方案 this.objectApiName==='Solution_Programme__c'
      this.isAcc = false;
      this.isAccApply = false;
      this.isSolution = true;
    }
    if(this.objectApiName==='Account'||this.objectApiName==='Account_Delay_Apply__c'||this.objectApiName==='Solution_Programme__c'){
      getInitData({ recordId: this.recordId,objectApiName:this.objectApiName})
      .then(result => {
          this.obj =  JSON.parse(result.objJson);
          // if(this.objectApiName==='Account'){
              console.log('handleUserInfo');
              var userProfileId = result.currentUserProfileId;
              this.nodeName = result.nodeName;
              console.log(this.nodeName + '<===this.nodeName');
              console.log('userProfileId = ' + userProfileId);
              console.log('ProfileId_SystemAdmin = ' + ProfileId_SystemAdmin);
              console.log('ProfileId_2J3 = ' + ProfileId_2J3);
              if(userProfileId===ProfileId_SystemAdmin){
                this.isadmin = true;
              }else{
                this.isadmin = false;
              }
              if(userProfileId===ProfileId_2J3){
                this.isdealers = true;
              }else{
                this.isdealers = false;
              }
              console.log(this.isadmin);
              console.log(this.isdealers);
              if(!this.isadmin && !this.isdealers) {
                console.log('双非锁定');
                this.RejectionReasonDis = true;
                this.AssociatedHospitalDis = true;
                this.InstitutionalTypeDis = true;
                this.HospitalTypeDis = true;
                this.WhetherRiskPassingDis = true;
              }else if(this.isadmin && !this.isdealers){
                console.log('测试执行');
                this.RejectionReasonDis = false;
                this.AssociatedHospitalDis = true;
                this.InstitutionalTypeDis = true;
                if (this.objectApiName==='Account_Delay_Apply__c') {
                    this.InstitutionalTypeDis = false;
                    this.HospitalTypeDis = true;
                    this.WhetherRiskPassingDis = true;
                }else{
                    this.InstitutionalTypeDis = true;
                    this.HospitalTypeDis = false;
                    this.WhetherRiskPassingDis = true;
                }
              }else if (this.isdealers) {
                this.RejectionReasonDis = false;
                this.AssociatedHospitalDis = true;
                
                if (this.objectApiName==='Account_Delay_Apply__c') {
                    this.InstitutionalTypeDis = true;
                    this.HospitalTypeDis = true;
                    this.WhetherRiskPassingDis = false;
                }else{
                    this.InstitutionalTypeDis = true;
                    this.HospitalTypeDis = false;
                    this.WhetherRiskPassingDis = false;
                }
 
              }
          // }
      }).catch(error => {
          console.error('Error loading report: ', error);
      });
    }
  }
  //decides if it will show the menu that may two buttons, the recall and the reassign 
  get showButtonMenu() {
    return (
      this.approvalHistory.isCurrentUserApprover ||
      this.approvalHistory.showRecall
    );
  }
 
  //decides if it will show the submit for approval button
  get showSubmitForApprovalButton() {
    return this.approvalHistory &&
      this.approvalHistory.showSubmitForApproval &&
      this.allowSubmitForApproval
      ? true
      : false;
  }
 
  //will return a different modal title depending on the state 
  get modalTitle() {
    if (this.currentModalState && modalStates[this.currentModalState])
      return modalStates[this.currentModalState].title;
    return "";
  }
  // will return a different label for the submit button, depending on the current state.(Approve, Reject, Submit, etc)
  get modalsubmitLabel() {
    if (this.currentModalState && modalStates[this.currentModalState])
      return modalStates[this.currentModalState].submitLabel;
    return "";
  } 
 
  // decides if the comment input field will show in the modal, based on the current state
  get showCommentModal() {
    return (
      this.currentModalState === modalStates.SUBMIT_APPROVAL.state ||
      this.currentModalState === modalStates.APPROVE.state ||
      this.currentModalState === modalStates.REJECT.state ||
      this.currentModalState === modalStates.RECALL.state
    );
  }
 
  // decides if the lookup component will show in the modal, based on the current state
  get showLookupModal() {
    return (
      this.currentModalState === modalStates.GET_NEXT_APPROVER_SUBMIT.state ||
      this.currentModalState === modalStates.REASSIGN.state ||
      this.currentModalState === modalStates.GET_NEXT_APPROVER_APPROVE.state
    );
  }
 
  // decides the label for the lookup component, based on the current state
  get lookupLabel() {
    return modalStates[this.currentModalState].lookupLabel;
  }
 
  get showDataTable() {
    return this.approvalHistory && this.approvalHistory.approvalSteps.length > 0
      ? true
      : false;
  }
 
  @wire(getApprovalHistory, { recordId: "$recordId" })
  wiredGetApprovalHist(value) {
    this.wiredApprovalHistory = value;
    if (value.data) {
      this.approvalHistory = value.data;
      console.log('wiredGetApprovalHist');
      console.log(JSON.stringify(this.approvalHistory));
    } else if (value.error) {
      displayToastErrorQuery(this, ShowToastEvent);
    }
  }
 
  refreshApprovalHistory() {
    console.log('refreshApprovalHistory');
    refreshApex(this.wiredApprovalHistory);
    console.log('/lightning/r/'+this.objectApiName+'/'+this.recordId+'/view');
    window.location.href = '/lightning/r/'+this.objectApiName+'/'+this.recordId+'/view';
  }
 
  @api
  submitForApproval(){
    this.handleSubmitForApprovalClick();
  }
  //button click handlers
  //the handlers show the modal and change the currentModalState depending on the button clicked
 
  handleSubmitForApprovalClick() {
    console.log('handleSubmitForApprovalClick');
    showModal(this);
    this.currentModalState = modalStates.SUBMIT_APPROVAL.state;
  }
 
  handleReassignClick() {
    showModal(this);
    this.isShow = false;
    this.currentModalState = modalStates.REASSIGN.state;
  }
 
  handleRecallClick() {
    showModal(this);
    this.isShow = false;
    this.currentModalState = modalStates.RECALL.state;
  }
handleApproveClick1() {
  this.isLoading=true;
}
  handleApproveClick() {
    this.inputFieldStyle ='display: none;';
    this.inputFieldStyleTwo = 'display: block;';
    // this.inputFieldStyleThree = 'display: none;';
    // this.inputFieldStyleFour = 'display: block;';
    if(this.objectApiName==='Account'){
      var InsType = this.obj.InstitutionalType__c;
      if (this.nodeName.indexOf('医院新建审批_事业推进部')!=-1) {
        this.RejectionReasonDis = false;
        this.InstitutionalTypeDis = false;
        console.log('InsType='+InsType);
        if(InsType=== '非医疗机构'){
          this.HospitalTypeDis = false;
        }else{
          this.HospitalTypeDis = true;
        }
      }
      if (this.isdealers) {
        this.RejectionReasonDis = true;
        this.AssociatedHospitalDis = true;
        this.InstitutionalTypeDis = true;
        this.HospitalTypeDis = true;
        this.WhetherRiskPassingDis = false;
      }else{
        this.WhetherRiskPassingDis = true;
      }
      
    }
    if(this.objectApiName==='Account_Delay_Apply__c'){
      var InsType = this.obj.InstitutionalType__c;
      console.log('InsType='+InsType);
      if (this.nodeName.indexOf('医院变更审批_事业推进部')!=-1) {
        if(InsType== '非医疗机构'){
          this.HospitalTypeDis = false;
        }else{
          this.HospitalTypeDis = true;
        }
        if (this.isdealers) {
          this.WhetherRiskPassingDis = false;
        }else{
          this.WhetherRiskPassingDis = true;
        }
      }
    }
 
    showModal(this);
    this.isShow = true;
    this.currentModalState = modalStates.APPROVE.state;
 
  }
 
  handleRejectClick() {
    this.inputFieldStyle = 'display: block;';
    this.inputFieldStyleTwo = 'display: none;';
    // this.inputFieldStyleThree = 'display: block;';
    // this.inputFieldStyleFour = 'display: none;';
    if(this.objectApiName==='Account'){
      
      if (this.nodeName.indexOf('医院新建审批_事业推进部')!=-1) {
        this.InstitutionalTypeDis = false;
        var InsType = this.InstitutionalTypeDis;
        if(InsType=== '非医疗机构'){
          this.HospitalTypeDis = false;
        }else{
          this.HospitalTypeDis = true;
        }
        if (this.isdealers) {
          this.RejectionReasonDis = true;
          this.AssociatedHospitalDis = true;
          this.InstitutionalTypeDis = true;
          this.HospitalTypeDis = true;
          this.WhetherRiskPassingDis = false;
        }else{
          this.WhetherRiskPassingDis = true;
        }
      }
    }
 
    if(this.objectApiName==='Account_Delay_Apply__c'){
      if (this.nodeName.indexOf('医院变更审批_事业推进部')!=-1) {
        var InsType = this.obj.InstitutionalType__c;
          if(InsType=== '非医疗机构'){
            this.HospitalTypeDis = false;
          }else{
            this.HospitalTypeDis = true;
          }
        if (this.isdealers) {
          this.WhetherRiskPassingDis = false;
        }else{
          this.WhetherRiskPassingDis = true;
        }
      }
    }
    showModal(this);
    this.isShow = true;
    this.currentModalState = modalStates.REJECT.state;
  }
  //end button click handlers
 
  //this function submits for approval, if a next approver is needed, 
  //it will show the next approver modal which will trigger the submition again.
  submitForApprovalApexCall() {
    hideModal(this);
    this.isLoading=true;
    submitForApprovalApex({
      recordId: this.recordId,
      comments: this.modalComment,
      nextApproverId: this.selectedUser
    })
      .then(result => {
 
        let jsonResult = JSON.parse(result);
        if (jsonResult.success) {
          displayToast(this, ShowToastEvent, SUCCESS);
          this.refreshApprovalHistory();
        } else {
          displayToast(this, ShowToastEvent, ERROR);
        }
        clearModalState(this);
      })
      .catch(error => {
        if (verifyIfNextApproverWasNeeded(error.body.pageErrors)) {
          showGetNextApproverModal(this, modalStates.GET_NEXT_APPROVER_SUBMIT.state);
        } else {
          let errorMessage = extractErrorMessage(error.body.pageErrors);
          displayToast(this, ShowToastEvent, ERROR, errorMessage);
          clearModalState(this);
        }
      });
  }
 
  //function that takes care of reassigning the pending step to the selected user.
  reassignApexCall() {
    hideModal(this);
    reassignStep({ recordId: this.recordId, newActorId: this.selectedUser })
      .then(() => {
        displayToast(this, ShowToastEvent, SUCCESS);
        clearModalState(this);
        this.refreshApprovalHistory();
      })
      .catch(() => {
        displayToast(this, ShowToastEvent, ERROR);
        clearModalState(this);
      });
  }
 
  //function that takes care of approve, reject, and recall. If next approver is needed
  //it will show the next approver modal which will trigger the submition again.
  processStepApexCall(action) {
    console.log('processStepApexCall');
    hideModal(this);
    this.isLoading=true;
    processStep({
      recordId: this.recordId,
      comments: this.modalComment,
      nextApproverId: this.selectedUser,
      action: action,
      objApiName:this.objectApiName,
      modalsubmitLabel:this.modalsubmitLabel,
      objJson:JSON.stringify(this.obj)
    })
      .then(result => {
        console.log('then');
        console.log(result);
        let jsonResult = JSON.parse(result);
        console.log(jsonResult);
        console.log(jsonResult.success);
        if (jsonResult.success) {
          // displayToast(this, ShowToastEvent, SUCCESS);
          this.isLoading=false;
          if (this.modalsubmitLabel=='批准') {
            this.showToast('success','批准完成');
          }else{
            this.showToast('success','驳回完成');
          }
          
          setTimeout(() => {
                this.refreshApprovalHistory();
            }, 3000); 
          
        } else {
          if(jsonResult.returnMes){
            this.showToast('error',jsonResult.returnMes);
              // window.location.href = '/lightning/r/'+this.objectApiName+'/'+this.recordId+'/view';
             setTimeout(() => {
                window.location.href = '/lightning/r/' + this.objectApiName + '/' + this.recordId + '/view';
            }, 3000);   
          }else{
            displayToast(this, ShowToastEvent, ERROR);
              // window.location.href = '/lightning/r/'+this.objectApiName+'/'+this.recordId+'/view';
            setTimeout(() => {
                window.location.href = '/lightning/r/' + this.objectApiName + '/' + this.recordId + '/view';
            }, 3000); 
          }
        }
        clearModalState(this);
      })
      .catch(error => {
        console.log('error');
        if (verifyIfNextApproverWasNeeded(error.body.pageErrors)) {
          showGetNextApproverModal(this, modalStates.GET_NEXT_APPROVER_APPROVE.state);
        } else {
          let errorMessage = extractErrorMessage(error.body.pageErrors);
          displayToast(this, ShowToastEvent, ERROR, errorMessage);
          clearModalState(this);
          setTimeout(() => {
                window.location.href = '/lightning/r/' + this.objectApiName + '/' + this.recordId + '/view';
            }, 3000); 
          // window.location.href = '/lightning/r/'+this.objectApiName+'/'+this.recordId+'/view';
        }
      });
  }
 
  handleModalCancel() {
    hideModal(this);
    clearModalState(this);
  }
 
  //function that handles the modal Submit button.
  //depending on the current state, it will call the appropriate imperative method
  handleModalSubmit() {
    
    if(this.isShow&&(this.isAcc||this.isAccApply||this.isSolution)){
      //先提交其他字段的填写
      var today = new Date();
      console.log('------------');
      console.log(this.objectApiName);
      console.log(this.recordId);
      console.log(this.isSolution);
      console.log(this.modalsubmitLabel);
      console.log(this.currentModalState);
      console.log(JSON.stringify(this.obj));
      // return;
      // if(this.isAcc){
      //   if(this.modalsubmitLabel === '批准' || this.modalsubmitLabel === '拒绝'){
      //     //== '步骤:医院新建审批_营业支援部(等待处理的 首先 批准)'
      //     if(testlink.contains('医院新建审批_营业支援部') ){
      //         if(this.modalsubmitLabel === '批准'){
      //             if(!this.stringIsEmpty(this.obj.RejectionReason__c)){
      //                 this.showToast('error', '您已填写驳回理由,批准不需要驳回理由。');
      //                 hideModal(this);
      //                 return;
      //             }
      //             if(this.stringIsEmpty(this.obj.InstitutionalType__c)){
      //                 this.showToast('error', '批准前,机构类型必填。');
      //                 hideModal(this);
      //                 return;
      //             }
      //             if(this.obj.InstitutionalType__c === '非医疗机构' && this.stringIsEmpty(this.obj.HospitalType__c)){
      //                 this.showToast('error', '非医疗机构请选择医院类型。');
      //                 hideModal(this);
      //                 return;
      //             }
      //             if(this.obj.InstitutionalType__c === '医疗机构' && !this.stringIsEmpty(this.obj.HospitalType__c)){
      //                 this.showToast('error', '医疗机构不需要选择医院类型。');
      //                 hideModal(this);
      //                 return;
      //             }
      //             if(this.obj.InstitutionalType__c === '医疗机构'){
      //                 this.obj = {
      //                   ...this.obj,
      //                   ['Is_Active__c']: '有効'
      //                 };
      //                 this.obj = {
      //                   ...this.obj,
      //                   ['Approved_Confirm_Date__c']: today
      //                 };
      //             }
      //         }
      //         //拒绝
      //         if(this.modalsubmitLabel === '拒绝'){
      //             if(this.stringIsEmpty(this.obj.RejectionReason__c)){
      //                 this.showToast('error', '拒绝前,请选择驳回理由。');
      //                 hideModal(this);
      //                 return;
      //             }
      //             if(this.obj.RejectionReason__c === '重复' && this.stringIsEmpty(this.obj.AssociatedHospital__c)){
      //                 this.showToast('error', '驳回理由是重复的,请填写关联医院。');
      //                 hideModal(this);
      //                 return;
      //             }
      //             if(this.obj.RejectionReason__c !== '重复' && !this.stringIsEmpty(this.obj.AssociatedHospital__c)){
      //                 this.showToast('error', '驳回理由不是重复的,不能填写关联医院。');
      //                 hideModal(this);
      //                 return;
      //             }
      //             if(!this.stringIsEmpty(this.obj.RejectionReason__c) && (!this.stringIsEmpty(this.obj.InstitutionalType__c)||!this.stringIsEmpty(this.obj.HospitalType__c))){
      //                 this.showToast('error', '审批拒绝,不允许填写机构类型或医院类型。');
      //                 hideModal(this);
      //                 return;
      //             }
      //             if(this.obj.RejectionReason__c === '医院已关张' || this.obj.RejectionReason__c === '重复'){
      //                 this.obj = {
      //                   ...this.obj,
      //                   ['Is_Active__c']: '驳回'
      //                 };
      //             }else{
      //                 this.obj = {
      //                   ...this.obj,
      //                   ['Is_Active__c']: '草案中'
      //                 };
      //             }
      //         }
      //     }else if(testlink.contains('质量法规二级部长') ){
      //         if(this.modalsubmitLabel === '批准'){
      //            if(this.obj.InstitutionalType__c === '非医疗机构' && this.obj.HospitalType__c === '高等院校'){
      //               this.obj = {
      //                 ...this.obj,
      //                 ['Is_Active__c']: '有効'
      //               };
      //               this.obj = {
      //                 ...this.obj,
      //                 ['Approved_Confirm_Date__c']: today
      //               };
      //            }
      //         }
      //         if(this.modalsubmitLabel === '拒绝'){
      //             this.obj = {
      //               ...this.obj,
      //               ['Is_Active__c']: '驳回'
      //             };
      //          }     
      //      }else if(testlink.contains('经销商管理部一级审批')){
      //         if(this.modalsubmitLabel === '批准'){
      //             if(this.stringIsEmpty(this.obj.WhetherRiskPassing__c)){
      //                 this.showToast('error', '是否为有风险通过 必填。');
      //                 hideModal(this);
      //                 return;
      //             }
      //            if(this.obj.InstitutionalType__c === '非医疗机构' && this.obj.HospitalType__c === '企业集团' && this.obj.WhetherRiskPassing__c === '否'){
      //               this.obj = {
      //                 ...this.obj,
      //                 ['Is_Active__c']: '有効'
      //               };
      //               this.obj = {
      //                 ...this.obj,
      //                 ['Approved_Confirm_Date__c']: today
      //               };
      //            }
      //         }
      //          if(this.modalsubmitLabel == '拒绝'){
      //             this.obj = {
      //               ...this.obj,
      //               ['Is_Active__c']: '驳回'
      //             };
      //          } 
  
      //     }else if(testlink.contains('总经理审批')){
      //         if(this.modalsubmitLabel === '批准'){
      //             this.obj = {
      //               ...this.obj,
      //               ['Is_Active__c']: '有効'
      //             };
      //             this.obj = {
      //               ...this.obj,
      //               ['Approved_Confirm_Date__c']: today
      //             };
      //         }
      //         if(this.modalsubmitLabel === '拒绝'){
      //             this.obj = {
      //               ...this.obj,
      //               ['Is_Active__c']: '驳回'
      //             };
      //         } 
      //     }else{
      //         if(this.modalsubmitLabel === '拒绝'){
      //             this.obj = {
      //               ...this.obj,
      //               ['Is_Active__c']: '驳回'
      //             };
      //          }   
      //     }
      //  }
      // }
      if(this.isSolution){
        if(this.obj.Confirmation_Result__c){
        }else{
          this.showToast('error', '必须填写反馈结果!');
          hideModal(this);
          return;
        }
      }
      // this.handleSubmit();
      // saveRecord({objectApiName:this.objectApiName,objId:this.recordId,objJson:JSON.stringify(this.obj)})
      //     .then(result => {
            this.handleSubmit();
      //       hideModal(this);
      //       return;
      //     })
      //     .catch(error => {
      //       hideModal(this);
      //       this.showToast('error', error);
      //       return;
      //     });
    }else{
      this.handleSubmit();
    }
  }
  showToast(variant,mes) {
    const event = new ShowToastEvent({
        message: mes,
        variant: variant,
    });
    this.dispatchEvent(event);
    this.dispatchEvent(new CloseActionScreenEvent());
    return;
  }
  handleSubmit(){
    console.log('handleSubmit');
    switch (this.currentModalState) {
      case modalStates.SUBMIT_APPROVAL.state:
        this.modalComment = getCommentPropertyFromModal(this);
        this.submitForApprovalApexCall();
        break;
      case modalStates.GET_NEXT_APPROVER_SUBMIT.state:
        if (validateUserLookup(this)) {
          setSelectedUser(this);
          this.submitForApprovalApexCall();
        }
        break;
      case modalStates.REASSIGN.state:
        if (validateUserLookup(this)) {
          setSelectedUser(this);
          this.reassignApexCall();
        }
        break;
      case modalStates.APPROVE.state:
        this.modalComment = getCommentPropertyFromModal(this);
        this.processStepApexCall(modalStates.APPROVE.action);
        break;
      case modalStates.GET_NEXT_APPROVER_APPROVE.state:
        if (validateUserLookup(this)) {
          setSelectedUser(this);
          this.processStepApexCall(modalStates.APPROVE.action);
        }
        break;
      case modalStates.RECALL.state:
        this.modalComment = getCommentPropertyFromModal(this);
        this.processStepApexCall(modalStates.RECALL.action);
        break;
      case modalStates.REJECT.state:
        console.log('1');
        this.modalComment = getCommentPropertyFromModal(this);
        console.log('2');
        this.processStepApexCall(modalStates.REJECT.action);
        console.log('3');
        break;
      default:
        break;
    }
  }
  //searches the users based on the lookup component search event.
  handleLookupSearch(event) {
    searchUsers(event.detail)
      .then(results => {
        this.template.querySelector("c-lookup").setSearchResults(results);
      })
      .catch(error => {
        this.lookupErrors = [error];
      });
  }
 
  handleSelectionChange() {
    this.lookupErrors = [];
  }
  stringIsEmpty(str) {
    if (str === '' || str === undefined || str === null) {
        return true;
    } else {
        return false;
    }
  }
}