import { LightningElement, api, track } from 'lwc'; //import searchContactInit from '@salesforce/apex/LexNewAndEditLeadPIPLController.searchContactInit'; //import searchContactInitV2 from '@salesforce/apex/LexNewAndEditLeadPIPLController.searchContactInitV2'; import getObjectInfo from '@salesforce/apex/LexSearchLookupController.getObjectInfo'; import searchContactInit from '@salesforce/apex/LexNewAndEditLeadPIPLController.searchContactInit'; //import getContactAWS from '@salesforce/apex/LexNewAndEditLeadPIPLController.getContactAWS';//getNoPIContact //import getNoPIContact from '@salesforce/apex/LexNewAndEditLeadPIPLController.getNoPIContact'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; // import { AWSService } from 'c/piUtils'; const contactColumns = [ { label: "选择", fieldName: "sfRecordId", type: "button", initialWidth: 120, hideDefaultActions: true, typeAttributes: { label: "选择", name: "sfRecordId", size: 1, }, }, { label: "姓名", fieldName: "medicalStaffFullName", initialWidth: 120, hideDefaultActions: true, wrapText: true, }, { label: "客户名称", fieldName: "accountName", hideDefaultActions: true, wrapText: true, }, { label: "邮箱", fieldName: "email", hideDefaultActions: true, wrapText: true, }, { label: "电话", fieldName: "phone", hideDefaultActions: true, wrapText: true, }, { label: "手机号", fieldName: "mobilePhone", hideDefaultActions: true, wrapText: true, }, ]; export default class LexSearchLookupLWC extends LightningElement { @track isLoading = true; @api title; @api searchNameLabel; @api accountId = ''; @api provinceId; @api hospitalId; @api searchType = 'Contact' @api searchNameValue = ''; @track awsIdToContactMap = []; @track conAWSIds = []; @track contactStaticResource = ''; @track data = []; @track noPIContactList = []; @track columns = []; //查询字段数组 @api searchFieldArray = []; //查询where条件 @api searchWhere; //搜索条件字段 @api searchField; //查询对象api @api sobjectType; connectedCallback() { console.log('searchFieldArray = ' + this.searchFieldArray); console.log('searchField = ' + this.searchField); // if (this.searchFieldArray == null || this.searchField == null) { // this.showToast('Error', '初始化失败'); // return // } // this.AWSService = new AWSService(); console.log('成功进入 searchLookupLwc'); console.log('this.accountId = ' + this.accountId); console.log('this.searchNameValue = ' + this.searchNameValue); console.log('this.sobjectType = ' + this.sobjectType); if (this.sobjectType == 'Contact') { this.columns = contactColumns; } else { this.columns = [ { label: "选择", fieldName: "id", type: "button", initialWidth: 120, hideDefaultActions: true, typeAttributes: { label: "选择", name: "id", size: 1, }, }, ] } this.searchContacts(); } searchContacts() { console.log('enter searchContact'); console.log('this.accountId:' + this.accountId); console.log('this.searchNameValue:' + this.searchNameValue); this.isLoading = true; let that = this; if (this.sobjectType == 'Contact') { this.data = []; debugger searchContactInit({ accountId: this.accountId + '', searchKeyWord: this.searchNameValue }).then((r) => { r = JSON.parse(JSON.stringify(r)); this.data = []; if (r.status == 'Success') { for (var i in r.entity.conList) { let info = new Object(); info.sfRecordId = r.entity.conList[i].Id; info.accountName = r.entity.conList[i].Account.Name; info.medicalStaffFullName = r.entity.conList[i].Name; info.email = r.entity.conList[i].Email; info.phone = r.entity.conList[i].Phone; info.mobilePhone = r.entity.conList[i].MobilePhone; that.data.push(info); } that.data = [...that.data]; } else { this.showToast('Error', r.msg); } this.isLoading = false; }).catch(err => { console.log(err); }); } else { this.searchLookupInfo(); } } searchLookupInfo() { getObjectInfo({ objectName: this.sobjectType, searchFieldArray: this.searchFieldArray, searchWhere: this.searchWhere, searchField: this.searchField, searchNameValue: this.searchNameValue }).then((r) => { r = JSON.parse(JSON.stringify(r)); console.log('r = ' + JSON.stringify(r)); console.log('this.searchFieldArray=====' + this.searchFieldArray); if (r.status == 'Success') { console.log('getObjectInfo success'); let fieldName = Object.keys(r.entity.fieldMapWithLabels); console.log('fieldName=====' + fieldName); //构建colums let fieldInfo = r.entity.fieldMapWithLabels; let tempList = []; fieldName.forEach(name => { let tempColumns = { label: fieldInfo[name], fieldName: name, initialWidth: 160, hideDefaultActions: true, wrapText: true, }; tempList.push(tempColumns); console.log('tempColumns=====' + JSON.stringify(tempColumns)); }) this.columns = [...this.columns, ...tempList]; this.data = r.entity.objectInfo; this.data.forEach(data => { if (data.Account) { data.Account = data.Account.Name; } let datakey = Object.keys(data); datakey.forEach(key => { if (key.includes('__r')) { console.log('data[key].Name:', data[key].Name); data[key] = data[key].Name; } }) }) console.log('data=====' + JSON.stringify(this.data)); this.isLoading = false; } else { this.showToast('Error', r.msg); } }) .catch(error => { console.log('error:', JSON.stringify(error)); }) } dataChange(event) { let fieldName = event.target.getAttribute("data-field"); let value = event.detail.value; console.log("fieldName = " + fieldName + " value = " + event.detail.value); switch (fieldName) { case "searchNameDataField": this.searchNameValue = value; break; } } closeModal() { this.dispatchEvent(new CustomEvent('close', {})); } searchHandleRowAction(event) { debugger let row = event.detail.row; console.log('row = ' + JSON.stringify(row)); if (this.sobjectType == 'Contact') { let sfRecordId = row.sfRecordId; let medicalStaffFullName = row.medicalStaffFullName; let phone = row.phone; let email = row.email; let mobilePhone= row.mobilePhone; this.dispatchEvent(new CustomEvent('selectcontact', { composed: true, bubbles: true, cancelable: true, detail: { data: { sfRecordId: sfRecordId, medicalStaffFullName: medicalStaffFullName, phone: phone, email: email, mobilePhone: mobilePhone } } })); } else { let Id = row.Id; let Name = row.Name; this.dispatchEvent(new CustomEvent('selectlookup', { composed: true, bubbles: true, cancelable: true, detail: { data: { Id: Id, Name: Name } } })); } } showToast(type, msg) { this.isLoading = false; const event = new ShowToastEvent({ title: type, variant: type, message: msg }); this.dispatchEvent(event); } }