import { LightningElement, track, wire,api } from 'lwc';
|
import { CurrentPageReference } from "lightning/navigation";
|
import { CloseActionScreenEvent } from 'lightning/actions';
|
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
|
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
|
import {loadStyle} from 'lightning/platformResourceLoader';
|
import submitApproval from '@salesforce/apex/LexUtils.submitApproval';
|
import getRecord from '@salesforce/apex/LexUtils.getRecord';
|
|
export default class lexadjustSubmitApproval extends LightningElement {
|
|
@api recordId;
|
IsLoading=true;
|
adjust;
|
|
@wire(CurrentPageReference)
|
getStateParameters(currentPageReference) {
|
if (currentPageReference) {
|
const urlValue = currentPageReference.state.recordId;
|
if (urlValue) {
|
let str = `${urlValue}`;
|
this.recordId = str;
|
console.log(this.recordId);
|
}
|
}
|
}
|
|
connectedCallback(){
|
Promise.all([
|
loadStyle(this, lwcCSS)
|
]);
|
this.submitApproval().then(res=>{
|
this.IsLoading=false;
|
this.dispatchEvent(new CloseActionScreenEvent());
|
});
|
}
|
async submitApproval(){
|
//提交前的check
|
this.adjust = await getRecord({recordId: this.recordId, objectApiName: 'PreProduct_StorageAdjust__c' });
|
if(this.adjust.AcceptStorage__c){
|
this.IsLoading=false;
|
this.dispatchEvent(new CloseActionScreenEvent());
|
this.dispatchEvent(
|
new ShowToastEvent({ title: '', message: '产品预留接收方所属本部为其他或市场本部时,不允许提交审批', variant: 'error', mode: 'sticky' }),
|
);
|
return;
|
}
|
if(this.adjust.GiveStorage__c){
|
this.IsLoading=false;
|
this.dispatchEvent(new CloseActionScreenEvent());
|
this.dispatchEvent(
|
new ShowToastEvent({ title: '', message: '产品预留调出方所属本部为其他或市场本部时,不允许提交审批', variant: 'error', mode: 'sticky' }),
|
);
|
return;
|
}
|
//后台方法提交审批
|
let mes = await submitApproval({recordId : this.recordId});
|
if(mes != 'OK'){
|
this.IsLoading=false;
|
this.dispatchEvent(new CloseActionScreenEvent());
|
this.dispatchEvent(
|
new ShowToastEvent({ title: '', message: mes, variant: 'error', mode: 'sticky' }),
|
);
|
console.log(mes);
|
return;
|
}
|
else{
|
this.IsLoading=false;
|
this.dispatchEvent(new CloseActionScreenEvent());
|
this.dispatchEvent(
|
new ShowToastEvent({ title: '', message:'提交审批成功', variant: 'success'}),
|
);
|
setTimeout(function() {
|
location.reload();
|
}, 2000);
|
return;
|
}
|
}
|
}
|