import { LightningElement, wire, api } from 'lwc'; import { CurrentPageReference } from "lightning/navigation"; import { CloseActionScreenEvent } from 'lightning/actions'; import init from '@salesforce/apex/buttonAccountCtl.init'; import initUserName from '@salesforce/apex/buttonAccountCtl.initUserName'; import selecctAccountByAccountId from '@salesforce/apex/buttonAccountCtl.selecctAccountByAccountId'; import { NavigationMixin } from 'lightning/navigation'; import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils'; export default class LexCreateRepairFromDepartment extends NavigationMixin(LightningElement) { @api recordId; str; IsLoading = true; Id; RepairSalesPointProvinceChinaC; HospitalC; HospitalId; DepartmentClassC; DepartmentClassId; Name; userID; @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(result => { console.log(result); if (result != null) { this.Id = result.Id; this.HospitalC = result.HospitalC == undefined ? "" : result.HospitalC;; this.HospitalId = result.HospitalId == undefined ? "" : result.HospitalId;; this.DepartmentClassC = result.DepartmentClassC == undefined ? "" : result.DepartmentClassC;; this.DepartmentClassId = result.DepartmentClassId == undefined ? "" : result.DepartmentClassId;; this.Name = result.Name; this.userID = result.userID; console.log('result.userID1111111'+result.userID); console.log('userID11111111111'+JSON.stringify(result)); initUserName({ userId: this.userID }).then(res => { console.log('result11111111111'+JSON.stringify(res));`` if (res[0].RepairSalesPoint_Province_China__c != null) { this.RepairSalesPointProvinceChinaC = res[0].RepairSalesPoint_Province_China__c; } this.CreateRepairFromDepartment(); }) } }).catch(error => { console.log(error); }) } //新建修理 CreateRepairFromDepartment() { var RecordTypeName; var Incharge_Staff = ''; var Incharge_Staff_id = ''; var Work_Location = ''; var FSE_GI_Main_Leader__id = ''; var FSE_GI_Main_Leader__name = ''; var FSE_SP_Main_Leader__id = ''; var FSE_SP_Main_Leader__name = ''; selecctAccountByAccountId({ AccountId: this.Id }).then(List => { console.log('科室查询--------->>>>>>>>>',List); if (List[0]['ParentId'] != null) { RecordTypeName = List[0]['Parent']['RecordType_DeveloperName__c']; console.log('RecordType_DeveloperName__c-------->>>>>',List[0]['Parent']['RecordType_DeveloperName__c']); // RecordTypeId = List[0]['Parent']['RecordType_DeveloperName__c'].substring(0, 15); if (List[0]['Parent']['Parent']['FSE_GI_Main_Leader__c'] != null) { FSE_GI_Main_Leader__id = List[0]['Parent']['Parent']['FSE_GI_Main_Leader__c'].substring(0, 15); FSE_GI_Main_Leader__name = List[0]['Parent']['Parent']['FSE_GI_Main_Leader__r']['Name']; } if (List[0]['Parent']['Parent']['FSE_SP_Main_Leader__c'] != null) { FSE_SP_Main_Leader__id = List[0]['Parent']['Parent']['FSE_SP_Main_Leader__c'].substring(0, 15); FSE_SP_Main_Leader__name = List[0]['Parent']['Parent']['FSE_SP_Main_Leader__r']['Name']; } if (RecordTypeName != null || RecordTypeName != undefined) { // var recordId = List[0]['Parent']['RecordType_DeveloperName__c'].substring(0, 15); if (RecordTypeName == 'Department_Class_GI' || RecordTypeName == 'Department_Class_BF' || RecordTypeName == 'Department_Class_ET') { if (List[0]['Parent']['Parent']['FSE_GI_Main_Leader__c'] != null) { console.log('Work_Location1----------------',List[0]['Parent']['Parent']['FSE_GI_Main_Leader__r']['Work_Location__c']); Work_Location = List[0]['Parent']['Parent']['FSE_GI_Main_Leader__r']['Work_Location__c']; } } else if (RecordTypeName == 'Department_Class_GS' || RecordTypeName == 'Department_Class_URO' || RecordTypeName == 'Department_Class_ENT' || RecordTypeName == 'Department_Class_GYN' || RecordTypeName == 'Department_Class_OTH') { if (List[0]['Parent']['Parent']['FSE_SP_Main_Leader__c'] != null) { console.log('Work_Location2----------------',List[0]['Parent']['Parent']['FSE_SP_Main_Leader__r']['Work_Location__c']); Work_Location = List[0]['Parent']['Parent']['FSE_SP_Main_Leader__r']['Work_Location__c']; } } } if (RecordTypeName == 'Department_Class_GI') { Incharge_Staff = FSE_GI_Main_Leader__name; Incharge_Staff_id = FSE_GI_Main_Leader__id; } if (RecordTypeName == 'Department_Class_BF') { Incharge_Staff = FSE_GI_Main_Leader__name; Incharge_Staff_id = FSE_GI_Main_Leader__id; } if (RecordTypeName == 'Department_Class_ET') { Incharge_Staff = FSE_GI_Main_Leader__name; Incharge_Staff_id = FSE_GI_Main_Leader__id; } if (RecordTypeName == 'Department_Class_GS') { Incharge_Staff = FSE_SP_Main_Leader__name; Incharge_Staff_id = FSE_SP_Main_Leader__id; } if (RecordTypeName == 'Department_Class_URO') { Incharge_Staff = FSE_SP_Main_Leader__name; Incharge_Staff_id = FSE_SP_Main_Leader__id; } if (RecordTypeName == 'Department_Class_ENT') { Incharge_Staff = FSE_SP_Main_Leader__name; Incharge_Staff_id = FSE_SP_Main_Leader__id; } if (RecordTypeName == 'Department_Class_GYN') { Incharge_Staff = FSE_SP_Main_Leader__name; Incharge_Staff_id = FSE_SP_Main_Leader__id; } if (RecordTypeName == 'Department_Class_OTH') { Incharge_Staff = FSE_SP_Main_Leader__name; Incharge_Staff_id = FSE_SP_Main_Leader__id; } } console.log('修理委托人id---------------->>>>>>>',Incharge_Staff_id); console.log('修理品返送地---------------------->>>'+Work_Location); const url = encodeDefaultFieldValues({ Hospital__c: this.HospitalC, Department_Class__c: this.DepartmentClassC, Account__c: this.Id, Incharge_Staff__c: Incharge_Staff_id, SalesOfficeCode_selection__c: Work_Location, // SalesOfficeCode_selection__c: encodeURI(Work_Location), work_location_select__c: this.RepairSalesPointProvinceChinaC }); this[NavigationMixin.Navigate]({ type: 'standard__objectPage', attributes: { objectApiName: 'Repair__c', actionName: 'new' }, state: { //nooverride: '1', defaultFieldValues: url } }); this.dispatchEvent(new CloseActionScreenEvent()); // var url = "/a0J/e?CF00N10000002Dx66_lkid=" + this.HospitalId + "&CF00N10000002Dx66=" + this.HospitalC + // "&CF00N10000002Dx5t_lkid=" + this.DepartmentClassId + "&CF00N10000002Dx5t=" + this.DepartmentClassC + // "&CF00N10000002Dx5n_lkid=" + this.Id + "&CF00N10000002Dx5n=" + this.Name + // "&CF00N10000002EMHw_lkid=" + Incharge_Staff_id + "&CF00N10000002EMHw=" + Incharge_Staff + // "&00N10000002FH86=%e5%8f%aa%e4%bf%ae%e7%90%86&00N10000006P6Rn=" + this.RepairSalesPointProvinceChinaC + // "&00N10000006P6SM=" + encodeURI(Work_Location) + "&retURL=%2F" + this.Id; // window.open(url); }) } }