/* * @Date: 2024-02-21 14:12:06 * @Author: @zyh * @LastEditTime: 2024-02-28 15:37:49 * @Descripttion: */ 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'; import lwcCSS from '@salesforce/resourceUrl/lwcCSS'; import {loadStyle} from 'lightning/platformResourceLoader'; const event1 = new ShowToastEvent({ message: "科室状态为无效,不允许新建OPD计划", variant : "error" , mode : 'sticky' }); import init from '@salesforce/apex/LexOPDSupplementaryController.initNewOPDButton'; export default class lexNewOPDButtonAccount extends NavigationMixin(LightningElement) { @api recordId; IsLoading=true; Account; @wire(CurrentPageReference) getStateParameters(currentPageReference) { debugger; if (currentPageReference) { const urlValue = currentPageReference.state.recordId; console.log('currentPageReference',currentPageReference); console.log('currentPageReference',currentPageReference.state); console.log('currentPageReference.attributes',currentPageReference.attributes.recordId); console.log('urlValue',urlValue); if (urlValue) { let str = `${urlValue}`; this.recordId = str; }else{ const urlValue = currentPageReference.attributes.recordId; if (urlValue) { let str = `${urlValue}`; this.recordId = str; } } } console.log(this.recordId); } connectedCallback(){ debugger; Promise.all([ loadStyle(this, lwcCSS) ]); debugger; init({recordId:this.recordId}).then(res=>{ debugger; if (res!=null) { debugger; this.Account=res; console.log(res); this.newOPDButtonAccount().then(res=>{ this.IsLoading=false; debugger; this.dispatchEvent(new CloseActionScreenEvent()); debugger; }); } else{ debugger; const eventInItError = new dispatchEvent({ message : '页面初始化错误,请联系管理员', variant : 'error', mode : 'sticky' }); debugger; 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 : '*' }); this.IsLoading=false; this.dispatchEvent(new CloseActionScreenEvent()); debugger; this[NavigationMixin.Navigate]({ type: 'standard__objectPage', attributes: { objectApiName: 'OPDPlan__c', actionName: 'new' }, state: { // nooverride: '1', defaultFieldValues: defaultValues, } }); } }