import { LightningElement, api, track, wire } from 'lwc';
|
import { CurrentPageReference } from 'lightning/navigation';
|
import initData from '@salesforce/apex/LexNewAndEditContactPIPLController.initData';
|
import searchContactByAccountId from '@salesforce/apex/LexNewAndEditContactPIPLController.searchContactByAccountId';
|
import { NavigationMixin } from 'lightning/navigation';
|
import { AWSService } from 'c/piUtils';
|
import lexPIPLCustomStyle from '@salesforce/resourceUrl/lexPIPLCustomStyle'
|
import { loadStyle } from 'lightning/platformResourceLoader';
|
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
|
import { decodeDefaultFieldValues } from "lightning/pageReferenceUtils";
|
import { conmentCancel } from "c/lexPIPLConmentMethods";
|
import Contact from '@salesforce/schema/Contact';
|
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
|
// 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 LexNewAndEditContactPIPL extends NavigationMixin(LightningElement) {
|
sobjectType = 'Contact';
|
|
@track customLabel = customLabel;
|
@api recordId;
|
@track recordCloneId;
|
@track recordTypeId;
|
@wire(CurrentPageReference) pageRef;
|
@track recordData = {};
|
@track title = '';
|
@track isLoading = false;
|
@track layout = [];
|
@track isDoctor = true;
|
|
|
@track staticResource;
|
@track staticResourceV2;
|
@track staticResourceContact;
|
@track piFieldsMap;
|
@track abstractData = '';
|
@track data = {};
|
@track piplData = {};
|
@track isNewMode = false;
|
@track isCloneMode = false;
|
@track isEditMode = false;
|
@track sectionName = [];
|
@track AWSToSobjectMap = {};
|
@track AWSDataId = '';
|
@track txId = '';
|
@track isShowSearchAccount = false;
|
@track accountId = '';
|
@track contactId = '';
|
@track accountName = '';
|
@track dataIdManageCodeMap = {};
|
@track saveAndNew = false;
|
AWSService;
|
@track customDivRef;
|
@track accid;
|
|
@track modifyObj = {};
|
modifyArray = ['LastName'];
|
@track isInitSuccess = false;
|
|
defaultValues = {};
|
fieldLabel = {};
|
|
@track mobilePhone = ''; //deloitte-zhj 20231106
|
@track hasMobilePhoneField = false; //deloitte-zhj 20231106
|
|
@wire(getObjectInfo, { objectApiName: Contact })
|
getReportInfo({ data, error }) {
|
if (data) {
|
this.fieldLabel = data.fields;
|
console.log('this.fieldLabel = ' + JSON.stringify(this.fieldLabel));
|
}
|
}
|
|
connectedCallback() {
|
this.isLoading = true;
|
loadStyle(this, lexPIPLCustomStyle);
|
console.log('enter connectedCallback');
|
this.AWSService = new AWSService();
|
if (!this.recordId) {
|
this.title = '新建客户人员';
|
this.isNewMode = true;
|
}
|
if (this.recordId) {
|
this.title = '编辑客户人员';
|
this.isEditMode = true;
|
}
|
if (this.pageRef && this.pageRef.state) {
|
this.accid = this.pageRef.state.accid;
|
this.recordTypeId = this.pageRef.state.recordTypeId;
|
console.log('this.recordTypeId = ' + this.recordTypeId);
|
this.isCloneMode = Boolean(this.pageRef.state.c__isClone);
|
//克隆
|
if (this.isCloneMode) {
|
this.isNewMode = false;
|
this.isEditMode = false;
|
this.recordCloneId = this.pageRef.state.c__recordId;
|
console.log('recordCloneId = ' + this.recordCloneId);
|
this.title = '克隆客户人员';
|
}
|
if (this.pageRef.state.defaultFieldValues) {
|
this.defaultValues = decodeDefaultFieldValues(
|
this.pageRef.state.defaultFieldValues
|
);
|
console.log('this.contactAWSDataId = ' + this.contactAWSDataId);
|
}
|
console.log("defaultValues:", JSON.stringify(this.defaultValues));
|
}
|
console.log('recordId = ' + this.recordId + ' recordCloneId = ' + this.recordCloneId + ' recordTypeId = ' + this.recordTypeId + ' sobjectType = ' + this.sobjectType);
|
let id = this.isCloneMode == true ? this.recordCloneId : this.recordId;
|
debugger
|
initData({
|
rid: id,
|
recordTypeId: this.recordTypeId,
|
sobjectType: this.sobjectType,
|
accid: this.accid
|
}).then((r) => {
|
r = JSON.parse(JSON.stringify(r));
|
console.log('r = ' + JSON.stringify(r))
|
if (r.status == 'Success') {
|
this.isDoctor = r.entity.isDoctor;
|
console.log('this.isDoctor = ' + this.isDoctor);
|
if (this.recordTypeId == null)
|
this.recordTypeId = r.entity.recordTypeId;
|
console.log('this.recordTypeId = ' + this.recordTypeId);
|
this.recordData = r.entity.data;
|
console.log('this.recordData = ' + JSON.stringify(this.recordData));
|
let index = 1;
|
//如果不是医院类型,使用标准页面
|
if (!this.isDoctor) {
|
debugger
|
let layout = JSON.parse(r.entity.layout);
|
layout = this.sortMetaLayouts(layout);
|
console.log('this.layout = ' + JSON.stringify(layout));
|
for (let s of layout) {
|
s['showSection'] = false;
|
if (s['editHeading'] || s['detailHeading']) {
|
s['showSection'] = true;
|
}
|
s['showLabel'] = false;
|
for (let c of s.layoutColumns) {
|
c['index'] = index++;
|
if (c.layoutItems.length != 0 && s['showLabel'] == false) {
|
s['showLabel'] = true;
|
}
|
if (c.layoutItems) {
|
for (let item of c.layoutItems) {
|
item['isDisable'] = item.behavior == 'Readonly' ? true : false;
|
item['isRequired'] = item.behavior == 'Required' ? true : false;
|
item['isModify'] = false;
|
let fieldName = item['field'];
|
if (fieldName == 'RecordTypeId') {
|
item['isDisable'] = true;
|
}
|
if (this.isNewMode && this.defaultValues && Object.keys(this.defaultValues).length != 0) {
|
if (this.defaultValues[item["field"]]) {
|
item["value"] = this.defaultValues[item["field"]];
|
}
|
if (item['field'] == 'AccountId') {
|
console.log('this.defaultValuesaccid = ' + this.defaultValues['AccountId']);
|
this.accountId = this.defaultValues['AccountId'];
|
}
|
}
|
}
|
}
|
}
|
}
|
this.layout = layout;
|
} else {
|
this.AWSDataId = r.entity.AWSDataId;
|
console.log('this.AWSDataId = ' + this.AWSDataId);
|
let layout = JSON.parse(r.entity.layout);
|
layout = this.sortMetaLayouts(layout);
|
console.log('this.layout = ' + JSON.stringify(layout));
|
this.sectionName = layout.map(s => s.label);
|
for (let s of layout) {
|
s['showSection'] = false;
|
if (s['editHeading'] || s['detailHeading']) {
|
s['showSection'] = true;
|
}
|
s['showLabel'] = false;
|
for (let c of s.layoutColumns) {
|
c['index'] = index++;
|
if (c.layoutItems.length != 0 && s['showLabel'] == false) {
|
s['showLabel'] = true;
|
}
|
if (c.layoutItems) {
|
for (let i = 0; i < c.layoutItems.length; i++) {
|
c.layoutItems[i]['isDisable'] = c.layoutItems[i].behavior == 'Readonly' ? true : false;
|
c.layoutItems[i]['isRequired'] = c.layoutItems[i].behavior == 'Required' ? true : false;
|
c.layoutItems[i]['isModify'] = false;
|
let fieldName = c.layoutItems[i]['field'];
|
if (this.isCloneMode && fieldName != 'UnifiedI_Contact_ID__c' && fieldName != 'ServicePlatformCode__c') {
|
c.layoutItems[i]['value'] = this.recordData[fieldName];
|
}
|
if (fieldName == 'RecordTypeId') {
|
c.layoutItems[i]['isDisable'] = true;
|
}
|
if (c.layoutItems[i]['field'] == 'Name') {
|
c.layoutItems[i].field = 'LastName';
|
c.layoutItems[i].fieldLabel = '姓名'
|
c.layoutItems[i]['isModify'] = true;
|
if (this.isEditMode || this.isCloneMode) {
|
c.layoutItems[i]['value'] = this.recordData.LastName
|
}
|
// 创建要插入的新元素
|
let newItem = {
|
field: "Salutation",
|
};
|
// 使用splice方法在满足条件的item后插入新元素
|
c.layoutItems.splice(i + 1, 0, newItem);
|
}
|
if (c.layoutItems[i]['field'] == 'AccountId' && (this.isEditMode || this.isCloneMode)) {
|
this.accountId = this.recordData.AccountId == null ? '' : this.recordData.AccountId;
|
}
|
if (this.isNewMode && this.defaultValues && Object.keys(this.defaultValues).length != 0) {
|
if (this.defaultValues[c.layoutItems[i]["field"]]) {
|
c.layoutItems[i]["value"] = this.defaultValues[c.layoutItems[i]["field"]];
|
}
|
if (c.layoutItems[i]['field'] == 'AccountId') {
|
console.log('this.defaultValuesaccid = ' + this.defaultValues['AccountId']);
|
this.accountId = this.defaultValues['AccountId'];
|
}
|
}
|
//deloitte-zhj 20231106
|
if(fieldName == 'MobilePhone'){
|
this.hasMobilePhoneField = true;
|
}
|
}
|
}
|
}
|
}
|
|
this.layout = layout;
|
console.log('this.accountId = ' + JSON.stringify(this.accountId));
|
console.log('this.layout = ' + JSON.stringify(this.layout));
|
this.AWSToSobjectMap = JSON.parse(JSON.stringify(r.entity.AWSToSobjectNonEncryptedMap));
|
this.staticResource = JSON.parse(r.entity.staticResource);
|
this.staticResourceV2 = JSON.parse(r.entity.staticResourceV2);
|
console.log('this.staticResourceV2 = ' + JSON.stringify(this.staticResourceV2));
|
|
//编辑
|
if (this.isEditMode || this.isCloneMode) {
|
//解密客户的加密字段
|
this.querySobjectFromAWS();
|
}
|
}
|
this.isInitSuccess = true;
|
|
} else {
|
//this.showToast('Error', r.msg);
|
this.showMyToast(r.msg, '', 'error')
|
}
|
})
|
}
|
|
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;
|
}
|
|
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);
|
}
|
}
|
|
querySobjectFromAWS() {
|
debugger
|
let 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];
|
if (c['field'] == 'LastName') {
|
that.modifyObj['LastName'] = data.object[f] == null ? '' : data.object[f];
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
//deloitte-zhj 20231106
|
if(!that.hasMobilePhoneField){
|
that.mobilePhone = data.object.mobilePhone;
|
}
|
}
|
}, this.staticResource.token)
|
}
|
|
|
dataChange(event) {
|
let fieldName = event.target.getAttribute("data-field");
|
let value = event.detail.value;
|
console.log("fieldName = " + fieldName + " value = " + event.detail.value);
|
console.log(typeof event.detail.value);
|
switch (fieldName) {
|
case "LastName":
|
this.modifyObj[fieldName] = value;
|
break;
|
case "AccountId":
|
this.accountId = value[0];
|
console.log('this.accountId = ' + this.accountId)
|
break
|
}
|
}
|
|
clickSubmit() {
|
debugger
|
console.log('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();
|
}
|
}
|
clickSection(event) {
|
event.preventDefault();
|
}
|
|
handleSubmit(event) {
|
this.isLoading = true;
|
//1. Get Sobject Information from Form
|
console.log('handleSubmit');
|
event.preventDefault();
|
const fields = event.detail.fields;
|
//如果不是医生类型,直接保存即可无需加密
|
if (!this.isDoctor) {
|
//保存到后端
|
this.template.querySelector('lightning-record-edit-form').submit(fields);
|
} else {
|
console.log('this.modifyObj = ' + JSON.stringify(this.modifyObj));
|
Object.assign(fields, this.modifyObj);
|
console.log('fields = ' + JSON.stringify(fields));
|
|
debugger
|
//2. select cannot actively select redaction option
|
let validationResultMessage = this.validateFieldValueFormate(fields);
|
console.log(validationResultMessage);
|
if (validationResultMessage) {
|
//this.showToast('Error', validationResultMessage);
|
this.showMyToast(validationResultMessage, '', 'error')
|
return
|
}
|
|
//3. Check Required Field
|
let checkRequiredFieldMsgResult = this.checkRequiredFieldMsg(fields);
|
console.log('checkRequiredFieldMsgResult = ' + checkRequiredFieldMsgResult);
|
if (checkRequiredFieldMsgResult != '') {
|
//this.showToast('Error', checkRequiredFieldMsgResult + '需要进行填写');
|
this.showMyToast(checkRequiredFieldMsgResult + '需要进行填写', '', 'error')
|
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
|
searchContactByAccountId({
|
accountId: this.accountId,
|
RecordTypeId: this.recordTypeId,
|
Isactive: fields['Isactive__c']
|
}).then((result) => {
|
result = JSON.parse(JSON.stringify(result));
|
if (result.status == 'fail') {
|
//this.showToast('Error', result.message);
|
this.showMyToast(result.message, '', 'error')
|
return
|
}
|
this.accountName = result.accountName;
|
this.dataIdManageCodeMap = result.dataIdManageCodeMap;
|
let contactList = '';
|
for (let i = 0; i < result.contactList.length; i++) {
|
if (result.contactList[i].AWS_Data_Id__c)
|
contactList += ',' + result.contactList[i].AWS_Data_Id__c;
|
}
|
contactList = contactList.substring(1);
|
payloadForNewPI = JSON.parse(payloadForNewPI);
|
payloadForNewPI[0].contactIds = contactList;
|
payloadForNewPI[0].isMobileVerif = result.isMobileVerif;
|
payloadForNewPI[0].isNameMobileVerif = result.isNameMobileVerif;
|
//deloitte-zhj 20231106 start
|
if(!this.hasMobilePhoneField){
|
payloadForNewPI[0].mobilePhone = this.mobilePhone;
|
}
|
//deloitte-zhj 20231106 end
|
payloadForNewPI = JSON.stringify(payloadForNewPI);
|
//新建
|
if (this.isNewMode || this.isCloneMode || this.AWSDataId == '' || this.AWSDataId == null) {
|
this.NewPIToAWS(payloadForNewPI, fields);
|
return
|
}
|
//编辑
|
if (this.isEditMode) {
|
this.UpdatePIToAWS(payloadForNewPI, fields);
|
}
|
});
|
}
|
|
|
}
|
|
//验证字段
|
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[c.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.medicalStaffFullName = leadPIData.lastName;
|
leadPIData.sfRecordId = '';
|
console.log('Sobject PI Data x :' + leadPIData);
|
leadPayloadList.push(leadPIData);
|
console.log('leadPayloadList = ' + JSON.stringify(leadPayloadList));
|
return JSON.stringify(leadPayloadList);
|
}
|
|
//新建保存ToAWS
|
NewPIToAWS(payloadForNewPI, fields) {
|
debugger
|
this.AWSService.post(this.staticResourceV2.newUrl, payloadForNewPI, (result) => {
|
if (result && result.object) {
|
//判断已存在相同名字的联系人
|
let errorMsg = '';
|
if (result.status == '129') {
|
errorMsg = '客户 [ ' + this.accountName + ' ],已存在相同名字的联系人 人员管理编码 [' + this.dataIdManageCodeMap[result.object[0].dataId] + ' ] ,不能重复创建,请了解';
|
//this.showToast('Error', errorMsg)
|
this.showMyToast(errorMsg, '', 'error')
|
return
|
}
|
if (result.status == '130') {
|
if (result.object[0] && result.object[0].sfRecordId != null && result.object[0].sfRecordId != '') {
|
errorMsg = '已找到重复值: UniqueNumber__c 与记录值重复,ID 为: ' + result.object[0].sfRecordId + '客户人员信息';
|
}
|
else {
|
errorMsg = '数据中存在重复的电话号码';
|
}
|
//this.showToast('Error', errorMsg)
|
this.showMyToast(errorMsg, '', 'error')
|
return
|
}
|
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;
|
//保存到后端
|
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.staticResourceV2.updateUrl, payloadForNewPIJson, (result) => {
|
if (result && result.object) {
|
//判断已存在相同名字的联系人
|
let errorMsg = '';
|
if (result.status == '129') {
|
errorMsg = '客户 [ ' + this.accountName + ' ],已存在相同名字的联系人 人员管理编码 [' + this.dataIdManageCodeMap[result.object[0].dataId] + ' ] ,不能重复创建,请了解';
|
//this.showToast('Error', errorMsg)
|
this.showMyToast(errorMsg, '', 'error')
|
return
|
}
|
if (result.status == '130') {
|
if (result.object[0] && result.object[0].sfRecordId != null && result.object[0].sfRecordId != '') {
|
errorMsg = '已找到重复值: UniqueNumber__c 与记录值重复,ID 为: ' + result.object[0].sfRecordId + '客户人员信息';
|
}
|
else {
|
errorMsg = '数据中存在重复的电话号码';
|
}
|
//this.showToast('Error', errorMsg)
|
this.showMyToast(errorMsg, '', 'error')
|
return
|
}
|
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'] = this.AWSDataId;
|
this.txId = result.txId;
|
console.log('this.txId = ' + this.txId);
|
console.log('PI After fields = ' + JSON.stringify(fields));
|
if (fields.RecordTypeId) {
|
fields['RecordTypeId'] = fields.RecordTypeId.substring(1, fields.RecordTypeId.length - 1);
|
}
|
//保存到后端
|
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) {
|
debugger
|
let updatedRecord = event.detail.id;
|
console.log('onsuccess: ', updatedRecord);
|
console.log('confirmTrans');
|
let that = this;
|
if (!this.isDoctor) {
|
this.showToast('Success', '保存成功');
|
console.log('updatedRecord = ' + updatedRecord)
|
if (this.saveAndNew) {
|
console.log('this.recordTypeId = ' + this.recordTypeId);
|
this[NavigationMixin.Navigate]({
|
type: 'standard__objectPage',
|
attributes: {
|
objectApiName: this.sobjectType,
|
actionName: 'new',
|
},
|
state: {
|
recordTypeId: this.recordTypeId
|
}
|
});
|
setTimeout(function() {
|
location.reload();
|
}, 1000); // 延迟一秒(1000毫秒)
|
} else {
|
this[NavigationMixin.Navigate]({
|
type: 'standard__recordPage',
|
attributes: {
|
actionName: "view",
|
recordId: updatedRecord,
|
objectApiName: this.sobjectType
|
}
|
});
|
setTimeout(function() {
|
location.reload();
|
}, 1000); // 延迟一秒(1000毫秒)
|
}
|
} else {
|
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)
|
if (that.saveAndNew) {
|
console.log('that.recordTypeId = ' + that.recordTypeId);
|
that[NavigationMixin.Navigate]({
|
type: 'standard__objectPage',
|
attributes: {
|
objectApiName: that.sobjectType,
|
actionName: 'new',
|
},
|
state: {
|
recordTypeId: that.recordTypeId
|
}
|
});
|
setTimeout(function() {
|
location.reload();
|
}, 1000); // 延迟一秒(1000毫秒)
|
} else {
|
that[NavigationMixin.Navigate]({
|
type: 'standard__recordPage',
|
attributes: {
|
actionName: "view",
|
recordId: updatedRecord,
|
objectApiName: that.sobjectType
|
}
|
});
|
setTimeout(function() {
|
location.reload();
|
}, 1000); // 延迟一秒(1000毫秒)
|
}
|
});
|
}
|
}
|
|
//提交保存失败
|
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(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){
|
if (this.isDoctor) {
|
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
|
}
|
|
|
//取消
|
cancel() {
|
conmentCancel(this.defaultValues);
|
}
|
|
//标准新建页面跳转
|
RedirectStandardNewPage() {
|
// this[NavigationMixin.Navigate]({
|
// type: 'standard__objectPage',
|
// attributes: {
|
// objectApiName: this.sobjectType,
|
// actionName: 'list'
|
// }
|
// }).then(() => {
|
// // 跳转成功后的逻辑
|
// debugger
|
// console.log('跳转成功');
|
// // this[NavigationMixin.Navigate]({
|
// // type: 'standard__objectPage',
|
// // attributes: {
|
// // objectApiName: 'Contact',
|
// // actionName: 'new'
|
// // },
|
// // state: {
|
// // nooverride: '1',
|
// // recordTypeId: this.recordTypeId
|
// // }
|
// // });
|
// })
|
// .catch(error => {
|
// // 取消跳转的逻辑
|
// console.log('取消跳转');
|
// });
|
|
// 在取消操作的回调函数中执行页面跳转
|
this[NavigationMixin.Navigate]({
|
type: 'standard__objectPage',
|
attributes: {
|
objectApiName: 'Contact',
|
actionName: 'new'
|
},
|
state: {
|
nooverride: '1',
|
recordTypeId: this.recordTypeId
|
}
|
});
|
}
|
|
//标准编辑页面跳转
|
RedirectStandardEditPage() {
|
this[NavigationMixin.Navigate]({
|
type: 'standard__recordPage',
|
attributes: {
|
objectApiName: 'Contact',
|
recordId: this.recordId,
|
actionName: 'edit',
|
},
|
state: {
|
nooverride: '1',
|
}
|
});
|
}
|
|
//显示信息
|
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 =
|
'<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;
|
}
|
}
|