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(){ var checkUpdate=0; var Status =this.Campaign.Status; if (this.Campaign.Status == '取消') { this.dispatchEvent(event1); return; } if (this.Campaign.Status != '草案中' && this.Campaign.Status != '公开中') { const event2 = new ShowToastEvent({ message : 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' }); checkUpdate +=1; this.dispatchEvent(eventErroe3); } if(checkUpdate!=0){ return; } }); if(checkUpdate!=0){ return; } const eventFail = new ShowToastEvent({ message: result1, variant : 'error' }); checkUpdate +=1; this.dispatchEvent(eventFail); } }); if(checkUpdate!=0){ return; } window.location.reload(); } }