//author : kkbes add LexOPDPostPoneController import { LightningElement, track, wire,api } 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'; import init from '@salesforce/apex/LexOPDPostPoneController.init'; import findRecordId from '@salesforce/apex/LexOPDPostPoneController.findRecordId'; import changeTrade from '@salesforce/apex/OpdPlanWebService.changeTrade'; const event1 = new ShowToastEvent({ message: "OPD计划的状态为取消或完毕时,不能改期!", variant : 'error', mode :'sticky' }); const event2 = new ShowToastEvent({ message: "只有当OPD计划中的备品申请单无/草案/备品申请的出库指示为空时,才可以进行改期操作!", variant : 'error', mode :'sticky' }); export default class lexPostPoneReport extends NavigationMixin(LightningElement) { @api recordId; IsLoading=true; OPDPlan; RecordType; @wire(CurrentPageReference) getStateParameters(currentPageReference) { if (currentPageReference) { const urlValue = currentPageReference.state.recordId; if (urlValue) { let str = `${urlValue}`; this.recordId = str; } } } connectedCallback(){ Promise.all([ loadStyle(this, lwcCSS) ]); init({ recordId: this.recordId }).then(result => { if (result != null) { this.OPDPlan = result; this.PostPoneReport().then(result=>{ this.IsLoading=false; this.dispatchEvent(new CloseActionScreenEvent()); }); } }).catch(error => { const event3 = new ShowToastEvent({ message: error.message, variant : 'error', mode :'sticky' }); this.dispatchEvent(event3); }); } async PostPoneReport(){ var Status = this.OPDPlan.Status__c; if(Status == '取消' || Status == '完毕' ){ this.dispatchEvent(event1); return; } var opdplanid = this.OPDPlan.Id; var rtn =await changeTrade({opdplanId:opdplanid}) if (rtn != 'OK') { const event = new ShowToastEvent({ message: rtn, variant : 'error', mode :'sticky' }); this.dispatchEvent(event); return; } await findRecordId().then(result=>{ if(result!=null){ this.RecordType = result[0]; } else{ const eventIdIsNull = new ShowToastEvent({ message: '请及时联系管理员', variant : 'error', mode :'sticky' }); this.dispatchEvent(eventIdIsNull); } }).catch(error=>{ console.log(error.message); }); this.navigateToNewObjectPage(); } navigateToNewObjectPage() { this.IsLoading=false; this.dispatchEvent(new CloseActionScreenEvent()); const defaultFieldValues = encodeDefaultFieldValues({ CancelOPDPlan__c : this.OPDPlan.Id , Status__c : '延期报告' }) this[NavigationMixin.Navigate]({ type: 'standard__objectPage', attributes: { objectApiName: 'CancelPostponePlan__c', actionName: 'new' }, state: { nooverride: '1', defaultFieldValues: defaultFieldValues , recordTypeId : this.RecordType.Id } }); } }