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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<template>
<div class="layout-data-page">
<div class="data-header">
<a-checkbox :indeterminate="indeterminate" :checked="checkAll" @change="onCheckAllChange" /> <span>{{nowSelectKeys.length}} 项</span>
</div>
<div class="data-list-body">
<ul class="data-list-content">
<li v-for="(item,index) in dataList" :key="item.key" @click="onChange(item,index)" class="data-list-content-item">
<input type="checkbox" class="list-checkbox-input" :checked="item.selected">
<span>
<span style="font-size:14px;">{{item.title}}<span style="margin-left:4px;font-style: italic;font-size: 12px;color: #8e99a5;">({{item.description}})</span></span>
</span>
</li>
</ul>
</div>
</div>
</template>
<script>
export default {
name: 'selectItem',
components: {
},
data () {
return {
selectKeys: [],
nowSelectKeys: [],
indeterminate: false,
checkAll: false,
}
},
props: {
value: {
type: Array,
default: () => {
return []
}
},
dataList: {
type: Array,
default: () => {
return []
}
},
},
created () {
this.selectKeys = this.value
this.initData()
},
methods: {
onChange (e) {
e.selected = !e.selected
if (e.selected) {
this.selectKeys.push(e)
} else {
for (let j = 0; j < this.selectKeys.length; j++) {
if (e.key == this.selectKeys[j].key) {
this.selectKeys.splice(j, 1)
break
}
}
}
this.initData()
this.$emit("input", this.selectKeys)
},
onCheckAllChange (e) {
if (e.target.checked) {
for (let i = 0; i < this.dataList.length; i++) {
this.dataList[i].selected = e.target.checked
let state = false;
for (let j = 0; j < this.selectKeys.length; j++) {
if (this.dataList[i].key == this.selectKeys[j].key) {
state = true
break
}
}
if (!state) {
this.selectKeys.push(this.dataList[i])
}
}
}
else {
for (let i = 0; i < this.dataList.length; i++) {
this.dataList[i].selected = e.target.checked
for (let j = 0; j < this.selectKeys.length; j++) {
if (this.dataList[i].key == this.selectKeys[j].key) {
this.selectKeys.splice(j, 1);
}
}
}
}
this.initData()
this.$emit("input", this.selectKeys)
},
initData () {
this.nowSelectKeys = []
for (let i = 0; i < this.dataList.length; i++) {
if (this.dataList[i].selected) {
this.nowSelectKeys.push(this.dataList[i])
}
}
this.indeterminate = !!this.nowSelectKeys.length && this.nowSelectKeys.length < this.dataList.length
this.checkAll = this.nowSelectKeys.length === this.dataList.length && this.nowSelectKeys.length > 0
}
},
watch: {
dataList: {
handler (dataList) {
this.initData()
},
},
}
}
</script>
<style scoped lang="less">
.layout-data-page {
position: relative;
width: 100%;
height: 100%;
vertical-align: middle;
border-radius: 4px;
.data-header {
width: 100%;
height: 40px;
padding: 8px 5px 9px;
overflow: hidden;
color: rgba(0, 0, 0, 0.65);
background: #fff;
border-bottom: 1px solid #e8e8e8;
border-radius: 4px 4px 0 0;
}
.data-list-body {
width: 100%;
height: calc(100% - 40px);
overflow-x: hidden;
overflow-y: auto;
.data-list-content {
height: 100%;
margin: 0;
padding: 0;
overflow: auto;
list-style: none;
}
.data-list-content-item {
position: relative;
height: 24px;
padding: 3px 2px 2px 5px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
transition: all 0.3s;
overflow: hidden;
cursor: pointer;
.list-checkbox-input {
width: 16px;
height: 16px;
cursor: pointer;
}
}
.data-list-content-item:hover {
background-color: rgb(230 247 255);
}
.data-list-content-item > span {
position: absolute;
top: 0;
margin-left: 4px;
}
}
}
</style>