KKbes
2023-07-26 6be68288146f38a6e99e5237870aa0709c98ee60
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
import { LightningElement, track, wire,api } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { CurrentPageReference } from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
const event1 = new ShowToastEvent({
                    message:
                    "已经取消!",
                    variant : 'error'
});
const event3 = new ShowToastEvent({
                    message:
                    "必须输入取消理由",
                    variant : 'error'
});
import init  from '@salesforce/apex/LexSubmitCampaignController.initCancleService';
import submitApprovalRequest  from '@salesforce/apex/LexSubmitCampaignController.submitApprovalRequest';
import newAndUpdateCampaignCancle  from '@salesforce/apex/LexSubmitCampaignController.newAndUpdateCampaignCancle';
import cancleServiceNewAndUpdate  from '@salesforce/apex/LexSubmitCampaignController.cancleServiceNewAndUpdate';
export default class lexCancelInService extends LightningElement {
    @api recordId;
    IsLoading=true;
    Campaign;
 
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
        if (currentPageReference) {
          const urlValue = currentPageReference.state.recordId;
          if (urlValue) {
            let str = `${urlValue}`;
            this.recordId = str;
          }
        }
    }
 
    connectedCallback(){
        init({
            recordId: this.recordId
        }).then(result => {
            if (result != null) {
                this.Campaign = result;
                this.cancelInService().then(result=>{
                   this.IsLoading=false;
                this.dispatchEvent(new CloseActionScreenEvent());
            });
            }
        }).catch(error => {
            const eventInItError = new ShowToastEvent({
                   message:
                error.message,
                variant : 'error'
            });
            this.dispatchEvent(eventInItError);
        });
 
    }
 
    async cancelInService(){
        if (this.Campaign.Status == '取消') {
            this.dispatchEvent(event1);
            return;
        }
        if (this.Campaign.Status != '草案中' && this.Campaign.Status != '公开中') {
            const event2 = new dispatchEvent({
                message : this.Campaign.Status +"状态不能取消" ,
                variant : 'error'
            })
            this.dispatchEvent(event2);
            return;
        }
        if (this.Campaign.CancleReason__c == null || this.Campaign.CancleReason__c == '' || this.Campaign.CancleReason__c == undefined) {
            this.dispatchEvent(event3);
            return;
        }
        var IsCancelFromOpen = false;
        console.log(this.Campaign.Status);
        if (this.Campaign.Status == '公开中') {
            IsCancelFromOpen = true;
        }
        await cancleServiceNewAndUpdate({
        Id: this.Campaign.Id, Status : '取消申请中', IsCancelFromOpen : IsCancelFromOpen}).then(result1=>{
            if(result1 != 'success'){
            const event4 = new dispatchEvent({
                message : result1,
                variant : 'error'
            });
            this.dispatchEvent(event4);
        }
        });
        //开始审批流
        await  submitApprovalRequest({recordId : this.recordId}).then(result=>{
            if(result!=null){
                var theStatus ='';
                if(IsCancelFromOpen){
                    theStatus = '公开中';
                }
                else{
                    theStatus = '草案中'
                }
                newAndUpddateCampaign({campaignId : this.Campaign.Id , Status : theStatus}).then(result2=>{
                     if(result2!='success'){
                         const eventErroe3 = new ShowToastEvent({
                              message:
                               result2,
                               variant : 'error'
                        });
                        this.dispatchEvent(eventErroe3);    
                     }
 
                });
                const eventFail = new ShowToastEvent({
                            message:
                             result1,
                          variant : 'error'
                    });    
                this.dispatchEvent(eventFail);
            }
        });
        window.location.reload();
 
 
    }
 
}