import { LightningElement, api, track, wire } from 'lwc'; import { CurrentPageReference } from 'lightning/navigation'; import initData from '@salesforce/apex/LexNewAndEditRentalApplyPIPLController.initData'; import getOrignalRentalApply from '@salesforce/apex/LexNewAndEditRentalApplyPIPLController.getOrignalRentalApply'; import { NavigationMixin } from 'lightning/navigation'; //import { AWSService } from 'c/piUtils'; //deloitte-zhj 20231229 PIPL还原 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 RENTAL from '@salesforce/schema/Rental_Apply__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'; import Agency_ID_c from '@salesforce/label/c.Agency_ID_c'; const customLabel = { LexRecordNotCreateable, LexNotCreateNote } // Add By Li Jun 20231025 End export default class LexNewAndEditRentalApplyPIPL extends NavigationMixin(LightningElement) { sobjectType = 'Rental_Apply__c'; modifyFieldArray = ['Repair__c', 'Follow_UP_Opp__c', 'Loaner_medical_Staff__c']; defaultValueFieldArray = ['Repair__c', 'Name', 'Hospital__c', 'Strategic_dept__c', 'Account__c', 'Demo_purpose1__c', 'demo_purpose2__c', 'Person_In_Charge__c', 'applyUser__c', 'Loaner_received_staff__c', 'QISRepair__c', 'QIS_number__c']; @api recordId; @wire(CurrentPageReference) pageRef; @track layout = []; @track labelMap = {}; @track customLabel = customLabel; title; recordTypeId = '' //deloitte-zhj 20231229 PIPL还原 //staticResource; //AWSDataId = ''; //contactAWSDataId = ''; //AWSService; //contactIdMap = {}; // hospitalId = ''; // accountId = ''; txId = ''; contactId = ''; practitioner = ''; devRecordTypeId = ''; isNewMode = false; isEditMode = false; isCloneMode = false; isClone = false; isLoading = false; isShowSearchAccount = false saveAndNew = false; sectionName = []; AWSToSobjectMap = {}; recordData = {}; defaultValues = {}; searchFieldArray; searchWhere; searchField = 'Name'; searchObjectType; @track iconName = ""; fieldLabel = {}; @track isEdit = false; @track phoneNumber = ''; @track directShippmentAddress = ''; @track isInitSuccess = false; @track fieldInfo = {}; //add by Link 2023-11-06:审批后编辑限制跳过特定简档 @track canEditApproved = false; @wire(getObjectInfo, { objectApiName: RENTAL }) getRentalInfo({ data, error }) { if (data) { this.fieldLabel = data.fields; this.labelMap = { 'Repair__c': data.fields.Repair__c != null ? data.fields.Repair__c.label : '', 'Follow_UP_Opp__c': data.fields.Follow_UP_Opp__c != null ? data.fields.Follow_UP_Opp__c.label : '', 'Loaner_medical_Staff__c': data.fields.Loaner_medical_Staff__c != null ? data.fields.Loaner_medical_Staff__c.label : '', }; // 遍历字段描述信息并提取字段名和数据类型 const fieldDescriptions = data.fields; const fieldInfo = {}; for (const fieldName in fieldDescriptions) { if (fieldDescriptions.hasOwnProperty(fieldName)) { const fieldDesc = fieldDescriptions[fieldName]; // fieldInfo.push({ // name: fieldName, // dataType: fieldDesc.dataType // }); fieldInfo[fieldName] = fieldDesc.dataType; } } // 将字段信息存储在track变量中 this.fieldInfo = fieldInfo; console.log('this.fieldInfo = ' + JSON.stringify(this.fieldInfo)) } } connectedCallback() { this.isLoading = true; loadStyle(this, lexPIPLCustomStyle); //this.AWSService = new AWSService(); //deloitte-zhj 20231229 PIPL还原 if (this.pageRef && this.pageRef.state) { this.recordTypeId = this.pageRef.state.recordTypeId; this.isClone = this.pageRef.state.c__isClone; if (this.pageRef.state.defaultFieldValues) { let defaultFieldValuesObj = this.pageRef.state.defaultFieldValues; let defaultFieldValuesStr = defaultFieldValuesObj; console.log('defaultFieldValuesStr1:'+defaultFieldValuesStr); console.log('defaultFieldValuesStr2:'+defaultFieldValuesStr.replace(/\+/g, '%2B')); this.defaultValues = decodeDefaultFieldValues(defaultFieldValuesStr.replace(/\+/g, '%2B')); //this.defaultValues = decodeDefaultFieldValues(this.pageRef.state.defaultFieldValues); } console.log('this.recordTypeId = ' + this.recordTypeId); console.log('defaultValues:', JSON.stringify(this.defaultValues)); } 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() { let rid; if (this.isCloneMode) { rid = this.pageRef.state.c__recordId; } else { rid = this.recordId } initData({ 'rid': rid, '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); console.log('layout:' + JSON.stringify(layout)); this.layout = layout; this.recordData = r.entity.data; //deloitte-zhj 20231229 PIPL还原 // this.AWSToSobjectMap = JSON.parse(JSON.stringify(r.entity.AWSToSobjectNonEncryptedMap)); // this.staticResource = JSON.parse(r.entity.staticResource); // this.staticResourceV2 = JSON.parse(r.entity.staticResourceV2); // this.staticResourceContact = JSON.parse(r.entity.staticResourceContact); // this.devRecordTypeId = r.entity.devRecordTypeId; // 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 => { section['showLabel'] = false; section['showSection'] = false; if (section['editHeading']) { 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; //recordTypeId字段都应该是不可编辑的 if (item['field'] == 'RecordTypeId') { item['isDisable'] = true; } //deloitte-zhj 20231229 PIPL还原 start // 特殊Lookup,故采用自定义 // if (this.modifyFieldArray.includes(item['field'])) { // item['isModify'] = true; // item['isShowIcon'] = true; // item['label'] = this.labelMap[filedName]; // let lookupName = filedName.slice(0, -1) + 'r'; // if (this.isEditMode || this.isCloneMode) { // if (filedName == 'Loaner_medical_Staff__c') { // item['value'] = this.recordData[lookupName] == null ? '' : this.recordData[lookupName].LastName; // this.contactAWSDataId = this.recordData[lookupName] == null ? '' : this.recordData[lookupName].AWS_Data_Id__c; // //解密客户人员 // this.queryContactName(filedName); // } else { // item['value'] = this.recordData[lookupName] == null ? '' : this.recordData[lookupName].Name; // } // this.contactIdMap[filedName] = this.recordData[filedName] == null ? '' : this.recordData[filedName]; // //this.template.querySelector('[data-icon='+ filedName + ']').iconName = this.recordData[lookupName] == null ? 'utility:search' : 'utility:close'; // } // } // if ((this.isEditMode || this.isCloneMode) && item['field'] == 'Hospital__c') { // this.hospitalId = this.recordData[filedName] == null ? '' : this.recordData[filedName]; // } // if ((this.isEditMode || this.isCloneMode) && item['field'] == 'Account__c') { // this.accountId = this.recordData[filedName] == null ? '' : this.recordData[filedName]; // } // if(this.isCloneMode && item['field'] != 'Name' ){ // item['value'] = this.recordData[filedName] == null ? '' : this.recordData[filedName]; // } //deloitte-zhj 20231229 PIPL还原 end //PIPL相关按钮处理 if (this.isNewMode && this.defaultValues && Object.keys(this.defaultValues).length != 0) { if(this.defaultValues[filedName] != '\"' && this.defaultValues[filedName] != 'undefined'){ item['value'] = this.defaultValues[filedName]; } if (filedName == 'Loaner_medical_Staff__c') { item['value'] = this.defaultValues[filedName] == null ? '' : this.defaultValues[filedName]; this.contactIdMap[filedName] = this.defaultValues[filedName] == null ? '' : this.defaultValues[filedName]; this.contactAWSDataId = this.defaultValues['loanerMedicalStaffAWSDataId'] == null ? '' : this.defaultValues['loanerMedicalStaffAWSDataId']; this.queryContactName(filedName); } if (item['field'] == 'Request_shipping_day__c' && this.defaultValues[filedName]) { item['value'] = new Date(new Date(this.defaultValues[filedName] + '').getTime() + (8 * 60 * 60 * 1000)).toISOString().substring(0,10); } if(filedName == 'Hospital__c'){ this.hospitalId = this.defaultValues['Hospital__c'] } if (filedName == 'Repair__c' && this.defaultValues['RepairName'] != 'undefined') { item['value'] = (this.defaultValues['RepairName'] == null || this.defaultValues['RepairName'] == undefined) ? '' : this.defaultValues['RepairName']; this.contactIdMap[filedName] = this.defaultValues[filedName]; } if (filedName == 'Account__c') { this.accountId = this.defaultValues[filedName]; } if (filedName == 'IsJump__c') { item['value'] = this.defaultValues[filedName] == 'true' ? true : false; } if (filedName == 'Follow_UP_Opp__c' && this.defaultValues['Follow_UP_OppName'] != 'undefined') { item['value'] = this.defaultValues['Follow_UP_OppName'] == null ? '' : this.defaultValues['Follow_UP_OppName']; this.contactIdMap[filedName] = this.defaultValues[filedName]; } if(this.defaultValues[filedName] == 'true'){ item['value'] = true; } if(this.defaultValues[filedName] == 'false'){ item['value'] = false; } //deloitte-zhj 20231229 PIPL还原 // if (filedName == 'Repair__c' && this.defaultValues['RepairName'] != 'undefined') { // item['value'] = (this.defaultValues['RepairName'] == null || this.defaultValues['RepairName'] == undefined) ? '' : this.defaultValues['RepairName']; // this.contactIdMap[filedName] = this.defaultValues[filedName]; // } // if (filedName == 'Follow_UP_Opp__c' && this.defaultValues['Follow_UP_OppName'] != 'undefined') { // item['value'] = this.defaultValues['Follow_UP_OppName'] == null ? '' : this.defaultValues['Follow_UP_OppName']; // this.contactIdMap[filedName] = this.defaultValues[filedName]; // } // if (filedName == 'Loaner_medical_Staff__c') { // item['value'] = this.defaultValues[filedName] == null ? '' : this.defaultValues[filedName]; // this.contactIdMap[filedName] = this.defaultValues[filedName] == null ? '' : this.defaultValues[filedName]; // this.contactAWSDataId = this.defaultValues['loanerMedicalStaffAWSDataId'] == null ? '' : this.defaultValues['loanerMedicalStaffAWSDataId']; // this.queryContactName(filedName); // } // if (filedName == 'Account__c') { // this.accountId = this.defaultValues[filedName]; // } } // if (item['field'] == 'Request_shipping_day__c') { // item['value'] = null // item['value'] = new Date().toISOString().substring(0,10); // } if ((this.isNewMode || this.isCloneMode) && item['field'] == 'Name') { item['value'] = '*'; } if(this.isEditMode && filedName == 'Phone_number__c'){ this.phoneNumber = item['value']; } if(this.isEditMode && filedName == 'direct_shippment_address__c'){ this.directShippmentAddress = item['value']; } }) } }) }) console.log('contactIdMap = ' + JSON.stringify(this.contactIdMap)); if (r.entity.isEdit != null) this.isEdit = r.entity.isEdit console.log('this.isEdit = ' + this.isEdit); //deloitte-zhj 20231229 PIPL还原 // if(this.defaultValues['rentalApplyAWSDataId']){ // this.AWSDataId = this.defaultValues['rentalApplyAWSDataId']; // //解密意向的加密字段 // this.queryLeadFromAWSIFS(); // } // //编辑 // if (this.isEditMode || this.isCloneMode) { // //解密意向的加密字段 // this.queryLeadFromAWSIFS(); // } this.isInitSuccess = true; } else { console.log('result:'+JSON.stringify(r)); this.showMyToast('Error', r.msg,'error'); } // setTimeout(() => { // this.isLoading = false; // }, 1500); }) } 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); } } 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; } //deloitte-zhj 20231229 PIPL还原 start // //解密客户人员 // queryContactName(filedName) { // let 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() { // let 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]; // } // } // } // } // } // } // if(data.object.phoneNumber) // that.phoneNumber = data.object.phoneNumber; // if(data.object.directShippmentAddress) // that.directShippmentAddress = data.object.directShippmentAddress; // console.log('that.phoneNumber = ' + that.phoneNumber); // console.log('that.directShippmentAddress = ' + that.directShippmentAddress); // } // }, this.staticResource.token) // } // //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; // if (fieldName == 'Hospital__c') { // this.hospitalId = value[0]; // } // if (fieldName == 'Account__c') { // this.accountId = value[0]; // } // } //deloitte-zhj 20231229 PIPL还原 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 = " + value); this.contactIdMap[fieldName] = value; if (fieldName == 'Hospital__c') { this.hospitalId = value[0]; } if (fieldName == 'Account__c') { this.accountId = value[0]; } } 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; //zhj MEBG新方案改造 2022-11-29 start if (this.isEdit && (fields.Phone_number__c != this.phoneNumber || fields.direct_shippment_address__c != this.directShippmentAddress) && !this.canEditApproved) { this.showMyToast('申请单批准后,不能编辑备品借用信息','','error'); this.isLoading = false; return } //保存到后端 console.log("submit = " + JSON.stringify(fields)); this.template.querySelector("lightning-record-edit-form").submit(fields); //zhj MEBG新方案改造 2022-11-29 end // this.modifyFieldArray.forEach(fieldname => { // fields[fieldname] = this.contactIdMap[fieldname]; // }) // // DB202303417030 【大及巨大课题】备品中心维修续借课题 2023 07 04 zhangheyang Start // let raName = fields['Name']; // getOrignalRentalApply({ 'raName': raName }) // .then(result => { // result = JSON.parse(JSON.stringify(result)); // if (result) { // if (result.Routine_Check_Status__c == 'OK') { // fields['AWS_Data_Id__c'] = result.AWS_Data_Id__c // } // } // this.continueSubmit(fields); // }) // DB202303417030 【大及巨大课题】备品中心维修续借课题 2023 07 04 zhangheyang End } // continueSubmit(fields) { // debugger // console.log('fields = ' + JSON.stringify(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); // //zhj MEBG新方案改造 2022-11-29 start // if (this.isEdit && (fields.Phone_number__c != this.phoneNumber || fields.direct_shippment_address__c != this.directShippmentAddress)) { // this.showMyToast('申请单批准后,不能编辑备品借用信息','','error'); // this.isLoading = false; // return // } // //zhj MEBG新方案改造 2022-11-29 end // //5. PI To AWS // //新建 // debugger // if (this.isNewMode || this.isCloneMode || this.AWSDataId == '') { // this.NewPIToAWS(payloadForNewPI, fields); // return // } // //编辑 // if (this.isEditMode) { // this.UpdatePIToAWS(payloadForNewPI, fields); // } // } // //新建保存ToAWS // NewPIToAWS(payloadForNewPI, fields) { // 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; // 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.fieldInfo // // for (const key in fields) { // // if(this.fieldInfo[key] == 'Date'){ // // console.log(key + ': ' + fields[key]); // // fields[key] = new Date(fields[key]); // // } // // } // 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; // } // if (this.recordData.Routine_Check_Status__c == 'OK') { // this.template.querySelector('lightning-record-edit-form').submit(fields); // return; // } // obj[0].dataId = this.AWSDataId; // 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; // 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); 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) { // this[NavigationMixin.Navigate]({ // type: 'standard__objectPage', // attributes: { // objectApiName: this.sobjectType, // actionName: 'new' // }, // state: { // recordTypeId: this.recordTypeId // } // }); 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 } } // //验证字段 // validateFieldValueFormate(fields) { // let error_msg = ''; // let b = false; // for (let 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); // } // 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"); // if (this.modifyFieldArray.includes(this.practitioner)) { // if (this.practitioner == 'Repair__c') { // if (!this.hospitalId) { // this.hospitalId = ''; // } // if (this.hospitalId == Agency_ID_c || this.hospitalId == '') { // this.showToast('Error', '请先选择医院名'); // return // } // this.lookupFieldLabel = '修理'; // this.lookupTitle = '修理'; // this.searchFieldArray = ['Id', 'Name', 'Service_Repair_No__c', 'Failure_Occurrence_Date__c', 'Repair_Ordered_Date__c', 'Hospital__r.Name', 'Account__r.Name', 'Status1__c', 'Status2__c']; // this.searchWhere = 'Hospital__c =\'' + this.hospitalId + '\' AND RecordTypeId = \'' + this.devRecordTypeId + '\' AND Agreed_Date__c != null'; // this.searchObjectType = 'Repair__c'; // } // if (this.practitioner == 'Follow_UP_Opp__c') { // if (!this.hospitalId) { // this.hospitalId = ''; // } // if (this.hospitalId == Agency_ID_c || this.hospitalId == '') { // this.showToast('Error', '请先选择医院名'); // return // } // this.lookupFieldLabel = '询价'; // this.lookupTitle = '询价'; // this.searchFieldArray = ['Id', 'Name', 'OCM_man_province_cus__c', 'Opportunity_No__c', 'Account.Name', 'CloseDate', 'StageName', 'Competitor__c', 'OCSM_RMB_Without_Tax_1000TR__c', 'Wholesale_Price_F__c', 'OCSM_RMB_Without_Tax_1000__c']; // this.searchWhere = 'Hospital__c =\'' + this.hospitalId + '\''; // this.searchObjectType = 'Opportunity' // } // if (this.practitioner == 'Loaner_medical_Staff__c') { // if (this.accountId == Agency_ID_c || this.accountId == '') { // this.showToast('Error', '请先选择医院名'); // return // } // this.lookupFieldLabel = '客户名'; // this.lookupTitle = '客户名'; // this.searchObjectType = 'Contact' // } // this.isShowSearchAccount = true; // //this.template.querySelector(".slds-modal").style="display:none"; // } // } // //选择客户人员后进行赋值 // handleSelectContact(event) { // this.isLoading = true; // 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"; // }) // } // console.log('selectContact.data.sfRecordId = ' + selectContact.data.sfRecordId); // console.log('c[value] = ' + c['value']); // } // } // } // } // } // this.layout = [...this.layout]; // this.isLoading = false; // this.closeHospitalNameModal(); // } // //清空客户姓名 // 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"; // } // } // handleSelectLookup(event) { // this.isLoading = true; // let fieldName = this.practitioner; // const selectLookup = 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'] = selectLookup.data.Name; // this.contactIdMap[fieldName] = selectLookup.data.Id; // } // } // } // } // } // this.layout = [...this.layout]; // this.isLoading = false; // this.closeHospitalNameModal(); // } // //关闭客户人员根据医院模态框 // closeHospitalNameModal() { // this.isShowSearchAccount = false; // //this.template.querySelector(".slds-modal").style=""; // } 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'); let iconName = ''; let content = ''; if (variant == 'success') { iconName = 'utility:check'; } else { iconName = 'utility:error'; } if (message != '') { content = '

' + title + '

' + message + '
'; } else { content = '

' + title + '

'; } this.template .querySelector('c-common-toast') .showToast(variant, content, iconName, 10000); this.isLoading = false; } }