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 lwcCSS from '@salesforce/resourceUrl/lwcCSS'; import {loadStyle} from 'lightning/platformResourceLoader'; import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils'; import init from'@salesforce/apex/LexOPDSupplementaryController.initReportSubmit'; import getRecordTypeByNameAndSobject from'@salesforce/apex/LexOPDSupplementaryController.getRecordTypeByNameAndSobject'; const event1 = new ShowToastEvent({ message: "OPD计划的状态为取消或完毕时,不能新建OPD报告!", variant : "error" , mode : 'sticky' }); const event2 = new ShowToastEvent({ message: "没有出库的申请不允许创建OPD报告!", variant : "error" , mode : 'sticky' }); export default class lexOPDReportSubmit extends NavigationMixin(LightningElement) { @api recordId; @api showElement = false; // @api showIsLoading=false; // IsLoading=true; OPDPlan; oppids; selectedRecordTypeId='3'; recordTypeId1; recordTypeId2; recordTypeId3; recordTypeId4; recordTypeId5; recordTypeId6; recordTypes = [ { label: 'NTC/TTC(不用)', value:'2'}, { label: 'OPD', value: '3'}, { label: 'SIS-ENG', value: '4' }, { label: 'SIS-ET', value: '5' }, { label: 'VOC', value: '6' }, { label: '售后服务跟台', value: '1'}, { label: '新品装机培训', value: '7'}, { label: '故障预防培训', value: '8'}, // 其他记录类型选项... ]; handleChange(event) { this.selectedRecordTypeId = event.detail.value; } @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(res=>{ // this.showIsLoading=true; console.log(this.recordId); this.OPDPlan=res; this.oppids=this.OPDPlan.Related_Opportunity1_ID__c console.log(this.oppids); console.log('123123123'); console.log(this.OPDPlan); this.reportSubmit().then(res=>{ console.log('123'); }).catch(error=>{ console.log(error); }); }) } async reportSubmit(){ var Status = this.OPDPlan.Status__c; if(Status == '取消' || Status == '完毕' ){ this.dispatchEvent(event1); this.dispatchEvent(new CloseActionScreenEvent()); return; } this.showElement = true; // this.showIsLoading=false; var status1=this.OPDPlan.Rental_Apply2_Status_New__c; var status2=this.OPDPlan.Rental_Apply1_Status_New__c; var status3=this.OPDPlan.Rental_Apply3_Status_New__c; var status4=this.OPDPlan.Rental_Apply4_Status_New__c; var status5=this.OPDPlan.Rental_Apply5_Status_New__c; if(status1 != "已出库" && status1 != "申请者已收货" && status1 != "医院已装机确认" && status1 != "已回寄" && status1 != "已回收" && status1 != "完了" && status1 != "欠品中" && status2 != "已出库" && status2 != "申请者已收货" && status2 != "医院已装机确认" && status2 != "已回寄" && status2 != "已回收" && status2 != "完了" && status2 != "欠品中" && status3 != "已出库" && status3 != "申请者已收货" && status3 != "医院已装机确认" && status3 != "已回寄" && status3 != "已回收" && status3 != "完了" && status3 != "欠品中" && status4 != "已出库" && status4 != "申请者已收货" && status4 != "医院已装机确认" && status4 != "已回寄" && status4 != "已回收" && status4 != "完了" && status4 != "欠品中" && status5 != "已出库" && status5 != "申请者已收货" && status5 != "医院已装机确认" && status5 != "已回寄" && status5 != "已回收" && status5 != "完了" && status5 != "欠品中"){ this.dispatchEvent(event2); this.dispatchEvent(new CloseActionScreenEvent()); return; } this.recordTypeId1 = await getRecordTypeByNameAndSobject({Name : '售后服务跟台',SobjectType : 'Report__c'}); this.recordTypeId2 = await getRecordTypeByNameAndSobject({Name : 'NTC/TTC(不用)',SobjectType : 'Report__c'}); this.recordTypeId3 = await getRecordTypeByNameAndSobject({Name : 'OPD',SobjectType : 'Report__c'}); this.recordTypeId4 = await getRecordTypeByNameAndSobject({Name : 'SIS-ENG',SobjectType : 'Report__c'}); this.recordTypeId5 = await getRecordTypeByNameAndSobject({Name : 'SIS-ET',SobjectType : 'Report__c'}); this.recordTypeId6 = await getRecordTypeByNameAndSobject({Name : 'VOC',SobjectType : 'Report__c'}); this.recordTypeId7 = await getRecordTypeByNameAndSobject({Name : '新品装机培训',SobjectType : 'Report__c'}); this.recordTypeId8 = await getRecordTypeByNameAndSobject({Name : '故障预防培训',SobjectType : 'Report__c'}); } doNotGoPage(){ this.dispatchEvent(new CloseActionScreenEvent()); } goPage(){ if(this.selectedRecordTypeId == '1'){ this.selectedRecordTypeId = this.recordTypeId1; } else if(this.selectedRecordTypeId == '2'){ this.selectedRecordTypeId = this.recordTypeId2; } else if(this.selectedRecordTypeId == '3'){ this.selectedRecordTypeId = this.recordTypeId3; } else if(this.selectedRecordTypeId == '4'){ this.selectedRecordTypeId = this.recordTypeId4; } else if(this.selectedRecordTypeId == '5'){ this.selectedRecordTypeId = this.recordTypeId5; } else if(this.selectedRecordTypeId == '6'){ this.selectedRecordTypeId = this.recordTypeId6; } else if(this.selectedRecordTypeId == '7'){ this.selectedRecordTypeId = this.recordTypeId7; } else if(this.selectedRecordTypeId == '8'){ this.selectedRecordTypeId = this.recordTypeId8; } if(""!=this.oppids && null!=this.oppids){ const defaultValues = encodeDefaultFieldValues({ Opportunity1__c: this.OPDPlan.Related_Opportunity1_ID__c, Opportunity2__c: this.OPDPlan.Related_Opportunity2_ID__c, Opportunity_Situation__c : '跟进询价' , Hospital_Department__c : this.OPDPlan.Account_Laboratory__c, Department_Class_Ref__c : this.OPDPlan.OCM_category_ID__c , Hospital_Reference__c : this.OPDPlan.HospitalID__c, Loaner_request_no1__c : this.OPDPlan.Rental_Apply2__c, Report_OPDPlan__c : this.OPDPlan.Id }); this[NavigationMixin.Navigate]({ type: 'standard__objectPage', attributes: { objectApiName: 'Report__c', actionName: 'new' }, state: { // nooverride: '1', defaultFieldValues: defaultValues, recordTypeId : this.selectedRecordTypeId } }); return; } var Activity_Type = this.OPDPlan.Activity_Type2__c; const defaultValues = encodeDefaultFieldValues({ Hospital_Department__c : this.OPDPlan.Account_Laboratory__c, Department_Class_Ref__c : this.OPDPlan.OCM_category_ID__c , Hospital_Reference__c : this.OPDPlan.HospitalID__c, Loaner_request_no1__c : this.OPDPlan.Rental_Apply2__c, Report_OPDPlan__c : this.OPDPlan.Id }); this[NavigationMixin.Navigate]({ type: 'standard__objectPage', attributes: { objectApiName: 'Report__c', actionName: 'new' }, state: { // nooverride: '1', defaultFieldValues: defaultValues , recordTypeId : this.selectedRecordTypeId } }); } }