import { LightningElement,wire,track,api} from 'lwc'; import { CurrentPageReference } from "lightning/navigation"; import { CloseActionScreenEvent } from 'lightning/actions'; import { NavigationMixin } from 'lightning/navigation'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; // import { getRecordUi } from 'lightning/uiRecordApi'; // import NAME_FIELD from '@salesforce/schema/Repair__c.Incharge_Staff__c'; import MY_CUSTOM_OBJECT from '@salesforce/schema/Repair__c'; import init from '@salesforce/apex/NewRepairAuraController.init'; export default class newRepairLWC extends LightningElement { // Expose a field to make it available in the template // nameField = NAME_FIELD; // Flexipage provides recordId and objectApiName // @api recordId = 'a0J0l00000EouAT'; @api recordId; @api urlStr; @api objectApiName; /* @wire(CurrentPageReference) getStateParameters(currentPageReference) { console.log(111); console.log(currentPageReference); if (currentPageReference) { const urlValue = currentPageReference.state.recordId; if (urlValue) { let str = `${urlValue}`; console.log("str"); console.log(str); this.recordId = str; } } }*/ objectName = 'Repair__c'; uiPageLayoutView; isNewMode; //默认值赋值标记 // defaultFlag = true; defaultValue; isLoading = true; activeSections; connectedCallback(){ console.log(this.recordId); console.log(JSON.parse(this.urlStr)); } //获取Layout字段 handleRecordEditFormLoad(event) { console.log('Layout => ', JSON.stringify(event.detail.layout)); this.uiPageLayoutView = event.detail.layout; console.log('Layout1 => ',this.uiPageLayoutView); // urlStr 传参处理 init({ recordId : this.recordId,urlStr : this.urlStr }).then(result => { console.log("result"); console.log(result); this.defaultValue = result; //to del ! this.defaultValue['Delivered_Product'] = '02i10000004tNXIAA2'; this.defaultValue['Account'] = '0011000001g11rDAAQ'; this.defaultValue['SalesOfficeCode_selection'] = '北京'; this.defaultValue['On_site_repair'] = 'RC修理'; this.defaultValue['Repair_Detail'] = 'testLwc'; this.defaultValue['Hospital'] = '0011000001g11rDAAQ'; this.defaultValue['work_location_select'] = '北京办事处'; if (!result.status) { const inputFields = this.template.querySelectorAll( 'lightning-input-field' ); if (inputFields) { inputFields.forEach(field => { /*console.log('fieldsif => ',field); console.log('fieldsif => ',field.name); console.log('fieldsif => ',field.name.replace("__c",""));*/ let fieldName = field.name.replace("__c",""); if (this.defaultValue.hasOwnProperty(fieldName)) { field.value= this.defaultValue[fieldName]; } }); } } }).catch(error => { console.log("error"); console.log(error); }).finally(() => { let checkedSections = new Set(); if (this.uiPageLayoutView.sections.length > 0) { // console.log("id"); checkedSections.add(this.uiPageLayoutView.sections[0].id); //todo del or 显示所有 checkedSections.add(this.uiPageLayoutView.sections[1].id); // console.log(this.uiPageLayoutView.sections[0].id); //默认打开第一个accordion this.activeSections = Array.from(checkedSections); } this.isLoading = false; }); } // handleSubmit(event){ console.log("handleSubmit"); event.preventDefault(); // stop the form from submitting const fields = event.detail.fields; console.log("fields"); console.log(fields); console.log(event.detail); // this.template.querySelector('lightning-record-edit-form').submit(fields); } //成功后跳转 handleSucess(event){ const updatedRecord = event.detail.id; console.log('onsuccess: ', updatedRecord); } handleReset(event) { const fields = event.detail.fields; console.log('fields => ',fields); const inputFields = this.template.querySelectorAll( 'lightning-input-field' ); if (inputFields) { inputFields.forEach(field => { console.log('fieldsif => ',field); console.log('fieldsif => ',field.name); // field.reset(); }); } } handleSectionToggle(event) { const openSections = event.detail.openSections; /*if (openSections.length === 0) { this.activeSectionsMessage = 'All sections are closed'; } else { this.activeSectionsMessage = 'Open sections: ' + openSections.join(', '); }*/ } }