import { LightningElement,api,track,wire } from 'lwc'; import { CurrentPageReference } from 'lightning/navigation'; import initData from '@salesforce/apex/LexNewAndEditReportPIPLController.initData'; import { NavigationMixin } from 'lightning/navigation'; // import { AWSService } from 'c/piUtils'; // PIPL还原 by DTT-亚楠 20240126 import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import { getObjectInfo } from 'lightning/uiObjectInfoApi'; import lexPIPLCustomStyle from '@salesforce/resourceUrl/lexPIPLCustomStyle' import { decodeDefaultFieldValues } from "lightning/pageReferenceUtils"; import { loadStyle } from 'lightning/platformResourceLoader'; import CURRENTUSERID from '@salesforce/user/Id'; import REPORT from '@salesforce/schema/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 LexNewAndEditReportPIPL extends NavigationMixin(LightningElement) { sobjectType = 'Report__c'; // modifyFieldArray = ['Practitioner1__c','Practitioner2__c', 'Practitioner3__c', 'Practitioner4__c', 'Practitioner5__c','Person_In_Charge__c','Daily_Report__c']; modifyFieldArray = ['Practitioner1__c','Practitioner2__c', 'Practitioner3__c', 'Practitioner4__c','Person_In_Charge__c','Daily_Report__c','HospitalAcceptancePerson__c']; @track customLabel = customLabel; @api recordId; @wire(CurrentPageReference) pageRef; @track layout = []; @track labelMap = {}; title; // PIPL还原 by DTT-亚楠 20240126 start // recordTypeId = '' // staticResource; // AWSDataId = ''; // txId = ''; // PIPL还原 by DTT-亚楠 20240126 end hospitalId = ''; contactId = ''; contactAWSDataId = ''; practitioner = ''; isNewMode = false; isCloneMode = false; isEditMode = false; isLoading = false; isClone = false; isShowSearchAccount = false; saveAndNew = false; sectionName = []; AWSToSobjectMap = {}; recordData = {}; AWSService; contactIdMap = {}; defaultValues = {}; //查询特殊lookup searchFieldArray; searchWhere; searchField = 'Name'; searchObjectType; userId = CURRENTUSERID; @track iconName = ""; fieldLabel = {}; @wire(getObjectInfo, { objectApiName: REPORT }) getReportInfo({data,error}){ if(data){ this.fieldLabel = data.fields; this.labelMap ={ 'Practitioner1__c' : data.fields.Practitioner1__c != null ? data.fields.Practitioner1__c.label : '', 'Practitioner2__c' : data.fields.Practitioner2__c != null ? data.fields.Practitioner2__c.label : '', 'Practitioner3__c' : data.fields.Practitioner3__c != null ? data.fields.Practitioner3__c.label : '', 'Practitioner4__c' : data.fields.Practitioner4__c != null ? data.fields.Practitioner4__c.label : '', // 'Practitioner5__c' : data.fields.Practitioner5__c.label, 'Person_In_Charge__c' : data.fields.Person_In_Charge__c != null ? data.fields.Person_In_Charge__c.label : '', 'Daily_Report__c' : data.fields.Daily_Report__c != null ? data.fields.Daily_Report__c.label : '', 'HospitalAcceptancePerson__c' : data.fields.HospitalAcceptancePerson__c != null ? data.fields.HospitalAcceptancePerson__c.label : '', } } } connectedCallback(){ this.isLoading = true; loadStyle(this, lexPIPLCustomStyle); // this.AWSService = new AWSService(); // PIPL还原 by DTT-亚楠 20240126 if (this.pageRef && this.pageRef.state) { this.recordTypeId = this.pageRef.state.recordTypeId; this.isClone = this.pageRef.state.c__isClone; // 获取从其他页面带来的参数 if (this.pageRef.state.defaultFieldValues) { this.defaultValues = decodeDefaultFieldValues( this.pageRef.state.defaultFieldValues ); // console.log('this.contactAWSDataId = ' + this.contactAWSDataId); // PIPL还原 by DTT-亚楠 20240126 } } if(this.recordId){ this.isEditMode = true; this.title = '编辑报告书'; }else{ this.title = '新建报告书'; if(this.isClone){ this.title = '克隆报告书'; 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)); if (r.status == 'Success') { let layout = JSON.parse(r.entity.layout); this.recordData = r.entity.data; // PIPL还原 by DTT-亚楠 20240126 start // this.AWSToSobjectMap = JSON.parse(JSON.stringify(r.entity.AWSToSobjectNonEncryptedMap)); // this.staticResource = JSON.parse(r.entity.staticResource); // this.staticResourceContact = JSON.parse(r.entity.staticResourceContact); // if(r.entity.AWSDataId){ // this.AWSDataId = r.entity.AWSDataId; // } // PIPL还原 by DTT-亚楠 20240126 end if(r.entity.recordTypeId){ this.recordTypeId = r.entity.recordTypeId; } this.sectionName = layout.map(s => s.label); layout = this.sortMetaLayouts(layout); layout.forEach(section =>{ section['showSection'] = false; if(section['editHeading']){ section['showSection'] = true; } section['showLabel'] = false; //deloitte-zhj 20231218 字段一行展示修改 start section['Two'] = true; if(section['style'] == 'OneColumn'){ section['Two'] = false; } debugger //deloitte-zhj 20231218 字段一行展示修改 end 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(item['field'] == 'Hospital_Department__c'){ this.hospitalId = this.defaultValues['Hospital_Department__c']; } } } //实施人1,2,3,4,5与Contact关联,故采用自定义 if(this.modifyFieldArray.includes(item['field'])){ item['isModify'] = true; item['isShowIcon'] = true; item['label'] = this.labelMap[filedName]; if(this.isEditMode || this.isCloneMode){ let lookupName = filedName.slice(0, -1) + 'r'; if(filedName == 'Daily_Report__c'){ item['value'] = this.recordData[lookupName] == null ? '' : this.recordData[lookupName].Name; this.contactIdMap[filedName] = this.recordData[filedName] == null ? '' : this.recordData[filedName]; }else{ item['value'] = this.recordData[lookupName] == null ? '' : this.recordData[lookupName].LastName; this.contactIdMap[filedName] = this.recordData[filedName] == null ? '' : this.recordData[filedName]; // PIPL还原 by DTT-亚楠 20240126 start // this.contactAWSDataId = this.recordData[lookupName] == null ? '' : this.recordData[lookupName].AWS_Data_Id__c; // //解密客户人员 // this.queryContactName(filedName); // PIPL还原 by DTT-亚楠 20240126 end } } } if(this.isCloneMode && item['field'] != 'Name'){ item['value'] = this.recordData[filedName] == null ? '' : this.recordData[filedName]; } if(item['field'] == 'Hospital_Department__c' && this.isEditMode){ this.hospitalId = this.recordData.Hospital_Department__c == null ? '' : this.recordData.Hospital_Department__c; } //deloitte-zhj 20231102 if (filedName == 'RecordTypeId') { item['isDisable'] = true; } }) } }) }) this.layout = layout; // PIPL还原 by DTT-亚楠 20240126 start // //编辑 // if(this.isEditMode || this.isCloneMode){ // //解密意向的加密字段 // this.queryLeadFromAWSIFS(); // } // PIPL还原 by DTT-亚楠 20240126 end } else { this.showToast('Error', r.msg); } if(this.isCloneMode){ this.recordId = ''; } this.isLoading = false; }) } // 重新排版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; } // PIPL还原 by DTT-亚楠 20240126 start // //解密客户人员 // queryContactName(filedName){ // var that = this; // this.AWSService.query(this.staticResourceContact.queryUrl,this.contactAWSDataId,function(data){ // console.log('data = ' + JSON.stringify(data)); // if (data.object) { // for (let s of that.layout) { // for (let lc of s.layoutColumns) { // if(lc.layoutItems){ // for (let c of lc.layoutItems) { // if(c['field'] == filedName){ // c['value'] = data.object.lastName; // } // } // } // } // } // } // },this.staticResourceContact.token) // } // //解密加密字段 // queryLeadFromAWSIFS(){ // var that = this; // debugger; // this.AWSService.query(this.staticResource.queryUrl,this.AWSDataId,function(data){ // console.log('queryLeadFromAWSIFS data = ' + JSON.stringify(data)); // if (data.object) { // for (let s of that.layout) { // for (let lc of s.layoutColumns) { // if(lc.layoutItems){ // for (let c of lc.layoutItems) { // for (let f in that.AWSToSobjectMap) { // if (data.object.hasOwnProperty(f) && c['field'] == that.AWSToSobjectMap[f]) { // c['value'] = data.object[f] == null ? '' : data.object[f]; // } // } // } // } // } // } // } // },this.staticResource.token) // } // PIPL还原 by DTT-亚楠 20240126 end //取消 cancel() { conmentCancel(this.defaultValues); } //change事件 dataChange(event) { let fieldName = event.target.getAttribute("data-field"); let value = event.detail.value; console.log("fieldName = " + fieldName + " value = " + event.detail.value); this.contactIdMap[fieldName] = value; if(fieldName == 'Hospital_Department__c'){ this.hospitalId = value; } } // 重写保存按钮 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) { debugger this.isLoading = true; //1. Get Sobject Information from Form event.preventDefault(); var fields = event.detail.fields; this.modifyFieldArray.forEach(fieldname =>{ fields[fieldname] = this.contactIdMap[fieldname]; }) //保存到后端 console.log("submit = " + JSON.stringify(fields)); this.template.querySelector("lightning-record-edit-form").submit(fields); // PIPL还原 by DTT-亚楠 20240110 start // //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); // return // } // //编辑 // if(this.isEditMode){ // this.UpdatePIToAWS(payloadForNewPI,fields); // } // PIPL还原 by DTT-亚楠 20240110 end } // PIPL还原 by DTT-亚楠 20240110 start // //新建保存ToAWS // NewPIToAWS(payloadForNewPI,fields){ // let that = this; // this.AWSService.post(this.staticResourceV2.newUrl, payloadForNewPI, (result) => { // if (result && result.object) { // console.log('result = ' + JSON.stringify(result)); // for (let f in this.AWSToSobjectMap) { // if (result.object[0].hasOwnProperty(f)) { // fields[this.AWSToSobjectMap[f]] = result.object[0][f]; // console.log('this.AWSToSobjectMap[f] = ' + this.AWSToSobjectMap[f]); // console.log('fields[this.AWSToSobjectMap[f]] = ' + fields[this.AWSToSobjectMap[f]]); // } // else { // console.log(f + 'is not in result.object[0]'); // } // } // fields['AWS_Data_Id__c'] = result.object[0].dataId; // this.txId = result.txId; // if(fields.RecordTypeId){ // console.log('length = ' + JSON.stringify(fields.RecordTypeId.length)); // fields['RecordTypeId'] = fields.RecordTypeId.substring(1, fields.RecordTypeId.length - 1); // console.log('RecordTypeId = ' + JSON.stringify(fields['RecordTypeId'])); // } // //保存到后端 // that.template.querySelector('lightning-record-edit-form').submit(fields); // } else { // console.log('result = ' + JSON.stringify(result)); // } // }, this.staticResource.token); // } // //编辑保存ToAWS // UpdatePIToAWS(payloadForNewPI, fields) { // let obj = JSON.parse(payloadForNewPI); // if(this.AWSDataId){ // obj[0].dataId = this.AWSDataId; // }else{ // this.showMyToast("Error", '未找到该记录的AWS Id,请确认记录完整性', 'error'); // return; // } // let payloadForNewPIJson = JSON.stringify(obj); // this.AWSService.post(this.staticResourceV2.updateUrl, payloadForNewPIJson, (result) => { // if (result && result.object) { // console.log('result = ' + JSON.stringify(result)); // for (let f in this.AWSToSobjectMap) { // if (result.object[0].hasOwnProperty(f)) { // fields[this.AWSToSobjectMap[f]] = result.object[0][f]; // console.log('this.AWSToSobjectMap[f] = ' + this.AWSToSobjectMap[f]); // console.log('fields[this.AWSToSobjectMap[f]] = ' + fields[this.AWSToSobjectMap[f]]); // } // else { // console.log(f + 'is not in result.object[0]'); // } // } // if (this.isNewMode || this.isCloneMode) { // fields['AWS_Data_Id__c'] = result.object[0].dataId; // } else { // //更新 // fields['AWS_Data_Id__c'] = this.AWSDataId; // } // this.txId = result.txId; // if (fields.RecordTypeId) { // console.log('length = ' + JSON.stringify(fields.RecordTypeId.length)); // fields['RecordTypeId'] = fields.RecordTypeId.substring(1, fields.RecordTypeId.length - 1); // console.log('RecordTypeId = ' + JSON.stringify(fields['RecordTypeId'])); // } // //保存到后端 // console.log('update submit = ' + JSON.stringify(fields)); // this.template.querySelector('lightning-record-edit-form').submit(fields); // } else { // console.log('result = ' + JSON.stringify(result)); // } // }, this.staticResource.token); // } // //提交保存成功 // handleSuccess(event) { // let updatedRecord = event.detail.id; // console.log('onsuccess: ', updatedRecord); // console.log('confirmTrans'); // let that = this; // this.AWSService.confirm(true, updatedRecord, this.txId, this.staticResource.token, this.staticResource.transactionUrl, function (result) { // console.log('result = ' + JSON.stringify(result)) // that.showToast('Success', '保存成功'); // console.log('updatedRecord = ' + updatedRecord) // that.confirmAndNavigate(updatedRecord); // }); // } // // 保存成功后处理相关的收货地址数据并跳转页面 // confirmAndNavigate(updatedRecord){ // this.isLoading = true; // EncryptUpdate({'rid': updatedRecord}) // .then(result =>{ // if(result.message){ // console.log('EncryptUpdate Error:'+result.message); // this.showToast("Error", result.message); // } // if(this.saveAndNew){ // this[NavigationMixin.Navigate]({ // type: "standard__objectPage", // attributes: { // objectApiName: this.sobjectType, // actionName: "new", // }, // state: { // recordTypeId: this.recordTypeId, // }, // }); // }else{ // let url = "/" + updatedRecord; // parent.location.href = url // // this[NavigationMixin.Navigate]({ // // type: 'standard__recordPage', // // attributes: { // // actionName: "view", // // recordId: updatedRecord, // // objectApiName: this.sobjectType // // } // // }); // } // }) // } // //提交保存失败 // handleError(event) { // event.preventDefault(); // event.stopImmediatePropagation(); // 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("Error", 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 // } // //add by Li Jun 20231025 Start // if(this.txId && this.staticResource){ // this.AWSService.confirm(false,'',this.txId,this.staticResource.token,this.staticResource.transactionUrl,function(result){ // console.log('result = ' + JSON.stringify(result)) // }); // } // //add by Li Jun 20231025 End // } //提交保存成功 handleSuccess(event) { debugger; console.log('enter handleSuccess>>>>>>>>>>'); let updatedRecord = event.detail.id; this.navigate(updatedRecord); 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("Error", 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 } } // PIPL还原 by DTT-亚楠 20240110 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 = '