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
import { LightningElement,api, track } from 'lwc';
 
export default class JzSearchForm extends LightningElement {
    @api name;
    @api options = [];
 
    connectedCallback(){
        this.initJzSearchForm(this.options);
    }
 
    /**
     * 初始化搜索控件内容
     * [
     *  {
     *      label: 描述值 必填
     *      type: isInput:为true时与Lwc input 中类型一致,其它可为不填
     *      name: 控件名称 - 用与搜索中传入后台的参数名 必填
     *      value: 控件默认值 
     *      isInput: 为true时,显示Lwc中input框 
     *      isCombobox: 为true时,显示Lwc中lightning-combobox下拉框
     *      options: 为Combobox时,填写下拉框值 [{label: 'New', value: 'new'},...]
     *  },
     *  ...
     * ]
     * of jzSearchFormConfig
     */
    @track jzSearchFormConfig = [];
    @track searchParams = {};
 
    initJzSearchForm(init){
        let temp = [];
        init.forEach((item,index)=>{
            temp.push({...item});
            if(item.value)this.searchParams[item.name] = item.value;
            if(item.isCombobox) temp[index].options = [{label: '全部', value: ''}, ...item.options];
        })
        this.jzSearchFormConfig = temp;
    }
 
    // 值改变
    handleChange(event) {
        const name = event.target.name;
        this.searchParams[name] = event.target.value;
    }
 
    // 点击搜索获取搜索框中数据
    searchData(event) {
        // Prevent default behavior of anchor tag click which is to navigate to the href url
        event.preventDefault();
        const getSearchParamsEvent = new CustomEvent('getsearchparams', {
            detail: {searchParams: this.searchParams}
        });
        this.dispatchEvent(getSearchParamsEvent);
    }
 
}