import { LightningElement,api, track, wire } from 'lwc';
|
import {CurrentPageReference} from 'lightning/navigation';
|
import { CloseActionScreenEvent } from 'lightning/actions';
|
import getUserId from '@salesforce/apex/RentalApplyControllerLWT.getUserId';
|
import init from '@salesforce/apex/SelectSubstituteControllerLWT.initFromCustomSubmitButton';
|
import updateRaesc from '@salesforce/apex/SelectSubstituteControllerLWT.updateRaesc';
|
import selectRacById from '@salesforce/apex/SelectSubstituteControllerLWT.selectRacById';
|
import postponeCheck from '@salesforce/apex/SelectSubstituteControllerLWT.postponeCheck';
|
|
import { loadScript } from 'lightning/platformResourceLoader';
|
import { submitForApproval } from 'lightning/uiRecordApi';
|
import { updateRecord } from 'lightning/uiRecordApi';
|
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
|
export default class lexCustomSubmit extends LightningElement {
|
|
@api recordId;
|
id;
|
RentalApplyId;
|
Status;
|
IsLoading=true;
|
@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(){
|
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("必须填写延期希望结束日,延期申请理由");
|
const event = new ShowToastEvent({
|
title: '提示信息',
|
message:"必须填写延期希望结束日,延期申请理由"
|
});
|
this.dispatchEvent(event);
|
return;
|
}
|
console.log("hhh2");
|
let rtn;
|
await postponeCheck({
|
endDate:this.Rental_Apply_Equipment_Set__c.Rental_End_Date__c,
|
d:-5
|
}).then(res=>{
|
console.log(res);
|
rtn=res;
|
}).catch(err=>{
|
console.log("err:",err.message);
|
})
|
|
console.log(rtn);
|
if (rtn != "OK") {
|
// alert(rtn);
|
const event = new ShowToastEvent({
|
title: '提示信息',
|
message:rtn
|
});
|
this.dispatchEvent(event);
|
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]);
|
const event = new ShowToastEvent({
|
title: '提示信息',
|
message:result.errors[0].split(",")[1]
|
});
|
this.dispatchEvent(event);
|
}
|
console.log("hhh7");
|
|
// let request = new sforce.ProcessSubmitRequest();
|
// request.objectId = this.recordId;
|
// let processResults = sforce.connection.process([request]);
|
console.log("hhh8");
|
// submitForApproval(this.Rental_Apply_Equipment_Set__c.Id).then(result => {
|
// console.log(result);
|
// if (processResults[0].errors != null) {
|
// alert(processResults[0].errors.message);
|
// return;
|
// }
|
// console.log("hhh9");
|
// window.location.reload();
|
// })
|
// .catch(error => {
|
// console.error('Error submitting record for approval:', error.message);
|
// });
|
|
// await submitForApproval(this.recordId);
|
const fields = {}
|
const recordInput = { fields };
|
updateRecord({ fields: recordInput, recordId: this.recordId })
|
.then(() => {
|
console.log("更新成功");
|
})
|
.catch(error => {
|
console.log(error.message);
|
console.log(error);
|
// alert(error.body.message);
|
const event = new ShowToastEvent({
|
title: '提示信息',
|
message:error.body.message
|
});
|
this.dispatchEvent(event);
|
return;
|
// 处理异常情况
|
});
|
}
|
}
|