import { LightningElement,api, track } from 'lwc'; export default class jzlookup extends LightningElement { connectedCallback(){ this.changeSearchData(); setInterval(()=>{ this.time++; this.searchchangeRefresh(); },1000); } time =0; //加载 IsLoading = false; OnLoading(flag){ this.IsLoading = flag; } @api name='' @api option = [] @api searchdata=[]; @api label = '' @api placeholder = '' @track InputValue = ''; 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 = ''; } },3000) } 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); },3000); } ifFlag = false; //搜索输入 searchchange(event) { this.OnLoading(true); var values = event.target.value; this.InputValue = values; this.isClick = false; this.time = 0; this.inputTiem = 0; this.ifFlag = false; } inputTiem = 0; // oldSearchContent = ''; searchchangeRefresh() { // if (this.oldSearchContent === this.InputValue ) { // return; // }else{ // this.oldSearchContent = this.InputValue ; // } if (this.time - this.inputTiem >= 1) { this.ifFlag = true; this.inputTiem = this.time; 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]; debugger; 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.searchdata = [...[],...data]; if (this.ifFlag) { console.warn("isTrue"); this.ifFlag = false; this.time = -1; this.inputTiem = 0; this.changeSearchData(); } } } @api setvalue(data){ this.InputValue=data; } @api getvalue(){ return this.InputValue; } }