import { LightningElement,api, track } from 'lwc'; export default class jzlookup extends LightningElement { connectedCallback(){ this.changeSearchData(); setInterval(()=>{ this.searchchangeRefresh(); },400); } renderedCallback(){ if (this.disabled == true) { var inputs = this.template.querySelectorAll('lightning-input'); inputs.forEach(fileInput=>{ fileInput.disabled = true; }) } } //加载 IsLoading = false; OnLoading(flag){ this.IsLoading = flag; } @api name='' @api option = [] @api searchdata=[]; @api label = '' @api placeholder = '' @track InputValue = ''; @api disabled= false; ShowData = [] isShow = false; searchClick(event) { this.isShow= true; } onblurFn(event) { const getSearchParamsEvent = new CustomEvent('clear', { detail: {} }); this.dispatchEvent(getSearchParamsEvent); setTimeout(()=>{ this.isShow= false; if (!this.isClick) { this.InputValue = ''; } },300) } changeSearchData() { var TempShowData= []; this.searchdata.forEach(item=>{ var temp = {}; this.option.forEach(option=>{ temp.value1 = item[option.lableOne]; temp.value2 = item[option.lableTwo]; }) temp.Id = item.Id; TempShowData.push(temp); }) this.ShowData = [...[],...TempShowData]; setTimeout(()=>{ this.OnLoading(false); },1000); } ifFlag = false; //搜索输入 searchchange(event) { this.OnLoading(true); var values = event.target.value; this.InputValue = values; this.isClick = false; } oldSearchContent = ''; searchchangeRefresh() { if (this.oldSearchContent === this.InputValue ) { return; }else{ this.oldSearchContent = this.InputValue ; } const getSearchParamsEvent = new CustomEvent('searchchange', { detail: {searchContent:this.InputValue} }); this.dispatchEvent(getSearchParamsEvent); } isClick = false; //选项列表点击 itemclick(event) { var Id = event.target.dataset.id; var tempData = {}; this.searchdata.forEach(item=>{ if (item.Id == Id) { tempData = {...{},...item}; } }) this.InputValue = tempData[this.option[0].lableOne] == undefined?"":tempData[this.option[0].lableOne]; const getSearchParamsEvent = new CustomEvent('selected', { detail: {selectdata:tempData,name:this.name} }); this.dispatchEvent(getSearchParamsEvent); this.isShow= false; this.isClick = true; } @api refreshdata(data){ if (data!=undefined) { this.IsZero = false; this.searchdata = [...[],...data]; this.changeSearchData(); } } @api setvalue(data){ this.InputValue=data; } @api getvalue(){ return this.InputValue; } IsZero = false; @api iszero(){ this.OnLoading(false); this.IsZero = true; } }