import { LightningElement,api, track, wire } from 'lwc'; import {CurrentPageReference} from 'lightning/navigation'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import UserInfo_Owner from '@salesforce/apex/NewAgencyContractController.UserInfo_Owner'; import { NavigationMixin } from 'lightning/navigation'; import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils'; import { CloseActionScreenEvent } from 'lightning/actions'; export default class LexNewAgencyContract extends NavigationMixin(LightningElement) { @api recordId; ProfileId; IsLoading=true; @wire(CurrentPageReference) getStateParameters(currentPageReference){ console.log("进入页面"); console.log(currentPageReference); if(currentPageReference){ const urvalue=currentPageReference.state.recordId; if(urvalue){ let str=`${urvalue}`; this.recordId=str; } } } connectedCallback(){ UserInfo_Owner().then(res => { console.log('result===>',res) if (res.id == '00510000002YSBIAA4' || res.profileId == '00e10000000Y3o5AAC') { this.showToast('会自动分配新建合同的客户编码,保留旧编码的时候请用复制合同。','success'); const defaultFieldValues = encodeDefaultFieldValues({ Agent_Ref__c:this.recordId, }); this[NavigationMixin.Navigate]({ type: 'standard__objectPage', attributes: { objectApiName: 'Account', actionName:'new' }, state:{ defaultFieldValues:defaultFieldValues, recordTypeId:res.recordTypeId } }); } else { this.showToast('没有新建的权限','error'); } }).catch(err => { console.log('err:',err) }) } showToast(msg,type) { const event = new ShowToastEvent({ message: msg, variant: type }); this.IsLoading = false; this.dispatchEvent(event); this.dispatchEvent(new CloseActionScreenEvent()); } }