import { LightningElement, track, wire, api } from 'lwc'; import { CurrentPageReference,NavigationMixin } from 'lightning/navigation'; import { CloseActionScreenEvent } from 'lightning/actions'; import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import { updateRecord } from 'lightning/uiRecordApi'; import init from '@salesforce/apex/LexNewTransferApplyController.init'; import getRecordId from '@salesforce/apex/LexNewTransferApplyController.getRecordId'; import lwcCSS from '@salesforce/resourceUrl/lwcCSS'; import {loadStyle} from 'lightning/platformResourceLoader'; export default class lexNewTransferApply extends NavigationMixin(LightningElement){ @api recordId; IsLoading = true; raId; raName; @wire(CurrentPageReference) getStateParameters(currentPageReference){ if(currentPageReference) { const urlValue = currentPageReference.state.recordId; if(urlValue) { let str = `${urlValue}`; this.recordId = str; } } } connectedCallback(){ Promise.all([ loadStyle(this,lwcCSS) ]); init({ recordId: this.recordId }).then(result =>{ this.raId = result.raId; this.raName = result.raName; let raDetailSet = result.rae; let IsCanCreateTransfer = false; if(raDetailSet.length > 0){ if(raDetailSet[0].Rental_Apply__r.RecordType.DeveloperName != 'AgencyRequest'){ this.showToast('此记录类型不支持新建调拨单','warning'); return; }else{ for(let i=0; i{ console.log('res===='+res); const defaultValues = encodeDefaultFieldValues({ Name: '*', Rental_Apply__c: this.recordId }); this[NavigationMixin.Navigate]({ type: 'standard__objectPage', attributes: { objectApiName: 'TransferApply__c', actionName: 'new', RecordType: res }, state:{ nooverride: '1',// 20230924 ljh add // defaultFieldValues: this.defaultValues defaultFieldValues: defaultValues // 20230924 ljh update } }) }) }else{ this.showToast('该申请没有符合条件的借出备品配套一览明细!','warning'); return; } } }else{ this.showToast('该申请没有符合条件的借出备品配套一览明细!','warning'); return; } }) .catch(err=>{ this.dispatchEvent(new CloseActionScreenEvent()); console.log('init==='+err); }) } 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()); } } updateRecordView(recordId) { updateRecord({fields: { Id: recordId }}); } }