TableHeadSearch.vue
2.86 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
<!-- 表格头部搜索 -->
<template>
<el-popover v-model="isPopoverVisible"
placement="bottom"
title=""
width="150"
trigger="click">
<template>
<p class="flex">
<el-checkbox v-model="checkAll"
:indeterminate="isIndeterminate"
@change="handleCheckAllChange">
全选
</el-checkbox>
<el-button type="text"
@click="handleConfirm">
确定
</el-button>
</p>
<el-checkbox-group v-model="checkedList"
@change="handleCheckedChange">
<el-checkbox v-for="item in baseData[optionConfig.searchItemName]"
:key="item[optionConfig.optionId]"
:label="item[optionConfig.optionId]"
@change="handleCheckedChange">
{{ item[optionConfig.optionLabel] }}
</el-checkbox>
</el-checkbox-group>
</template>
<template #reference>
<img class="head-search"
src="./image/search.png"
@click="handleOpen">
</template>
</el-popover>
</template>
<script>
// import _ from 'lodash'
import { deepClone } from "@/common/util";
export default {
name: "TableHeadSearch",
props: {
// 原来的model值
searchForm: {
type: Object,
default: () => { },
},
optionConfig: {
type: Object,
default: () => { },
},
// 多选列表
// optionList: {
// type: Array,
// default: () => []
// },
// 多选列表Obj
baseData: {
type: Object,
default: () => { },
},
},
data() {
return {
isPopoverVisible: false,
checkAll: false,
checkedList: [],
isIndeterminate: false,
};
},
methods: {
handleOpen() {
this.checkedList = deepClone(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>