/*
|
* @Description:
|
* @version:
|
* @Author: chen jing wu
|
* @Date: 2023-05-25 13:59:44
|
* @LastEditors: chen jing wu
|
* @LastEditTime: 2023-09-27 15:30:05
|
*/
|
import { LightningElement, track, api } from 'lwc';
|
import getRecordsByName from '@salesforce/apex/lexLookupController.getRecordsByName'
|
|
export default class LexLookupLwc extends LightningElement {
|
@api
|
objectname;
|
@api
|
queryBrand;
|
@track
|
recordsList;
|
@track
|
selectedValue = "";
|
error;
|
@track
|
recordselected = false;
|
@api
|
iconname;
|
@api
|
initValue;
|
disabled = false;
|
//Method to query data after typing search term
|
onKeyChange(event) {
|
this.selectedValue = event.target.value;
|
if(this.queryBrand == undefined){
|
this.queryBrand = '';
|
}
|
getRecordsByName({objectName : this.objectname, searchFor : this.selectedValue, queryBrand : this.queryBrand})
|
.then(result => {
|
this.recordsList = result;
|
})
|
.catch(error => {
|
//exception handling
|
this.error = error;
|
})
|
|
}
|
connectedCallback(){
|
|
if(this.initValue != '' && this.initValue != undefined && this.initValue != null){
|
this.recordselected = true;
|
this.selectedValue = this.initValue;
|
}
|
}
|
|
|
@api
|
letDisabledTrue(){
|
this.recordselected = false;
|
this.disabled = true;
|
this.selectedValue = "";
|
this.recordsList = undefined;
|
}
|
@api
|
letDisabledFalse(){
|
this.recordselected = false;
|
this.disabled = false;
|
this.selectedValue = "";
|
this.recordsList = undefined;
|
}
|
//Method to clear search list and show selected value.
|
@api
|
clearSelection() {
|
console.log('qwer');
|
this.recordselected = false;
|
this.selectedValue = "";
|
this.recordsList = undefined;
|
const customEvent = new CustomEvent('buttonclick', {
|
bubbles: true, // 使事件冒泡
|
composed: true // 使事件可以跨shadow boundary传播
|
});
|
this.dispatchEvent(customEvent);
|
}
|
|
//Method to pass selected record to parent component.
|
setSelectedValue(event) {
|
this.selectedValue = event.target.dataset.itemname;
|
this.recordselected = true;
|
this.recordsList = undefined;
|
event.preventDefault();
|
const selectedEvent = new CustomEvent('selected', {
|
detail: {
|
Name : this.selectedValue,
|
Id : event.target.dataset.itemid,
|
ObjectName : this.objectname
|
}
|
});
|
this.dispatchEvent(selectedEvent);
|
}
|
clear(){
|
this.recordsList = undefined;
|
}
|
}
|