/* eslint-disable no-console */
|
/* eslint-disable @lwc/lwc/no-async-operation */
|
// import lookUp from '@salesforce/apex/LookUpUtilControllerEvent.lookUp';
|
import lookUp from '@salesforce/apex/LookUpUtilController.lookUp';
|
// import getRecordForContact from '@salesforce/apex/ControllerUtilEvent.getRecordForContact';
|
import getRecordForContact from '@salesforce/apex/ControllerUtil.getRecordForContact';
|
// import getPIPLInfo from '@salesforce/apex/LookUpUtilControllerEvent.getPIPLInfo';//deloitte-zhj 获取解密信息 2023/07/19
|
import getPIPLInfo from '@salesforce/apex/LookUpUtilController.getPIPLInfo';//deloitte-zhj 获取解密信息 2023/07/19
|
// import searchContactInit from '@salesforce/apex/LookUpUtilControllerEvent.searchContactInit';//deloitte-zhj 搜索需要的PI数据 2023/07/19
|
import searchContactInit from '@salesforce/apex/LookUpUtilController.searchContactInit';//deloitte-zhj 搜索需要的PI数据 2023/07/19
|
// import searchContactByAccountId from '@salesforce/apex/LookUpUtilControllerEvent.searchContactByAccountId';//deloitte-zhj 新建判断重复 2023/07/19
|
import searchContactByAccountId from '@salesforce/apex/LookUpUtilController.searchContactByAccountId';//deloitte-zhj 新建判断重复 2023/07/19
|
// import { AWSService } from 'c/piUtils';//deloitte-zhj 调用aws 2023/07/19
|
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
|
import { getRecord } from 'lightning/uiRecordApi';
|
import { NavigationMixin } from 'lightning/navigation';
|
import { api, LightningElement, track, wire } from 'lwc';
|
import saveContact from '@salesforce/apex/LwcDailyReportController.saveContact';
|
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
|
import { refreshApex } from '@salesforce/apex';
|
|
export default class lookUpUtilEvent extends NavigationMixin(LightningElement) {
|
// AWSService; //deloitte-亚楠 20240120 PIPL还原
|
@track theContact = {};
|
@track showModal = false;
|
//记录id
|
@api valueId;
|
@api objName;
|
@api iconName;
|
@api disabled;
|
@api filter;
|
@api agencyContactName;
|
@api uniqueKey;
|
@api fields;
|
|
@api searchLabel;
|
@track searchTerm;
|
//record name value
|
@track valueObj;
|
//record href
|
@track href;
|
//fetch result
|
@track options;
|
//是否展示pill
|
@track isValue = false;
|
isCanCanle = true;
|
@track blurTimeout;
|
isOpen = false;
|
@track visitorPalceFields = ['Account.Name'];
|
@track newContactAcc;
|
//访问对象
|
|
handleContactDepartmentSelection(event) {
|
console.log('handleContactDepartmentSelection!!!!!!!!!!!!');
|
this.newContactAcc = event.detail.selectedId;
|
}
|
get boxClass() {
|
let classes = "slds-combobox slds-dropdown-trigger slds-dropdown-trigger_click slds-has-focus";
|
if (this.isOpen) {
|
return classes + " slds-is-open";
|
}
|
return classes;
|
}
|
_passFilter;
|
@api
|
get passFilter() {
|
return this._passFilter;
|
}
|
|
set passFilter(newValue) {
|
this._passFilter = newValue;
|
this.filter = newValue;
|
}
|
//css:
|
@track inputClass = '';
|
|
@api staticResourceContact;
|
@track txId;
|
//deloitte-zhj 获取PIPL需要的数据 2023/07/19 start
|
connectedCallback() {
|
//deloitte-亚楠 20240120 PIPL还原 start
|
// if(!this.AWSService) {
|
// this.AWSService = new AWSService();
|
// }
|
// // if(!this.staticResourceContact) {
|
// getPIPLInfo().then((r) => {
|
// r = JSON.parse(JSON.stringify(r));
|
// console.log('r = ' + JSON.stringify(r))
|
// if (r.status == 'Success') {
|
// this.staticResourceContact = JSON.parse(r.entity.staticResourceContact);
|
// console.log('this.staticResourceContact.searchUrl = ' + this.staticResourceContact.searchUrl)
|
// } else {
|
// console.log('error msg = ' + r.msg)
|
// }
|
// })
|
// console.log('this.staticResourceContact.end :' +this.staticResourceContact);
|
// }
|
//deloitte-亚楠 20240120 PIPL还原 end
|
|
}
|
|
getPIPLInfoJs() {
|
|
}
|
|
//deloitte-zhj 获取PIPL需要的数据 2023/07/19 end
|
//deloitte-zhj 解密 2023/07/19 start
|
@wire(lookUp, { searchTerm: '$searchTerm', objName: '$objName', filter: '$filter' })
|
wiredRecords({ error, data }) {
|
console.log('enter wiredRecords');
|
//deloitte-亚楠 20240120 PIPL还原 start
|
// if(!this.AWSService) {
|
// this.AWSService = new AWSService();
|
// // if(!this.staticResourceContact || !this.staticResourceContact.search) {
|
// getPIPLInfo().then((r) => {
|
// r = JSON.parse(JSON.stringify(r));
|
// console.log('r = ' + JSON.stringify(r))
|
// if (r.status == 'Success') {
|
// this.staticResourceContact = JSON.parse(r.entity.staticResourceContact);
|
// console.log('this.staticResourceContact.searchUrl = ' + this.staticResourceContact.searchUrl)
|
// } else {
|
// console.log('error msg = ' + r.msg)
|
// }
|
// })
|
// // }
|
|
// }
|
//deloitte-亚楠 20240120 PIPL还原 end
|
|
if (data) {
|
let that = this;
|
console.log('data = ' + JSON.stringify(data))
|
// let dataClone = this.deepClone(data);
|
let dataClone = [];
|
console.log('dataClone deepClone= ' + JSON.stringify(dataClone));
|
//搜索,需要把对应account下面进行了PIPL的数据查出来,需要搜索值和accountid都存在才行
|
console.log('this.filter = ' + this.filter)
|
console.log('this.searchTerm = ' + this.searchTerm)
|
if (this.filter) {
|
searchContactInit({
|
accountId: this.filter
|
}).then((r) => {
|
r = JSON.parse(JSON.stringify(r));
|
console.log('r = ' + JSON.stringify(r))
|
if (r.status == 'Success') {
|
//deloitte-亚楠 20240120 PIPL还原 start
|
let conList = r.entity.conList;
|
for(let i=0; i < conList.length; i++){
|
let PIData = {};
|
PIData.Id = conList[i].Id;
|
PIData.Name = conList[i].LastName;
|
dataClone.push(PIData)
|
}
|
that.executeWiredRecords(dataClone);
|
// let awsIdToContactMap = r.entity.awsIdToContactMap;
|
// let conAWSIds = r.entity.conAWSIds;
|
// console.log('awsIdToContactMap = ' + awsIdToContactMap);
|
// console.log('conAWSIds = ' + conAWSIds);
|
// that.AWSService.search(that.staticResourceContact.searchUrl, {
|
// dataIds: conAWSIds,
|
// contactName: that.searchTerm
|
// }, function (data) {
|
// console.log('data = ' + JSON.stringify(data));
|
// if (data.object) {
|
// let limit = data.object.length > 50 ? 50 : data.object.length;//最多找20条
|
// for(let i=0; i < limit; i++){
|
// if(awsIdToContactMap.hasOwnProperty(data.object[i].dataId)){
|
// let PIData = {};
|
// PIData.Id = awsIdToContactMap[data.object[i].dataId].Id;
|
// PIData.Name = data.object[i].lastName;
|
// PIData.AWSDataId = data.object[i].dataId;
|
// dataClone.push(PIData)
|
// }
|
// }
|
// console.log('dataClone = ' + JSON.stringify(dataClone));
|
// }
|
// that.executeWiredRecords(dataClone);
|
// }, that.staticResourceContact.token)
|
//deloitte-亚楠 20240120 PIPL还原 end
|
} else {
|
console.log('r.msg = ' + r.msg)
|
}
|
})
|
} else {
|
this.executeWiredRecords(dataClone)
|
}
|
} else if (error) {
|
this.error = error;
|
this.record = undefined;
|
console.log("wire.error", this.error);
|
} else {
|
console.log('啥都没有');
|
}
|
}
|
deepClone(obj) {
|
return JSON.parse(JSON.stringify(obj));
|
}
|
executeWiredRecords(dataClone) {
|
//deloitte-亚楠 20240120 PIPL还原 start
|
if(dataClone.length != 0){
|
this.record = dataClone;
|
console.log('this.record = ' + JSON.stringify(this.record));
|
this.error = undefined;
|
this.options = this.record;
|
console.log("common this.options", JSON.stringify(this.options));
|
}else{
|
this.record = dataClone;
|
this.error = undefined;
|
this.options = this.record;
|
console.log("common this.options", JSON.stringify(this.options));
|
}
|
|
// let arr = [];
|
// for (var i in dataClone) {
|
// if (dataClone[i].AWSDataId && arr.indexOf(dataClone[i].AWSDataId) == -1)
|
// arr.push(dataClone[i].AWSDataId)
|
// }
|
// if(!this.AWSService) {
|
// this.AWSService = new AWSService();
|
// }
|
// console.log('arr = ' + arr);
|
// let that = this;
|
// if (arr.length != 0) {
|
// this.AWSService.search(this.staticResourceContact.searchUrl, {
|
// dataIds: arr
|
// }, function (dataAWS) {
|
// console.log('dataAWS = ' + JSON.stringify(dataAWS));
|
// if (dataAWS && dataAWS.object && dataAWS.object.length > 0) {
|
// let awsMap = {};
|
// for (let di in dataAWS.object) {
|
// awsMap[dataAWS.object[di].dataId] = dataAWS.object[di];
|
// }
|
// console.log('awsMap = ' + JSON.stringify(awsMap));
|
// for (var i in dataClone) {
|
// if (awsMap.hasOwnProperty(dataClone[i].AWSDataId)) {
|
// dataClone[i].Name = awsMap[dataClone[i].AWSDataId].lastName
|
// }
|
// }
|
// console.log('dataClone = ' + JSON.stringify(dataClone));
|
// that.record = dataClone;
|
// console.log('that.record = ' + JSON.stringify(that.record));
|
// that.error = undefined;
|
// that.options = that.record;
|
// console.log("common this.options", JSON.stringify(that.options));
|
// } else {
|
// that.record = dataClone;
|
// that.error = undefined;
|
// that.options = that.record;
|
// console.log("common this.options", JSON.stringify(that.options));
|
// }
|
// }, this.staticResourceContact.token)
|
// } else {
|
// this.record = dataClone;
|
// this.error = undefined;
|
// this.options = this.record;
|
// console.log("common this.options", JSON.stringify(this.options));
|
// }
|
//deloitte-亚楠 20240120 PIPL还原 end
|
}
|
|
@wire(getRecordForContact, { recordId: '$valueId', fields: '$fields' })
|
async wiredOptions({ error, data }) {
|
if(!this.valueId) {
|
return;
|
}
|
console.log('zzzzzzz----222222');
|
console.log('wiredOptions');
|
var agencyContactNameTmp;
|
if (data) {
|
//deloitte-亚楠 20240120 PIPL还原 start
|
this.record = data;
|
console.log('this.record = ' + JSON.stringify(this.record));
|
this.error = undefined;
|
this.valueObj = data.Name;
|
this.href = '/' + this.record.id;
|
this.isValue = true;
|
// if(!this.AWSService) {
|
// this.AWSService = new AWSService();
|
// }
|
// console.log('wiredOptions data = ' + JSON.stringify(data))
|
// // deloitte-zhj 解密 2023/07/19 start
|
// if (data.AWS_Data_Id && data.Name.includes('***')) {
|
// console.log('data.fields.AWS_Data_Id__c.value = ' + data.AWS_Data_Id)
|
// let that = this;
|
// // if(!this.staticResourceContact || !this.staticResourceContact.query) {
|
// console.log('enter connectedCallback')
|
|
// await getPIPLInfo().then((r) => {
|
// r = JSON.parse(JSON.stringify(r));
|
// console.log('r = ' + JSON.stringify(r))
|
// if (r.status == 'Success') {
|
// this.staticResourceContact = JSON.parse(r.entity.staticResourceContact);
|
// console.log('this.staticResourceContact.searchUrl = ' + this.staticResourceContact.searchUrl)
|
// console.log('this.staticResourceContact.queryUrl'+this.staticResourceContact);
|
// this.AWSService.query(this.staticResourceContact.queryUrl, data.AWS_Data_Id, function (dataAWS) {
|
// console.log('queryLeadFromAWSIFS data = ' + JSON.stringify(dataAWS));
|
// if (dataAWS.object) {
|
// //data.fields.Name.value = dataAWS.object['lastName'];
|
// that.record = data;
|
// console.log('that.record = ' + JSON.stringify(that.record));
|
// that.error = undefined;
|
// that.valueObj = dataAWS.object['lastName'];
|
// that.href = '/' + that.record.id;
|
// that.isValue = true;
|
// } else {
|
// that.record = data;
|
// that.error = undefined;
|
// that.valueObj = that.record.Name;
|
// that.href = '/' + that.record.id;
|
// that.isValue = true;
|
// }
|
// // agencyContactNameTmp = that.valueObj;
|
// // console.log('agencyContactName' +that.valueObj);
|
// // console.log('this.agencyContactName:' +this.agencyContactName);
|
// }, this.staticResourceContact.token)
|
// } else {
|
// console.log('error msg = ' + r.msg)
|
// }
|
// })
|
|
|
// } else {
|
// this.record = data;
|
// this.error = undefined;
|
// this.valueObj = this.record.Name;
|
// this.href = '/' + this.record.id;
|
// this.isValue = true;
|
// // agencyContactNameTmp = this.valueObj;
|
// }
|
// // this.valueObj = agencyContactNameTmp;
|
// // console.log('this.valueObj:'+this.valueObj);
|
// //deloitte-zhj 解密 2023/07/19 end
|
//deloitte-亚楠 20240120 PIPL还原 end
|
} else if (error) {
|
this.error = error;
|
this.record = undefined;
|
}
|
}
|
|
|
|
|
handleClick() {
|
console.log("In handleClick");
|
if(this.disabled){
|
return;
|
}
|
if(!this.filter) {
|
this.showToast('Error','请设定访问场所');
|
return;
|
}
|
this.searchTerm = '';
|
this.inputClass = 'slds-has-focus';
|
this.isOpen = true;
|
//deloitte-zhj refresh wiredRecords start
|
this.searchTerm = 'refresh';
|
this.searchTerm = '';
|
refreshApex(this.wiredRecords);
|
//deloitte-zhj refresh wiredRecords end
|
// this.boxClass = 'slds-combobox slds-dropdown-trigger slds-dropdown-trigger_click slds-has-focus slds-is-open';
|
}
|
|
onSelect(event) {
|
console.log("In onSelect");
|
let ele = event.currentTarget;
|
let selectedId = ele.dataset.id;
|
let key = this.uniqueKey;
|
console.log("key = " + key);
|
console.log("selectedId = " + selectedId);
|
const valueSelectedEvent = new CustomEvent('valueselect', {
|
detail: { selectedId, key },
|
});
|
this.dispatchEvent(valueSelectedEvent);
|
this.isOpen = false;
|
// this.boxClass = 'slds-combobox slds-dropdown-trigger slds-dropdown-trigger_click slds-has-focus';
|
}
|
|
searchChange(event) {
|
this.searchTerm = event.target.value;
|
}
|
|
onBlur() {
|
if (!this.isCanCanle) {
|
return;
|
}
|
this.isOpen = false;
|
// this.boxClass = 'slds-combobox slds-dropdown-trigger slds-dropdown-trigger_click slds-has-focus';
|
}
|
@api
|
handleRemovePill() {
|
if(this.disabled){
|
return;
|
}
|
console.log("In handleRemovePill");
|
this.isValue = false;
|
let selectedId = '';
|
let key = this.uniqueKey;
|
const valueSelectedEvent = new CustomEvent('valueselect', {
|
detail: { selectedId, key },
|
});
|
this.dispatchEvent(valueSelectedEvent);
|
}
|
|
newObject() {
|
if(!this.filter) {
|
this.showToast('Error','请设定访问场所');
|
return;
|
}
|
this.clearDailog();
|
this.isOpen = false;
|
this.showModal = true;
|
// const newEvent = new CustomEvent('newrecord', {
|
// detail: { key :this.uniqueKey},
|
// });
|
// this.dispatchEvent(newEvent);
|
}
|
closeModal() {
|
console.log('closeModal');
|
|
this.showModal = false;
|
}
|
handleMouseleave() {
|
this.isCanCanle = true;
|
}
|
handleMouseenter(event) {
|
this.isCanCanle = false;
|
}
|
sureSave(event) {
|
event.preventDefault();//很重要 如果没得这个会导致页面刷新!
|
console.log('submitDetails');
|
let flag = true;
|
let requiredFieldList = this.template.querySelectorAll('lightning-input-field');
|
requiredFieldList.forEach(ele => {
|
if (ele.required == true && this.stringIsEmpty(ele.value)) {
|
ele.reportValidity();
|
flag = false;
|
}
|
});
|
//deloitte-亚楠 20240120 PIPL还原
|
// if(!this.AWSService) {
|
// this.AWSService = new AWSService();
|
// }
|
console.log(flag);
|
console.log('this.theContact = ' + JSON.stringify(this.theContact));
|
if (flag) {
|
//deloitte-亚楠 20240120 PIPL还原 start
|
let that = this;
|
saveContact({
|
contactJson: JSON.stringify(that.theContact)
|
}).then(result => {
|
if (result.code === 200) {
|
that.showToast('success', '保存成功');
|
let selectedId = result.msg;
|
let key = that.uniqueKey;
|
const valueSelectedEvent = new CustomEvent('valueselect', {
|
detail: { selectedId, key },
|
});
|
that.dispatchEvent(valueSelectedEvent);
|
that.isOpen = false;
|
} else {
|
that.showToast('error', '保存联系人失败,' + result.msg);
|
}
|
that.showModal = false;
|
})
|
.catch(error => {
|
that.showToast('error', '保存报错,' + error);
|
that.showModal = false;
|
});
|
// let payloadForNewPI = [];
|
// let PIData = {};
|
// PIData['lastName'] = this.theContact['LastName']
|
// PIData['phone'] = this.theContact['Phone']
|
// payloadForNewPI.push(PIData);
|
// payloadForNewPI = JSON.stringify(payloadForNewPI);
|
// console.log('payloadForNewPI = ' + payloadForNewPI)
|
// // console.log('this.theContact[AccountId] = ' + this.theContact['AccountId'])
|
// // this.theContact['AccountId'] = this.newContactAcc;
|
// // console.log('this.theContact[AccountId] = ' + this.filter);
|
// let that = this;
|
// //deloitte-zhj 新建判断重复并且进行加密 2023/07/19 start
|
// if(!this.theContact['AccountId']) {
|
// this.theContact['AccountId'] = this.filter;
|
// }
|
// console.log('AccountId:' +this.theContact['AccountId'])
|
// console.log('visitorPlaceId:' +this.filter)
|
// searchContactByAccountId({
|
// accountId: this.theContact['AccountId'],
|
// visitorPlaceId:this.filter
|
|
// }).then((resultAccount) => {
|
// resultAccount = JSON.parse(JSON.stringify(resultAccount));
|
// console.log('resultAccount:'+resultAccount);
|
// if (resultAccount.status == 'fail') {
|
// that.showToast('Error', resultAccount.message);
|
// console.log()
|
// return
|
// }
|
// let accountName = resultAccount.accountName;
|
// let dataIdManageCodeMap = resultAccount.dataIdManageCodeMap;
|
// let contactList = '';
|
// for (var i = 0; i < resultAccount.contactList.length; i++) {
|
// if (resultAccount.contactList[i].AWS_Data_Id__c)
|
// contactList += ',' + resultAccount.contactList[i].AWS_Data_Id__c;
|
// }
|
// contactList = contactList.substring(1);
|
// payloadForNewPI = JSON.parse(payloadForNewPI);
|
// payloadForNewPI[0].contactIds = contactList;
|
// payloadForNewPI[0].isMobileVerif = resultAccount.isMobileVerif;
|
// payloadForNewPI[0].isNameMobileVerif = resultAccount.isNameMobileVerif;
|
// payloadForNewPI = JSON.stringify(payloadForNewPI);
|
// //AWS加密
|
// that.AWSService.post(that.staticResourceContact.newUrl + 'V2', payloadForNewPI, (resultAWS) => {
|
// if (resultAWS && resultAWS.object) {
|
// //判断已存在相同名字的联系人
|
// let errorMsg = '';
|
// if (resultAWS.status == '129') {
|
// errorMsg = '客户 [ ' + accountName + ' ],已存在相同名字的联系人 人员管理编码 [' + dataIdManageCodeMap[resultAWS.object[0].dataId] + ' ] ,不能重复创建,请了解';
|
// that.showToast('Error',errorMsg)
|
// return
|
// }
|
// if (resultAWS.status == '130') {
|
// if (resultAWS.object[0] && resultAWS.object[0].sfRecordId != null && resultAWS.object[0].sfRecordId != '') {
|
// errorMsg = '已找到重复值: UniqueNumber__c 与记录值重复,ID 为: ' + resultAWS.object[0].sfRecordId + '客户人员信息';
|
// }
|
// else {
|
// errorMsg = '数据中存在重复的电话号码';
|
// }
|
// that.showToast('Error',errorMsg)
|
// return
|
// }
|
// console.log('resultAWS = ' + JSON.stringify(resultAWS));
|
// that.theContact['LastName'] = resultAWS.object[0]['lastName'];
|
// that.theContact['Phone'] = resultAWS.object[0]['phone'];
|
// that.theContact['AWS_Data_Id__c'] = resultAWS.object[0]['dataId'];
|
// that.txId = resultAWS.txId;
|
// console.log('that.theContact = ' + that.theContact)
|
// //保存到后端
|
// saveContact({ contactJson: JSON.stringify(that.theContact) })
|
// .then(result => {
|
// if (result.code === 200) {
|
// //deloitte-zhj 新建判断重复并且进行加密成功之后需要进行事务确认 2023/07/19 start
|
// that.AWSService.confirm(true, result.msg, that.txId, that.staticResourceContact.token, that.staticResourceContact.transactionUrl, function (resultConfirm) {
|
// console.log('resultConfirm = ' + JSON.stringify(resultConfirm))
|
// that.showToast('success', '保存成功');
|
// let selectedId = result.msg;
|
// let key = that.uniqueKey;
|
// const valueSelectedEvent = new CustomEvent('valueselect', {
|
// detail: { selectedId, key },
|
// });
|
// that.dispatchEvent(valueSelectedEvent);
|
// that.isOpen = false;
|
// });
|
// //deloitte-zhj 新建判断重复并且进行加密成功之后需要进行事务确认 2023/07/19 end
|
// } else {
|
// that.showToast('error', '保存联系人失败,' + result.msg);
|
// }
|
// that.showModal = false;
|
// })
|
// .catch(error => {
|
// that.showToast('error', '保存报错,' + error);
|
// that.showModal = false;
|
// });
|
// } else {
|
// console.log('result = ' + JSON.stringify(result));
|
// }
|
// }, that.staticResourceContact.token);
|
// });
|
// //deloitte-zhj 新建判断重复并且进行加密 2023/07/19 end
|
//deloitte-亚楠 20240120 PIPL还原 end
|
}
|
}
|
stringIsEmpty(str) {
|
if (str === '' || str === undefined || str === null) {
|
return true;
|
} else {
|
return false;
|
}
|
}
|
|
showToast(type,msg) {
|
if(type == 'success'){
|
const event = new ShowToastEvent({
|
message: msg,
|
variant: type
|
});
|
this.dispatchEvent(event);
|
}else{
|
const event = new ShowToastEvent({
|
message: msg,
|
variant: type,
|
mode: 'sticky'
|
});
|
this.dispatchEvent(event);
|
}
|
}
|
//字段信息改变
|
async fieldChange(event) {
|
const { value } = event.detail;
|
const { fieldName } = event.target || event.currentTarget;
|
let checked = event.target.value || event.currentTarget.value;
|
if (value == undefined && checked != undefined) {
|
this.theContact[fieldName] = checked;
|
} else {
|
this.theContact[fieldName] = value instanceof Array ? value[0] : value;
|
}
|
}
|
//清空新建窗口的输入框
|
clearDailog() {
|
this.theContact['Name'] = null;
|
this.theContact['Phone'] = null;
|
this.theContact['AccountId'] = this.filter;
|
}
|
}
|