import { LightningElement,wire,track,api} from 'lwc'; import { CurrentPageReference, NavigationMixin} from "lightning/navigation"; import { CloseActionScreenEvent } from 'lightning/actions'; import init from '@salesforce/apex/lexConsumApply_FromAccountCtl.init'; import fieldDefineApp from '@salesforce/apex/lexConsumApply_FromAccountCtl.fieldDefineApp'; import UserInfo_Owner from '@salesforce/apex/lexConsumApply_FromAccountCtl.UserInfo_Owner'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils'; import lwcCSS from '@salesforce/resourceUrl/lwcCSS'; import {loadStyle} from 'lightning/platformResourceLoader'; export default class LexConsumApply_FromAccount extends NavigationMixin(LightningElement) { @api recordId; IsLoading = true; @wire(CurrentPageReference) getStateParameters(currentPageReference) { console.log(111); console.log(currentPageReference); if (currentPageReference) { const urlValue = currentPageReference.state.recordId; if (urlValue) { let str = `${urlValue}`; console.log("str"); console.log(str); this.recordId = str; } } } connectedCallback(){ console.log(this.recordId); Promise.all([ loadStyle(this, lwcCSS) ]); init({ recordId: this.recordId }).then(result=>{ UserInfo_Owner({}).then(res=>{ if(res.isFormalStuff){ this.showToast('试用期内,不能申请','error'); return; }else{ fieldDefineApp({}).then(resp=>{ var fieldmap = new Map(); for (var i=0; i< resp.length; i++) { var record = resp[i]; fieldmap.set(record.QualifiedApiName,record.DurableId.toString().split('.')[1]); } }) .catch(e=>{console.log(e)}) const defaultValues = encodeDefaultFieldValues({ Hospital__c:result.hospitalName, Strategic_dept__c:result.departClass, Account__c:result.name, Name:'*', demo_purpose2__c:'OPD试用', Person_In_Charge__c:res.id, applyUser__c:res.id }); this[NavigationMixin.Navigate]({ type: 'standard__objectPage', attributes: { objectApiName: 'Consum_Apply__c', actionName: 'new' }, state:{ defaultFieldValues: defaultValues } }) } }) .catch(error => { console.log("error"); console.log(error); }) }) .catch(error => { console.log("error"); console.log(error); }).finally(() => { this.dispatchEvent(new CloseActionScreenEvent()); }); } showToast(msg,type) { if(type == "success"){ const event = new ShowToastEvent({ message: msg, variant: type }); this.dispatchEvent(event); }else{ const event = new ShowToastEvent({ message: msg, variant: type, mode:'sticky' }); this.dispatchEvent(event); } this.dispatchEvent(new CloseActionScreenEvent()); } }