TableHeadSearch.vue
2.7 KB
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
<!-- 表格头部搜索 -->
<template>
<el-popover
placement="bottom"
title=""
width="150"
trigger="click"
v-model="isPopoverVisible"
>
<block>
<p class="flex">
<el-checkbox
:indeterminate="isIndeterminate"
v-model="checkAll"
@change="handleCheckAllChange"
>全选</el-checkbox>
<el-button
@click="handleConfirm"
type="text"
>确定</el-button>
</p>
<el-checkbox-group
v-model="checkedList"
@change="handleCheckedChange"
>
<el-checkbox
v-for="item in baseData[optionConfig.searchItemName]"
:label="item[optionConfig.optionId]"
:key="item[optionConfig.optionId]"
@change="handleCheckedChange"
>{{item[optionConfig.optionLabel]}}</el-checkbox>
</el-checkbox-group>
</block>
<img
slot="reference"
class="head-search"
src="./image/search.png"
@click="handleOpen"
/>
</el-popover>
</template>
<script>
import _ from 'lodash'
export default {
name: 'TableHeadSearch',
data() {
return {
isPopoverVisible: false,
checkAll: false,
checkedList: [],
isIndeterminate: false
}
},
props: {
// 原来的model值
searchForm: {
type: Array,
default: () => { }
},
optionConfig: {
type: Object,
default: () => { }
},
// 多选列表
// optionList: {
// type: Array,
// default: () => []
// },
// 多选列表Obj
baseData: {
type: Object,
default: () => { }
}
},
methods: {
handleOpen() {
this.checkedList = _.cloneDeep(this.searchForm[this.optionConfig.searchItemName])
this.handleCheckedChange(this.checkedList)
this.$nextTick()
},
handleCheckedChange(value) {
const checkedCount = value.length
this.checkAll = checkedCount === this.baseData[this.optionConfig.searchItemName].length
this.isIndeterminate = checkedCount > 0 && checkedCount < this.baseData[this.optionConfig.searchItemName].length
},
handleCheckAllChange(val) {
this.checkedList = val ? this.baseData[this.optionConfig.searchItemName].map(item => item[this.optionConfig.optionId]) : []
this.isIndeterminate = false
},
handleConfirm() {
this.isPopoverVisible = false
this.$emit('handleTableHeadChange', { searchItemName: this.optionConfig.searchItemName, checkedList: this.checkedList })
}
}
}
</script>
<style scoped>
.flex {
justify-content: space-between;
}
.head-search {
width: 12px;
height: 12px;
}
</style>