import lookUp from '@salesforce/apex/otherLookUp.lookUp';
|
import getRecordForLwc from '@salesforce/apex/ControllerUtil.getRecordForLwc';
|
import { getRecord } from 'lightning/uiRecordApi';
|
import { NavigationMixin } from 'lightning/navigation';
|
import { api, LightningElement, track, wire } from 'lwc';
|
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
|
import { refreshApex } from '@salesforce/apex';
|
|
export default class OtherLookUp extends NavigationMixin(LightningElement) {
|
AWSService;
|
@track theContact = {};
|
@track showModal = false;
|
//记录id
|
@api valueId;
|
@api objName;
|
@api visitPlaceId ='';
|
@api iconName;
|
@api disabled;
|
@api filter = '';
|
@api uniqueKey;
|
@api fields;
|
@api searchLabel;
|
@track searchTerm;
|
@track valueObj;
|
@track href;
|
@track options;
|
//是否展示pill
|
@track isValue = false;
|
isCanCanle = true;
|
@track blurTimeout;
|
isOpen = false;
|
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;
|
}
|
@track inputClass = '';
|
|
@wire(lookUp, { searchTerm: '$searchTerm', objName: '$objName', filter: '$filter',visitPlaceId:'$visitPlaceId'})
|
wiredRecords({ error, data }) {
|
console.log('searchTerm = '+ this.searchTerm);
|
console.log('objName = '+ this.objName);
|
console.log('filter = '+ this.filter);
|
console.log('visitPlaceId,'+this.visitPlaceId);
|
|
if(this.visitPlaceId) {
|
console.log('lookUp,visitPlaceId,'+this.visitPlaceId);
|
}
|
|
if (data) {
|
this.record = data;
|
this.error = undefined;
|
this.options = this.record;
|
console.log("common this.options", JSON.stringify(this.options));
|
} else if (error) {
|
this.error = error;
|
this.record = undefined;
|
console.log("wire.error",this.error);
|
}
|
|
|
}
|
|
//To get preselected or selected record
|
// @wire(getRecord, { recordId: '$valueId', fields: '$fields' })
|
// wiredOptions({ error, data }) {
|
// console.log('otherlookup wiredOptions:recordId:'+this.valueId);
|
// if(this.visitPlaceId) {
|
// console.log('getRecord,visitPlaceId,'+this.visitPlaceId);
|
// }
|
|
// console.log('getRecord start:');
|
// if (data) {
|
// console.log('execute1');
|
// this.record = data;
|
// this.error = undefined;
|
// this.valueObj = this.record.fields.Name.value;
|
// this.href = '/'+this.record.id;
|
// this.isValue = true;
|
// let selectedId = this.record.id;
|
// let selectedName = this.valueObj;
|
// let key = this.uniqueKey;
|
|
// console.log("this.href", this.href);
|
// console.log("this.record", JSON.stringify(this.record));
|
|
// } else if (error) {
|
// console.log('execute2');
|
// this.error = error;
|
// this.record = undefined;
|
// console.log("this.error", this.error);
|
// }
|
// }
|
|
@wire(getRecordForLwc, { recordId: '$valueId', fields: '$fields' })
|
wiredOptions({ error, data }) {
|
if(!this.valueId) {
|
return;
|
}
|
console.log('otherlookup wiredOptions:recordId:'+this.valueId);
|
if(this.visitPlaceId) {
|
console.log('getRecord,visitPlaceId,'+this.visitPlaceId);
|
}
|
|
console.log('getRecord start:');
|
console.log('getRecord start:fields' +this.fields);
|
if (data) {
|
console.log('execute1');
|
this.record = data;
|
this.error = undefined;
|
this.valueObj = this.record.Name;
|
this.href = '/'+this.record.Id;
|
this.isValue = true;
|
let selectedId = this.record.Id;
|
let selectedName = this.valueObj;
|
let key = this.uniqueKey;
|
|
console.log("this.href", this.href);
|
console.log("this.record", JSON.stringify(this.record));
|
|
} else if (error) {
|
console.log('execute2');
|
this.error = error;
|
this.record = undefined;
|
console.log("this.error", this.error);
|
}
|
}
|
renderedCallback(){
|
console.log('otherlookup renderedCallback:recordId:'+this.valueId);
|
console.log('otherlookup renderedCallback');
|
if(this.disabled) {
|
const allInputsAndButtons = this.template.querySelectorAll('button');
|
|
allInputsAndButtons.forEach(element => {
|
console.log('---------zzzz-------')
|
console.log(element);
|
// if(!element.id.includes('cancleApply')) {
|
element.variant = "plain";
|
// }
|
});
|
}
|
}
|
handleClick() {
|
console.log("In handleClick");
|
if(this.disabled){
|
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 selectedName = this.valueObj;
|
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';
|
}
|
onHover() {
|
// alert(this.disabled);
|
}
|
@api
|
handleRemovePill() {
|
console.log("In handleRemovePill");
|
if(this.disabled){
|
return;
|
}
|
this.isValue = false;
|
let selectedId = '';
|
let key = this.uniqueKey;
|
const valueSelectedEvent = new CustomEvent('valueselect', {
|
detail: { selectedId, key },
|
});
|
this.dispatchEvent(valueSelectedEvent);
|
}
|
closeModal() {
|
console.log('closeModal');
|
this.showModal = false;
|
}
|
handleMouseleave() {
|
this.isCanCanle = true;
|
}
|
handleMouseenter(event) {
|
this.isCanCanle = false;
|
}
|
stringIsEmpty(str) {
|
if (str === '' || str === undefined || str === null) {
|
return true;
|
} else {
|
return false;
|
}
|
}
|
showToast(variant, mes) {
|
const event = new ShowToastEvent({
|
message: mes,
|
variant: variant,
|
});
|
this.dispatchEvent(event);
|
}
|
}
|