import { LightningElement, track, wire,api } from 'lwc';
|
import { CurrentPageReference } from "lightning/navigation";
|
import { CloseActionScreenEvent } from 'lightning/actions';
|
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
|
|
const event1 = new ShowToastEvent({
|
message:
|
"已经取消!",
|
variant : "error"
|
});
|
const event4 = new ShowToastEvent({
|
message:
|
"必须输入取消理由",
|
variant : "error"
|
});
|
const event5 = new ShowToastEvent({
|
message:
|
"该活动信息已发送到智慧医疗,请确认后再操作",
|
variant : "error"
|
});
|
const event6 = new ShowToastEvent({
|
message:
|
"已取消",
|
variant : "success"
|
});
|
|
|
import init from '@salesforce/apex/LexSubmitCampaignController.initCancle';
|
import changeCampaign from '@salesforce/apex/OpdPlanWebService.changeCampaign';
|
import submitApprovalRequest from '@salesforce/apex/LexSubmitCampaignController.submitApprovalRequest';
|
import newAndUpdateCampaignCancle from '@salesforce/apex/LexSubmitCampaignController.newAndUpdateCampaignCancle';
|
export default class lexCancleCampaign 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.cancle().then(result=>{
|
this.IsLoading=false;
|
this.dispatchEvent(new CloseActionScreenEvent());
|
});
|
}
|
}).catch(error => {
|
const eventInItError = new ShowToastEvent({
|
message:
|
error.message,
|
variant : 'error'
|
});
|
this.dispatchEvent(eventInItError);
|
});
|
|
}
|
|
|
async cancle(){
|
var checkUpdate=0;
|
if(this.Campaign.Status =='取消'){
|
this.dispatchEvent(event1);
|
return;
|
}
|
if(this.Campaign.Status !='草案中' && this.Campaign.Status !='公开中' && this.Campaign.Status !='取消'){
|
const event2 = new ShowToastEvent({
|
message : this.Campaign.Status +'状态不能取消',
|
variant : 'error'
|
});
|
this.dispatchEvent(event2);
|
return;
|
}
|
// OPD取消和备品取消检查
|
var campaignId= this.Campaign.Id;
|
var rtn = await changeCampaign({campaignId : campaignId });
|
if (rtn != 'OK') {
|
const event3 = new dispatchEvent({
|
message : rtn,
|
variant : 'error'
|
})
|
this.dispatchEvent(event3);
|
return;
|
}
|
if(this.Campaign.CancleReason__c == null || this.Campaign.CancleReason__c =='' || this.Campaign.CancleReason__c == undefined){
|
this.dispatchEvent(event4);
|
return;
|
}
|
if(this.Campaign.IF_Submit__c != 0){
|
this.dispatchEvent(event5);
|
}
|
// End
|
//状态不同的取消操作会不一样,公开中的学会
|
if(this.Campaign.Status =='草案中'){
|
await newAndUpdateCampaignCancle({campaignId : this.Campaign.Id, Status : '取消'}).then(result=>{
|
if(result=='success'){
|
this.dispatchEvent(event6);
|
location.href = "/"+this.Campaign.Id;
|
}
|
else{
|
const event7 = new ShowToastEvent({
|
message : result,
|
variant : 'error'
|
})
|
checkUpdate +=1;
|
this.dispatchEvent(event7);
|
}
|
});
|
}else if(this.Campaign.Status =='公开中'){
|
await newAndUpdateCampaignCancle({campaignId : this.Campaign.Id, Status : '取消申请中'}).then(result=>{
|
if(result!='success'){
|
const event8 = new ShowToastEvent({
|
message : result,
|
variant : 'error'
|
})
|
checkUpdate +=1;
|
this.dispatchEvent(event8);
|
}
|
});
|
if(checkUpdate!=0){
|
return;
|
}
|
await submitApprovalRequest({recordId : this.recordId}).then(result1=>{
|
console.log(result1);
|
if(result1!=null){
|
//更新状态
|
newAndUpddateCampaign({campaignId : this.Campaign.Id , Status : '公开中'}).then(result2=>{
|
if(result2!='success'){
|
const eventErroe3 = new ShowToastEvent({
|
message:
|
result2,
|
variant : 'error'
|
});
|
checkUpdate +=1;
|
this.dispatchEvent(eventErroe3);
|
}
|
});
|
if(checkUpdate!=0){
|
return;
|
}
|
const eventFail = new ShowToastEvent({
|
message:
|
result1,
|
variant : 'error'
|
});
|
checkUpdate +=1;
|
this.dispatchEvent(eventFail);
|
return;
|
}
|
});
|
if(checkUpdate!=0){
|
return;
|
}
|
window.location.reload();
|
}
|
|
}
|
|
|
}
|