/* * @Description: * @version: * @Author: chen jing wu * @Date: 2023-05-25 13:59:44 * @LastEditors: chen jing wu * @LastEditTime: 2023-11-11 20:06:45 */ import { LightningElement, track, api } from 'lwc'; import getRecordsByName from '@salesforce/apex/lexLookupController.getRecordsByName' import { RefreshEvent } from 'lightning/refresh'; export default class LexLookupLwc extends LightningElement { @api objectname; @api queryBrand; @track recordsList; @track selectedValue = ""; error; @track recordselected = false; @api iconname; @api initValue = ""; initValuetemp = ''; 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; }else{ this.recordselected = false; } } renderedCallback(){ } @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.initValuetemp = this.selectedValue; this.selectedValue = ""; this.initValue = ""; this.recordsList = undefined; const customEvent = new CustomEvent('buttonclick', { bubbles: true, // 使事件冒泡 composed: true // 使事件可以跨shadow boundary传播 }); this.dispatchEvent(customEvent); } @api refresh(){ console.log('you============================'); console.log(this.initValue); console.log(this.selectedValue); console.log('me====================='); // if(this.initValue == '' && this.selectedValue == '' && this.initValuetemp != ''){ // // this.recordselected = true; // this.initValue = this.initValuetemp; // // this.selectedValue = this.initValue; // return; // } if(this.initValue != undefined && this.initValue != null && this.initValue != ''){ // this.recordselected = false; this.recordselected = true; this.selectedValue = this.initValue; }else{ this.selectedValue = ''; this.recordselected = false; } } dontClose(event){ event.preventDefault(); } //Method to pass selected record to parent component. setSelectedValue(event) { this.selectedValue = event.target.dataset.itemname; this.initValue = 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; } }