import { LightningElement,api,track,wire } from 'lwc'; import { CurrentPageReference } from 'lightning/navigation'; import initData from '@salesforce/apex/LexNewAndEditQISPIPLController.initData'; import { NavigationMixin } from 'lightning/navigation'; //import { AWSService } from 'c/piUtils'; //deloitte-zhj 20240105 PIPL还原 import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import lexPIPLCustomStyle from '@salesforce/resourceUrl/lexPIPLCustomStyle' import { loadStyle } from 'lightning/platformResourceLoader'; import { decodeDefaultFieldValues } from "lightning/pageReferenceUtils"; import { getObjectInfo } from 'lightning/uiObjectInfoApi'; import QIS from '@salesforce/schema/QIS_Report__c'; import { conmentCancel } from "c/lexPIPLConmentMethods"; // Add By Li Jun 20231025 Start import LexRecordNotCreateable from '@salesforce/label/c.LexRecordNotCreateable'; import LexNotCreateNote from '@salesforce/label/c.LexNotCreateNote'; const customLabel = { LexRecordNotCreateable, LexNotCreateNote } // Add By Li Jun 20231025 End export default class LexNewAndEditQISPIPL extends NavigationMixin(LightningElement) { sobjectType = 'QIS_Report__c'; @track customLabel = customLabel; @api recordId; @wire(CurrentPageReference) pageRef; @track layout = []; @track labelMap = {}; title; recordTypeId = '' //deloitte-zhj 20240105 PIPL还原 // staticResource; // AWSDataId = ''; // txId = ''; //AWSService; isNewMode = false; isCloneMode = false; isEditMode = false; isLoading = false; isClone = false; saveAndNew = false; sectionName = []; AWSToSobjectMap = {}; recordData = {}; contactIdMap = {}; defaultValues = {}; fieldLabel = {}; @track isInitSuccess = false; @wire(getObjectInfo, { objectApiName: QIS }) getOnCallInfo({data,error}){ if(data){ this.fieldLabel = data.fields; } } connectedCallback(){ this.isLoading = true; loadStyle(this, lexPIPLCustomStyle); //this.AWSService = new AWSService(); //deloitte-zhj 20240105 PIPL还原 if (this.pageRef && this.pageRef.state) { this.recordTypeId = this.pageRef.state.recordTypeId; this.isClone = this.pageRef.state.c__isClone; console.log('this.recordTypeId = ' + this.recordTypeId); // 获取从其他页面带来的参数 if (this.pageRef.state.defaultFieldValues) { this.defaultValues = decodeDefaultFieldValues( this.pageRef.state.defaultFieldValues ); console.log('this.contactAWSDataId = ' + this.contactAWSDataId); } } if(this.recordId){ this.isEditMode = true; this.title = '编辑QIS'; }else{ this.title = '新建QIS'; if(this.isClone){ this.title = '克隆QIS'; this.isCloneMode = true; }else{ this.isNewMode = true; } } setTimeout(() => { this.init(); }, 1000); } init(){ if(this.isCloneMode){ this.recordId = this.pageRef.state.c__recordId; } initData({ 'rid': this.recordId, 'recordTypeId': this.recordTypeId, 'sobjectType': this.sobjectType }).then((r) => { r = JSON.parse(JSON.stringify(r)); console.log('r===='+r.status); if (r.status == 'Success') { let layout = JSON.parse(r.entity.layout); this.layout = layout; this.recordData = r.entity.data; //deloitte-zhj 20240105 PIPL还原 // this.AWSToSobjectMap = JSON.parse(JSON.stringify(r.entity.AWSToSobjectNonEncryptedMap)); // this.staticResource = JSON.parse(r.entity.staticResource); // this.staticResourceV2 = JSON.parse(r.entity.staticResourceV2); // if(r.entity.AWSDataId){ // this.AWSDataId = r.entity.AWSDataId; // } if(r.entity.recordTypeId){ this.recordTypeId = r.entity.recordTypeId; } this.sectionName = layout.map(s => s.label); layout = this.sortMetaLayouts(layout); layout.forEach(section =>{ //update by Link 2023-10-07:跨列 start section['isOneCol'] = false; if(section['style'] == 'OneColumn'){ console.log(section['style']+' isOneCol is true'); section['isOneCol'] = true; } //update by Link 2023-10-07:跨列 end section['showLabel'] = false; section['showSection'] = false; if(section['editHeading'] || section['detailHeading']){ section['showSection'] = true; } section.layoutColumns.forEach(column =>{ if(column.layoutItems.length != 0 && section['showLabel'] == false){ section['showLabel'] = true; } if(column.layoutItems){ column.layoutItems.forEach(item =>{ let filedName = item['field']; item['isModify'] = false; item['isDisable'] = item.behavior == 'Readonly' ? true : false; item['isRequired'] = item.behavior == 'Required' ? true : false; if (this.isNewMode && this.defaultValues && Object.keys(this.defaultValues).length != 0) { if(this.defaultValues[filedName]){ item['value'] = this.defaultValues[filedName]; } } if(this.isCloneMode && item['field'] != 'QIS_Status__c'){ item['value'] = this.recordData[filedName] == null ? '' : this.recordData[filedName]; if(item['field'] == 'QIS_pre__c'){ item['value'] = this.pageRef.state.c__recordId; } } if (filedName == 'RecordTypeId') { item['isDisable'] = true; } }) } }) }) //deloitte-zhj 20240105 PIPL还原 // //编辑 // if(this.isEditMode || this.isCloneMode){ // //解密意向的加密字段 // this.queryLeadFromAWSIFS(); // } this.isInitSuccess = true; } else { this.showToast('Error', r.msg); } if(this.isCloneMode){ this.recordId = ''; } this.isLoading = false; }) } handleLoad() { console.log("handleLoad"); console.log("this.isInitSuccess = " + this.isInitSuccess); if (this.isInitSuccess) { let time = 1000; if (!this.isNewMode) { time = 2000; } let that = this; setTimeout(() => { that.isLoading = false; }, time); } } // 重新排版layout sortMetaLayouts(layout){ layout.forEach(s => { let c1 = (s.layoutColumns[0].layoutItems != null) ? s.layoutColumns[0].layoutItems : []; let c2 = []; if(s.layoutColumns.length > 1){ c2 = (s.layoutColumns[1].layoutItems != null) ? s.layoutColumns[1].layoutItems : []; } else{ s.layoutColumns.push({ "reserved": null, "layoutItems": [] }); } let emptySpaceItem = { "width": null, "showScrollbars": null, "showLabel": null, "scontrol": null, "reportChartComponent": null, "page_x": null, "height": null, "field": null, "emptySpace": true, "customLink": null, "component": null, "canvas": null, "behavior": null, "analyticsCloudComponent": null } let maxSize = 0 if(c1.length > c2.length){ maxSize = c1.length; for(let i = 0; i < maxSize; i++){ if(c2.length == maxSize){ break; } c2.push(emptySpaceItem); } }else{ maxSize = c2.length; for(let i = 0; i < maxSize; i++){ if(c1.length == maxSize){ break; } c1.push(emptySpaceItem); } } let tempList = []; let index = 0; for(let i = 0; i < maxSize; i++){ tempList.push(c1[i]); if(tempList.length == maxSize){ s.layoutColumns[index].layoutItems = tempList; tempList = []; tempList.push(c2[i]); index++; }else{ tempList.push(c2[i]); if(tempList.length == maxSize){ s.layoutColumns[index].layoutItems = tempList; tempList = []; index++; } } } }) layout = [...layout]; return layout; } //取消 cancel() { // if(this.isCloneMode){ // window.history.go(-4); // return // } conmentCancel(this.defaultValues); } // 重写保存按钮 clickSubmit(){ const btn = this.template.querySelector( ".hidden" ); if( btn ){ btn.click(); } } // 重写保存并提交按钮 clickSubmitAndNew(){ console.log('clickSubmitAndNew'); this.saveAndNew = true; const btn = this.template.querySelector(".hidden"); if (btn) { btn.click(); } } //提交保存 handleSubmit(event) { this.isLoading = true; //1. Get Sobject Information from Form event.preventDefault(); let fields = event.detail.fields; //保存到后端 console.log("submit = " + JSON.stringify(fields)); this.template.querySelector("lightning-record-edit-form").submit(fields); // this.isLoading = true; // //1. Get Sobject Information from Form // event.preventDefault(); // var fields = event.detail.fields; // //2. select cannot actively select redaction option // let validationResultMessage = this.validateFieldValueFormate(fields); // console.log('validationResultMessage=' + validationResultMessage); // if (validationResultMessage) { // this.showMyToast(validationResultMessage , '' , 'error') // this.isLoading = false; // return; // } // //3. Check Required Field // let checkRequiredFieldMsgResult = this.checkRequiredFieldMsg(fields); // console.log('checkRequiredFieldMsgResult = ' + checkRequiredFieldMsgResult); // if (checkRequiredFieldMsgResult != '') { // this.showMyToast(checkRequiredFieldMsgResult + '需要进行填写' , '' , 'error') // this.isLoading = false; // return; // } // //4. Prepare the payload for New PI API To AWS - To Do // let payloadForNewPI = this.getPIPayload(fields); // console.log('payloadForNewPI = ' + payloadForNewPI); // //5. PI To AWS // //新建 // debugger // if(this.isNewMode || this.isCloneMode || this.AWSDataId == ''){ // this.NewPIToAWS(payloadForNewPI,fields); // } // //编辑 // if(this.isEditMode){ // this.UpdatePIToAWS(payloadForNewPI,fields); // } } //提交保存成功 handleSuccess(event) { let updatedRecord = event.detail.id; console.log("onsuccess: ", updatedRecord); this.showMyToast('保存成功', '', 'success'); //deloitte-zhj 20231116 PIPL还原 start if (this.saveAndNew) { this[NavigationMixin.Navigate]({ type: "standard__objectPage", attributes: { objectApiName: this.sobjectType, actionName: "new", }, state: { recordTypeId: this.recordTypeId, }, }); } else { this[NavigationMixin.Navigate]({ type: "standard__recordPage", attributes: { actionName: "view", recordId: updatedRecord, objectApiName: this.sobjectType, }, }); } } // 保存成功后跳转页面 navigate(updatedRecord){ if(this.saveAndNew){ window.location.reload(true); }else{ let url = "/" + updatedRecord; parent.location.href = url } } //提交保存失败 handleError(event) { event.preventDefault(); event.stopImmediatePropagation(); //this.showToast("Error", event.detail.detail); console.log('event = ' + JSON.stringify(event)); //字段级别的报错 if (event.detail.output && event.detail.output.fieldErrors && Object.keys(event.detail.output.fieldErrors).length != 0) { let msg = ''; for (let key in event.detail.output.fieldErrors) { msg += ',' + event.detail.output.fieldErrors[key][0].message; } msg = msg.substring(1); this.showMyToast(event.detail.message + ' : ' + msg, '', 'error'); } else { //add by Li Jun 20231025 Start if(event.detail.message != '' && this.customLabel.LexRecordNotCreateable.indexOf(event.detail.message) != -1){ this.showMyToast("Error", this.customLabel.LexNotCreateNote, 'error'); }else{ this.showMyToast("Error", event.detail.message + ' : ' + event.detail.detail, 'error'); } //add by Li Jun 20231025 End } } // 大段报错信息处理 showMyToast(title, message, variant) { console.log('show custom message'); var iconName = ''; var content = ''; if (variant == 'success') { iconName = 'utility:check'; } else { iconName = 'utility:error'; } if (message != '') { content = '