index.vue
2.26 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
<template>
<z-form v-model="model" class="zee-filter" :list="formattedList" :span="span" :labelWidth="labelWidth" :colClass="colVisibleRender" :size="size" :formProps="formProps">
<div slot="$operation" class="zee-filter__button-group">
<el-button-group :size="size">
<el-button type="primary" @click="handleSearch" :loading="loading" icon="el-icon-search"><span>查询</span></el-button>
<el-button @click="handleReset"><span>重置</span></el-button>
<el-button v-if="showCollapsed" @click="collapsed = !collapsed">
<span>{{ collapsed ? '展开' : '收起' }}</span>
</el-button>
</el-button-group>
</div>
</z-form>
</template>
<script>
export default {
name: 'Filter',
props: {
value: Object,
list: Array,
labelWidth: {
type: String,
default: '80px',
},
size: {
type: String,
default: 'small',
},
span: {
type: Number,
default: 6,
},
visibleNum: {
type: Number,
default: 3,
},
loading: Boolean,
formProps: {
type: Object,
default: () => ({}),
},
},
data() {
return {
collapsed: true,
model: this.value || {},
};
},
watch: {
value(val = {}) {
this.model = val;
},
model(val) {
this.$emit('input', val);
},
},
computed: {
formattedList() {
return [...this.list, { key: '$operation', label: '', labelWidth: '0px', span: !this.collapsed ? 24 : undefined }];
},
showCollapsed() {
const { list, visibleNum } = this;
return list.length > visibleNum;
},
},
methods: {
// 渲染列表项class
colVisibleRender(item, index) {
if (this.collapsed) {
const visibleNumber = this.visibleNum ? this.visibleNum - 1 : 2;
return index > visibleNumber && index < this.list.length ? 'zee-filter__item hidden' : 'zee-filter__item';
}
return 'zee-filter__item';
},
// 搜索
handleSearch() {
this.$emit('search', this.model);
},
// 重置
handleReset() {
this.model = {};
this.$emit('reset');
},
},
};
</script>
<style>
.zee-filter__item.hidden {
display: none;
}
.zee-filter__button-group {
width: 100%;
box-sizing: border-box;
text-align: right;
}
</style>