import { LightningElement,api, track, wire } from 'lwc'; import {CurrentPageReference} from 'lightning/navigation'; import { CloseActionScreenEvent } from 'lightning/actions'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import { NavigationMixin } from 'lightning/navigation'; import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils'; const event1 = new ShowToastEvent({ message: "科室状态为无效,不允许新建OPD计划", variant : "error" }); import init from '@salesforce/apex/LexOPDSupplementaryController.initNewOPDButton'; export default class lexNewOPDButtonAccount extends NavigationMixin(LightningElement) { @api recordId; IsLoading=true; Account; @wire(CurrentPageReference) getStateParameters(currentPageReference) { if (currentPageReference) { const urlValue = currentPageReference.state.recordId; if (urlValue) { let str = `${urlValue}`; this.recordId = str; } } } connectedCallback(){ init({recordId:this.recordId}).then(res=>{ if (res!=null) { this.Account=res; this.newOPDButtonAccount().then(res=>{ this.IsLoading=false; this.dispatchEvent(new CloseActionScreenEvent()); }); } else{ const eventInItError = new dispatchEvent({ message : '页面初始化错误,请联系管理员', variant : 'error' }); this.dispatchEvent(eventInItError); return; } }); } async newOPDButtonAccount(){ var AccLab_active=this.Account.Is_Active__c; if(AccLab_active =="無効"){ this.dispatchEvent(event1); return; } const defaultValues = encodeDefaultFieldValues({ Account_Laboratory__c: this.recordId, OPDType__c: '科室', Name : '*', retURL : '%2F' + this.recordId }); this.IsLoading=false; this.dispatchEvent(new CloseActionScreenEvent()); this[NavigationMixin.Navigate]({ type: 'standard__objectPage', attributes: { objectApiName: 'OPDPlan__c', actionName: 'new' }, state: { nooverride: '1', defaultFieldValues: defaultValues, } }); } }