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 submitApprovalRequest from '@salesforce/apex/SelectSubstituteControllerLWT.submitApprovalRequest'; 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; 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); 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); return; } console.log("hhh7"); await submitApprovalRequest({recordId:this.recordId}).then(res=>{ console.log(res); if(res!=null&&res!=''){ const event = new ShowToastEvent({ title: '提示信息', message:res }); this.dispatchEvent(event); return; }else{ const event = new ShowToastEvent({ title: '提示信息', message:"更新成功" }); this.dispatchEvent(event); return; } }) } }