import { LightningElement, api, track, wire } from 'lwc'; import { CurrentPageReference } from 'lightning/navigation'; import initData from '@salesforce/apex/LeadDemoPIPLController.initData'; export default class LeadDemoPIPL extends LightningElement { sobjectType = 'Lead'; @api recordId; @track title; @track recordTypeId; @track isClone = false; @track isShowSpinner = true; @wire(CurrentPageReference) pageRef; @track layout; @track fields; @track staticResource; @track section_names; @track piFieldsMap; connectedCallback() { if(!this.recordId || this.isClone){ this.title = '新建意向'; } if(this.pageRef && this.pageRef.state) { this.recordTypeId = this.pageRef.state.recordTypeId; } console.log('recordId = ' + this.recordId + ' pid = ' + this.pid + ' recordTypeId = ' + this.recordTypeId + ' sobjectType = ' + this.sobjectType); initData({ rid : this.recordId, recordTypeId : this.recordTypeId, sobjectType : this.sobjectType }).then((r) =>{ r = JSON.parse(JSON.stringify(r)); if(r.status == 'Success'){ console.log('r.status == Success'); console.log('r.entity.layout start = ' + r.entity.layout); let layout = JSON.parse(r.entity.layout); for(var s of layout){ for(var c of s.layoutColumns){ for(var item of c.layoutItems){ console.log('item.behavior = ' + JSON.stringify(item.behavior)); item['disabled'] = item.behavior == 'Readonly' ? true : false; item['required'] = item.behavior == 'Required' ? true : false; } } } this.layout = layout; this.fields = r.entity.fields; this.staticResource = JSON.parse(r.entity.staticResource) this.section_names = this.layout.map(s=>s.label); let m = {}; for(let f of this.staticResource.PIDetails){ m[f.SF_Field_API_Name__c] = f; } this.piFieldsMap = m; console.log('this.piFieldsMap = ' + JSON.stringify(this.piFieldsMap)); }else{ this.showToast('Error',r.Msg); } this.isShowSpinner = false; }) } showToast(type,msg){ const event = new ShowToastEvent({ title : type, variant : type, message : msg }); this.dispatchEvent(event); } CaseInfoChange(){ console.log('hello'); } save(){ console.log('enter save button'); for(let s of this.layout){ for(let c of s.layoutColumns){ for(let item of c.layoutItems){ // if(item.field && item.behavior != "Readonly"){ // if(pi_fields_map.hasOwnProperty(item.field)){ // data[item.field] = obj[pi_fields_map[item.field].AWS_Field_API__c]; // //data[pi_fields_map[item.field].SF_Field_Encrypted_API__c] = obj[pi_fields_map[item.field].AWS_Encrypted_Field_API__c]; // }else{ // data[item.field] = item.value; // } // } console.log('item.field = ' + item.field + ' value = ' + item.value); } } } } cancel(){ } change(event){ console.log(event.target.value); // console.log(event.target); // for(let s of this.layout){ // for(let c of s.layoutColumns){ // for(let item of c.layoutItems){ // if(item.field == 'Email') // console.log('item.field = ' + item.field + ' value = ' + item.value); // } // } // } } }