import { LightningElement,api, track, wire } from 'lwc';
|
import {CurrentPageReference} from 'lightning/navigation';
|
import { CloseActionScreenEvent } from 'lightning/actions';
|
import getUserId from '@salesforce/apex/lexCustomSubmitController.getUserId';
|
import init from '@salesforce/apex/lexCustomSubmitController.initFromCustomSubmitButton';
|
import updateRaesc from '@salesforce/apex/lexCustomSubmitController.updateRaesc';
|
import selectRacById from '@salesforce/apex/lexCustomSubmitController.selectRacById';
|
import postponeCheck from '@salesforce/apex/lexCustomSubmitController.postponeCheck';
|
import submitApprovalRequest from '@salesforce/apex/lexCustomSubmitController.submitApprovalRequest';
|
|
import { loadScript } from 'lightning/platformResourceLoader';
|
import { submitForApproval } from 'lightning/uiRecordApi';
|
import { updateRecord } from 'lightning/uiRecordApi';
|
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
|
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
|
import {loadStyle} from 'lightning/platformResourceLoader';
|
export default class lexCustomSubmit extends LightningElement {
|
|
@api recordId;
|
id;
|
RentalApplyId;
|
Status;
|
IsLoading=true;
|
IsReload=false;
|
@wire(CurrentPageReference)
|
getStateParameters(currentPageReference){
|
console.log("进入页面");
|
console.log(currentPageReference);
|
if(currentPageReference){
|
const urvalue=currentPageReference.state.recordId;
|
if(urvalue){
|
let str=`${urvalue}`;
|
console.log('str');
|
console.log(str);
|
this.recordId=str;
|
}
|
}
|
}
|
|
|
|
connectedCallback(){
|
Promise.all([
|
loadStyle(this, lwcCSS)
|
]);
|
console.log(this.recordId);
|
init({recordId:this.recordId}).then(result=>{
|
console.log(result);
|
if(result!=null){
|
this.Rental_Apply_Equipment_Set__c=result;
|
this.cancelSubmit().then(res=>{
|
this.IsLoading=false;
|
this.dispatchEvent(new CloseActionScreenEvent());
|
});
|
}
|
}).catch(err=>{
|
console.log("error:");
|
console.log(err);
|
}).finally(()=>{
|
|
});
|
}
|
|
|
|
async cancelSubmit(){
|
console.log("hhh1");
|
if (this.Rental_Apply_Equipment_Set__c.Request_extend_day__c == ""
|
|| this.Rental_Apply_Equipment_Set__c.Request_extend_day__c == null
|
|| this.Rental_Apply_Equipment_Set__c.Extend_request_reason__c == ""
|
|| this.Rental_Apply_Equipment_Set__c.Extend_request_reason__c == null) {
|
// alert("必须填写延期希望结束日,延期申请理由");
|
this.showToast("必须填写延期希望结束日,延期申请理由",'warning');
|
return;
|
}
|
console.log("hhh2");
|
let rtn;
|
let d=-5;
|
await postponeCheck({
|
endDate:this.Rental_Apply_Equipment_Set__c.Rental_End_Date__c,
|
i:d
|
}).then(res=>{
|
console.log(res);
|
rtn=res;
|
}).catch(err=>{
|
console.log("err:",err.message);
|
});
|
|
console.log(rtn);
|
if (rtn != "OK") {
|
// alert(rtn);
|
|
this.showToast(rtn,'warning');
|
return;
|
}
|
console.log("hhh3");
|
let resultSet = await selectRacById({recordId:this.Rental_Apply_Equipment_Set__c.Rental_Apply__c})
|
;
|
let records = resultSet;
|
console.log("hhh4");
|
let result = await updateRaesc({
|
recordId:this.Rental_Apply_Equipment_Set__c.Id,
|
JingliApprovalManagerc:records[0].JingliApprovalManager__c,
|
BuchangApprovalManagerc:records[0].SalesManager__c,
|
BuchangApprovalManagerSalesc:records[0].BuchangApprovalManager__c,
|
ZongjianApprovalManagerc:records[0].BuchangApprovalManagerSales__c,
|
ExtendStatusc:'填写完毕',
|
});
|
console.log("hhh5");
|
console.log(result);
|
// let messages = getConnectDMLErrorMessages(result);
|
if(result!=null&&result.length>0&&result.errors.length>0){
|
// alert(result.errors[0].split(",")[1]);
|
this.showToast(result.errors[0].split(",")[1],'warning');
|
return;
|
}
|
console.log("hhh7");
|
|
await submitApprovalRequest({recordId:this.recordId}).then(res=>{
|
console.log(res);
|
if(res!=null&&res!=''){
|
this.showToast(res,'warning');
|
return;
|
}else{
|
const event = new ShowToastEvent({
|
title: '提示信息',
|
message:"更新成功"
|
});
|
this.showToast("更新成功",'success');
|
return;
|
}
|
})
|
|
}
|
updateRecordView(recordId){
|
updateRecord({fields:{Id:recordId}});
|
}
|
showToast(msg,type) {
|
|
if(type == 'success'){
|
const event = new ShowToastEvent({
|
message: msg,
|
variant: type
|
});
|
this.updateRecordView(this.recordId);
|
this.dispatchEvent(event);
|
this.dispatchEvent(new CloseActionScreenEvent());
|
}else{
|
const event = new ShowToastEvent({
|
message: msg,
|
variant: type,
|
mode: 'sticky'
|
});
|
this.dispatchEvent(event);
|
this.dispatchEvent(new CloseActionScreenEvent());
|
}
|
|
}
|
}
|