| import { LightningElement,api,track,wire } from 'lwc'; | 
| import { CurrentPageReference } from 'lightning/navigation'; | 
| import initData from '@salesforce/apex/LexNewAndEditCasePIPLController.initData'; | 
| import getContactByAWSId from '@salesforce/apex/LexNewAndEditCasePIPLController.getContactByAWSId'; | 
| import { NavigationMixin } from 'lightning/navigation'; | 
| import { AWSService } from 'c/piUtils'; | 
| import { ShowToastEvent } from 'lightning/platformShowToastEvent'; | 
| import { getObjectInfo } from 'lightning/uiObjectInfoApi'; | 
| import { decodeDefaultFieldValues } from "lightning/pageReferenceUtils"; | 
| import lexPIPLCustomStyle from '@salesforce/resourceUrl/lexPIPLCustomStyle' | 
| import {loadStyle} from 'lightning/platformResourceLoader'; | 
| import CASE from '@salesforce/schema/Case'; | 
| 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 LexNewAndEditCasePIPL extends NavigationMixin(LightningElement) { | 
|     sobjectType = 'Case'; | 
|     modifyFieldArray = ['ContactId']; | 
|     @track customLabel = customLabel; | 
|     @api recordId; | 
|     @wire(CurrentPageReference) pageRef; | 
|     @track layout = []; | 
|     @track labelMap = {}; | 
|   | 
|     title; | 
|     recordTypeId = ''  | 
|     staticResource; | 
|     AWSDataId = ''; | 
|     txId = ''; | 
|     contactId = ''; | 
|     contactAWSDataId = ''; | 
|     practitioner = ''; | 
|     hospitalId = ''; | 
|     isNewMode = false; | 
|     isEditMode = false; | 
|     isLoading = false; | 
|     isShowSearchAccount = false | 
|     saveAndNew = false; | 
|     sectionName = []; | 
|     AWSToSobjectMap = {}; | 
|     recordData = {}; | 
|     AWSService; | 
|     contactIdMap = {}; | 
|     defaultValues = {}; | 
|     //查询特殊lookup | 
|     searchFieldArray; | 
|     searchWhere; | 
|     searchField = 'Name'; | 
|     searchObjectType; | 
|     @track iconName = ""; | 
|     fieldLabel = {}; | 
|     @track searchNameValue = ''; | 
|   | 
|     @wire(getObjectInfo, { objectApiName: CASE }) | 
|     getCaseInfo({data,error}){ | 
|         if(data){ | 
|             this.fieldLabel = data.fields; | 
|             this.labelMap ={ | 
|                 'ContactId' : data.fields.ContactId != null ? data.fields.ContactId.label : '', | 
|             } | 
|         } | 
|     } | 
|   | 
|     connectedCallback(){ | 
|         this.isLoading = true; | 
|         loadStyle(this, lexPIPLCustomStyle); | 
|         this.AWSService = new AWSService(); | 
|         if (this.pageRef && this.pageRef.state) { | 
|             this.recordTypeId = this.pageRef.state.recordTypeId; | 
|             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 = '编辑CIC'; | 
|         }else{ | 
|             this.title = '新建CIC'; | 
|             this.isNewMode = true; | 
|         } | 
|   | 
|   | 
|         setTimeout(() => { | 
|             this.init(); | 
|         }, 1000); | 
|     } | 
|   | 
|     init(){ | 
|         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.layout = layout; | 
|                 this.recordData = r.entity.data; | 
|                 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; | 
|                 } | 
|                 if(r.entity.recordTypeId){ | 
|                     this.recordTypeId = r.entity.recordTypeId; | 
|                 } | 
|                 this.sectionName = layout.map(s => s.label); | 
|                 console.log('layout1:'+JSON.stringify(layout)); | 
|                 layout = this.sortMetaLayouts(layout); | 
|                 console.log('layout2:'+JSON.stringify(layout)); | 
|                 layout.forEach(section =>{ | 
|                     //update by Link 2023-09-26:跨列 start | 
|                     section['isOneCol'] = false; | 
|                     if(section['style'] == 'OneColumn'){ | 
|                         console.log(section['style']+' isOneCol is true'); | 
|                         section['isOneCol'] = true; | 
|                     } | 
|                     //update by Link 2023-09-26:跨列 end | 
|                     section['showSection'] = false; | 
|                     if(section['editHeading']){ | 
|                         section['showSection'] = true; | 
|                     } | 
|                     section['showLabel'] = false; | 
|                     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]; | 
|                                     } | 
|                                 } | 
|                                 // 客户人员姓名与Contact关联,故采用自定义 | 
|                                 if(this.modifyFieldArray.includes(item['field'])){ | 
|                                     item['isModify'] = true; | 
|                                     item['isShowIcon'] = true; | 
|                                     item['label'] = this.labelMap[filedName]; | 
|                                     let lookupName = filedName.slice(0, -2); | 
|                                     if(this.isEditMode ){ | 
|                                         if(this.recordData[lookupName] && this.recordData[lookupName].AWS_Data_Id__c){ | 
|                                             item['value'] = this.recordData[lookupName] == null ? '' : this.recordData[lookupName].LastName; | 
|                                             this.contactIdMap[filedName] = this.recordData[filedName] == null ? '' : this.recordData[filedName]; | 
|                                             this.contactAWSDataId = this.recordData[lookupName] == null ? '' : this.recordData[lookupName].AWS_Data_Id__c; | 
|                                             //解密客户人员 | 
|                                             this.queryContactName(filedName); | 
|                                             //this.template.querySelector('[data-icon='+ filedName + ']').iconName = this.recordData[lookupName] == null ? 'utility:search' : 'utility:close'; | 
|                                         }else{ | 
|                                             item['value'] = this.recordData[lookupName] == null ? '' : this.recordData[lookupName].Name; | 
|                                             this.contactIdMap[filedName] = this.recordData[filedName] == null ? '' : this.recordData[filedName]; | 
|                                         } | 
|                                     } | 
|                                 } | 
|                                 //recordTypeId字段都应该是不可编辑的 | 
|                                 if(item['field'] == 'RecordTypeId'){ | 
|                                     item['isDisable'] = true; | 
|                                 } | 
|                             }) | 
|                         } | 
|                          | 
|                     }) | 
|                 }) | 
|                 //编辑 | 
|                 if(this.isEditMode){ | 
|                     //解密意向的加密字段 | 
|                     this.queryLeadFromAWSIFS(); | 
|                 } | 
|             } else { | 
|                 // this.showToast('Error', r.Msg); | 
|                 this.showMyToast(r.msg, '', 'error'); | 
|                  | 
|             } | 
|             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; | 
|     } | 
|   | 
|     //解密客户人员 | 
|     queryContactName(filedName){ | 
|         var that = this; | 
|         debugger | 
|         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; | 
|         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) | 
|     } | 
|   | 
|     //取消 | 
|     cancel() { | 
|         if(this.recordId != null && this.recordId != ''){ | 
|             this[NavigationMixin.Navigate]({ | 
|                 type: 'standard__recordPage', | 
|                 attributes: { | 
|                     recordId: this.recordId, | 
|                     actionName: 'view', | 
|                 }, | 
|             }); | 
|         }else{ | 
|             conmentCancel(this.defaultValues); | 
|         } | 
|     } | 
|   | 
|     //change事件 | 
|     dataChange(event) { | 
|         let fieldName = event.target.getAttribute("data-field"); | 
|         let value = event.detail.value; | 
|         console.log("fieldName = " + fieldName + " value = " + value); | 
|         this.contactIdMap[fieldName] = 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) { | 
|         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]; | 
|         }) | 
|   | 
|         //2. select cannot actively select redaction option | 
|         let validationResultMessage = this.validateFieldValueFormate(fields); | 
|         console.log('validationResultMessage=' + validationResultMessage); | 
|         if (validationResultMessage) { | 
|             // this.showToast('Error', 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.showToast('Error', 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 | 
|         //新建 | 
|         if(this.isNewMode || this.isCloneMode || this.AWSDataId == ''){ | 
|             this.NewPIToAWS(payloadForNewPI,fields); | 
|         } | 
|         //编辑 | 
|         if(this.isEditMode){ | 
|             this.UpdatePIToAWS(payloadForNewPI,fields); | 
|         } | 
|     } | 
|   | 
|     //新建保存ToAWS | 
|     NewPIToAWS(payloadForNewPI,fields){ | 
|         this.AWSService.post(this.staticResource.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; | 
|                 console.log('this.txId = ' + this.txId); | 
|                 console.log('PI After fields = ' + JSON.stringify(fields)); | 
|                 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'])); | 
|                 } | 
|                 //保存到后端 | 
|                 this.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; | 
|         } | 
|         obj[0].dataId = this.AWSDataId; | 
|         let payloadForNewPIJson = JSON.stringify(obj); | 
|         this.AWSService.post(this.staticResource.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; | 
|                 console.log('this.txId = ' + this.txId); | 
|                 console.log('PI After fields = ' + JSON.stringify(fields)); | 
|                 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', '保存成功'); | 
|             that.showMyToast('保存成功', '', 'success'); | 
|             // that.isLoading = false; | 
|             console.log('updatedRecord = ' + updatedRecord) | 
|             that.navigate(updatedRecord); | 
|             | 
|         }); | 
|     } | 
|   | 
|     // 保存成功后跳转页面 | 
|     navigate(updatedRecord){ | 
|         if(this.saveAndNew){ | 
|             window.location.reload(true); | 
|         }else{ | 
|             let url = "/" + updatedRecord; | 
|             parent.location.href = url | 
|         } | 
|     } | 
|   | 
|     //提交保存失败 | 
|     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      | 
|         this.isLoading = false; | 
|     } | 
|   | 
|     //验证字段 | 
|     validateFieldValueFormate(fields) { | 
|         let error_msg = ''; | 
|         let b = false; | 
|         for(var key in fields){ | 
|             if(fields[key] == "*****") | 
|                 b = true; | 
|         } | 
|         if(b) | 
|             error_msg = '下拉框不能主动选择密文选项'; | 
|         return error_msg; | 
|     } | 
|   | 
|     //验证required字段需要进行填写 | 
|     checkRequiredFieldMsg(fields) { | 
|         let msg = ''; | 
|         try { | 
|             for (let s of this.layout) { | 
|                 for (let lc of s.layoutColumns) { | 
|                     if (lc.layoutItems) { | 
|                         for (let c of lc.layoutItems) { | 
|                             if (!c.isDisable && c.isRequired && (fields[c.field] == null || fields[c.field] === '')) { | 
|                                 msg += ";" + this.fieldLabel[item.field].label ; | 
|                             } | 
|                         } | 
|                     } | 
|                 } | 
|             } | 
|         } catch (err) { | 
|             // this.showToast('Error',err.message); | 
|             this.showMyToast(err.message,'', 'error'); | 
|   | 
|         } | 
|         msg = msg.substring(1); | 
|         return msg; | 
|     } | 
|   | 
|     //获取PI字段 | 
|     getPIPayload(sobjJsonLwc) { | 
|         console.log() | 
|         let leadPayloadList = []; | 
|         let leadPIData = {}; | 
|   | 
|         for (let f in this.AWSToSobjectMap) { | 
|             if (sobjJsonLwc.hasOwnProperty(this.AWSToSobjectMap[f])) { | 
|                 leadPIData[f] = sobjJsonLwc[this.AWSToSobjectMap[f]] | 
|             } | 
|             else { | 
|                 console.log(this.AWSToSobjectMap[f] + 'is not in sobjJsonLwc'); | 
|             } | 
|         } | 
|   | 
|         leadPIData.sfRecordId = ''; | 
|         console.log('Sobject PI Data x :' + leadPIData); | 
|         leadPayloadList.push(leadPIData); | 
|         console.log('leadPayloadList = ' + JSON.stringify(leadPayloadList)); | 
|         return JSON.stringify(leadPayloadList); | 
|     } | 
|      | 
|     //查询客户人员根据医院 | 
|     searchHospitalNameModal(event){ | 
|         this.practitioner = event.target.getAttribute("data-field"); | 
|         console.log | 
|         if(this.modifyFieldArray.includes(this.practitioner)){ | 
|             this.lookupFieldLabel = '客户名'; | 
|             this.lookupTitle = '客户名'; | 
|             this.searchObjectType  = 'Contact'; | 
|             this.searchNameValue = event.target.value; | 
|             console.log('this.searchNameValue = ' + JSON.stringify(event.target.value)); | 
|             console.log('this.searchNameValue = ' + event.target.value); | 
|             this.isShowSearchAccount = true; | 
|         } | 
|     } | 
|   | 
|     //选择客户人员后进行赋值 | 
|     handleSelectContact(event){ | 
|         this.isLoading = true; | 
|         debugger | 
|         let fieldName = this.practitioner; | 
|         const selectContact = event.detail; | 
|         for (let s of this.layout) { | 
|             for (let lc of s.layoutColumns) { | 
|                 if (lc.layoutItems) { | 
|                     for (let c of lc.layoutItems) { | 
|                         if(c['field'] == fieldName){ | 
|                             c['value'] = selectContact.data.medicalStaffFullName; | 
|                             if(selectContact.data.sfRecordId){ | 
|                                 this.contactIdMap[fieldName] = selectContact.data.sfRecordId; | 
|                                 this.template.querySelector('[data-icon='+ fieldName + ']').iconName = "utility:close"; | 
|                             }else{ | 
|                                 getContactByAWSId({'awsId': selectContact.data.AWSDataId}) | 
|                                 .then(result =>{ | 
|                                     this.contactIdMap[fieldName] = result.ContactInfo.Id; | 
|                                     this.isLoading = false; | 
|                                     this.template.querySelector('[data-icon='+ fieldName + ']').iconName = "utility:close"; | 
|                                 }) | 
|                             } | 
|                         } | 
|                     } | 
|                 } | 
|             } | 
|         } | 
|   | 
|         this.layout = [...this.layout]; | 
|         this.closeHospitalNameModal(); | 
|     } | 
|   | 
|     //关闭客户人员根据医院模态框 | 
|     closeHospitalNameModal(){ | 
|         this.isShowSearchAccount = false; | 
|         this.isLoading = false; | 
|     } | 
|   | 
|     //清空客户姓名 | 
|     clearName(event) { | 
|         let fieldname = event.target.getAttribute("data-icon") | 
|         console.log("enter clearName"); | 
|         if (this.contactIdMap[fieldname] != "") { | 
|             this.contactIdMap[fieldname] = ""; | 
|             for (let s of this.layout) { | 
|                 for (let c of s.layoutColumns) { | 
|                     if (c.layoutItems) { | 
|                         for (let item of c.layoutItems) { | 
|                             if (item["field"] == fieldname) { | 
|                                 item["value"] = ""; | 
|                                 //this.contactId = ""; | 
|                             } | 
|                         } | 
|                     } | 
|                 } | 
|             } | 
|             this.layout = [...this.layout]; | 
|             this.template.querySelector('[data-icon='+ fieldname + ']').iconName = "utility:search"; | 
|         } | 
|     } | 
|   | 
|     showToast(type, msg) { | 
|         this.isLoading = false; | 
|         const event = new ShowToastEvent({ | 
|             title: msg, | 
|             variant: type, | 
|             //message: msg | 
|         }); | 
|         this.dispatchEvent(event); | 
|     } | 
|   | 
|     // 大段报错信息处理 | 
|     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 = | 
|                 '<h2><strong>' + | 
|                 title + | 
|                 '<strong/></h2><h5>' + | 
|                 message + | 
|                 '</h5>'; | 
|         } else { | 
|             content = '<h2><strong>' + title + '<strong/></h2>'; | 
|         } | 
|         this.template | 
|             .querySelector('c-common-toast') | 
|             .showToast(variant, content, iconName, 10000); | 
|             this.isLoading = false; | 
|     } | 
| } |