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; connectedCallback(){ console.log(this.recordId); console.log(JSON.parse(this.urlStr)); console.log(333); } //获取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; this.defaultValue['Delivered_Product'] = '02i10000004tNXIAA2'; 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)) { console.log('fieldsif => ',field); // field.value= this.defaultValue[fieldName]; } }); } } }).catch(error => { console.log("error"); console.log(error); }).finally(() => { 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(); }); } } }