buli
2023-06-05 e9b970ea36eea5dcf93fd5b965bf13d7010ce0ad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
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;
    }
 
}