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; LodingText = '' OnLoading(flag,value=''){ this.LodingText = value; this.IsLoading = flag; } @api name='' @api option = [] @api searchdata=[]; @api label = '' @api placeholder = '' @track InputValue = ''; @api disabled= false; ShowData = [] isShow = false; searchClick(event) { //判断是否禁用 if(this.ondisabledShow) { return; } //判断值是否有变化 if(this.itemClickValue == this.InputValue && this.InputValue != undefined && this.InputValue!='') { return; } if(this.InputValue == undefined || this.InputValue == '' ) { this.isShow= true; this.OnLoading(true,"搜索中..."); const getSearchParamsEvent = new CustomEvent('searchclick', { detail: {} }); this.dispatchEvent(getSearchParamsEvent); return; } this.isShow= true; } onblurFn(event) { setTimeout(()=>{ if (!this.isClick) { const getSearchParamsEvent = new CustomEvent('clear', { detail: {} }); this.dispatchEvent(getSearchParamsEvent); } this.isShow= false; //判断值是否有变化 if(this.itemClickValue == this.InputValue) { return; } if (!this.isClick) { this.InputValue = ''; } },400) } refreshCount = 0; changeSearchData() { this.refreshCount ++; console.warn(this.refreshCount +" == "+ this.searchCount); if (this.refreshCount > this.searchCount) { this.refreshCount = this.searchCount; } if (this.refreshCount < this.searchCount) { return; } 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(()=>{ if (this.ShowData.length<1) { this.OnLoading(true,"暂无数据"); }else{ this.OnLoading(false,""); } },300); } ifFlag = false; searchCount = 0; //搜索输入 searchchange(event) { this.isClick = false; var values = event.target.value; //判断值是否有变化 if(this.itemClickValue == values) { return; } if (values.length >= 3) { this.isShow= true; this.OnLoading(true,"搜索中..."); this.InputValue = values; this.searchchangeRefresh(); this.searchCount++; } } oldSearchContent = ''; searchchangeRefresh() { const getSearchParamsEvent = new CustomEvent('searchchange', { detail: {searchContent:this.InputValue} }); this.dispatchEvent(getSearchParamsEvent); } isClick = false; itemClickValue = ''; //选项列表点击 itemclick(event,id) { if(this.isIconClick) { return; } var Id; if (id!=undefined) { Id = id; }else{ 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]; this.itemClickValue = this.InputValue; const getSearchParamsEvent = new CustomEvent('selected', { detail: {selectdata:tempData,name:this.name} }); this.dispatchEvent(getSearchParamsEvent); this.isShow= false; this.isClick = true; } isIconClick = false; iconclick(event) { this.itemclick(null,event.target.title); this.isIconClick = true; setTimeout(() => { this.isIconClick = false; }, 200); } @api refreshdata(data){ if (data!=undefined) { this.IsZero = false; this.searchdata = [...[],...data]; this.changeSearchData(); } } @api setvalue(data){ this.InputValue=data; this.itemClickValue = this.InputValue; } @api getvalue(){ return this.InputValue; } IsZero = false; @api iszero(){ this.OnLoading(false); this.IsZero = true; } ondisabledShow = false; @api todisabled() { var inputs = this.template.querySelectorAll('lightning-input'); inputs.forEach(inputFile=>{ inputFile.disabled = true; }) this.ondisabledShow = true; } }