import { LightningElement, track, wire,api } from 'lwc'; import { CurrentPageReference } from "lightning/navigation"; import { CloseActionScreenEvent } from 'lightning/actions'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import lwcCSS from '@salesforce/resourceUrl/lwcCSS'; import {loadStyle} from 'lightning/platformResourceLoader'; import { NavigationMixin } from 'lightning/navigation'; import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils'; import getRecord from '@salesforce/apex/LexUtils.getRecord'; export default class lexAdjustPreProductStock extends NavigationMixin(LightningElement) { @api recordId; IsLoading=true; PreProduct_Storage; @wire(CurrentPageReference) getStateParameters(currentPageReference) { if (currentPageReference) { const urlValue = currentPageReference.state.recordId; if (urlValue) { let str = `${urlValue}`; this.recordId = str; console.log(this.recordId); } } } connectedCallback(){ Promise.all([ loadStyle(this, lwcCSS) ]); this.adjustPreproduct().then(res=>{ this.IsLoading=false; this.dispatchEvent(new CloseActionScreenEvent()); }); } async adjustPreproduct(){ this.PreProduct_Storage = await getRecord({recordId: this.recordId, objectApiName: 'PreProduct_Storage__c' }); if(!this.PreProduct_Storage.ifValid__c){ this.IsLoading=false; this.dispatchEvent(new CloseActionScreenEvent()); this.dispatchEvent( new ShowToastEvent({ title: '', message: '此产品预留无效,不能申请数量调整', variant: 'error', mode: 'sticky' }), ); return; } if(this.PreProduct_Storage.Department__c ==='其他' || this.PreProduct_Storage.Department__c ==='市场'){ this.IsLoading=false; this.dispatchEvent(new CloseActionScreenEvent()); this.dispatchEvent( new ShowToastEvent({ title: '', message: '所属本部为其他或市场本部时,不允许创建调整申请', variant: 'error', mode: 'sticky' }), ); return; } const defaultValues = encodeDefaultFieldValues({ Status__c : '草案中', PreProduct_Storage__c : this.recordId }); this.IsLoading=false; this.dispatchEvent(new CloseActionScreenEvent()); this[NavigationMixin.Navigate]({ type: 'standard__objectPage', attributes: { objectApiName: 'PreProduct_StorageAdjust__c', actionName: 'new' }, state: { // nooverride: '1', defaultFieldValues: defaultValues, } }); } }