MenuCheckbox.vue
2.94 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
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
<template>
<div class="menu-checkbox">
<div class="menu-box">
<div class="menu-title">{{title}}:</div>
<div class="menu-grid">
<template v-for="(i,index) in list">
<div
:class="['item text-center',{'active':i.active}]"
:key="index"
@click="choose(i,index)"
>{{i.text}}</div>
</template>
</div>
</div>
<div class="menu-btn-box">
<van-button
block
round
@click="close(1)"
>
{{showReset?'重置':'取消'}}
</van-button>
<van-button
block
round
color="#3975C6"
@click="confirm"
>
确认
</van-button>
</div>
</div>
</template>
<script type='text/ecmascript-6'>
export default {
name: 'MenuCheckbox',
props: {
single: Boolean,
title: String,
data: {
type: Array,
default: () => []
}
},
data () {
return {
showReset: false,
list: [],
}
},
mounted () {
this.list = this.data
},
methods: {
choose (e, index) {
let { list, single, showReset } = this
if (single || !e.value) {
list.map(i => i.active = false)
list[index].active = true
} else {
if (list[0].active) list[0].active = false
list[index].active = !e.active
this.check()
}
if (!showReset) this.showReset = true
},
check () {
let { list, single } = this
if (!single) {
try {
list.map(e => { if (e.active) throw false })
} catch (error) {
return
}
}
this.reset()
},
reset () {
let { list } = this
list.map(i => i.active = false)
list[0].active = true
this.showReset = false
},
confirm () {
let { list } = this
let chooseList = []
list.map(e => {
if (e.active && e.value) chooseList.push(e)
})
this.$emit('confirm', chooseList)
this.close()
},
close (click) {
let { showReset } = this
if (click && showReset) {
this.reset()
return
}
this.$parent.close()
}
}
}
</script>
<style scoped lang='scss'>
.menu-box {
padding: 14px 16px 0;
.menu-title {
color: #333333;
font-size: 14px;
}
.menu-grid {
display: flex;
flex-wrap: wrap;
padding: 12px 0 0 23px;
.item {
height: 26px;
border-radius: 4px;
border: 1px solid #e4e4e4;
padding: 0 12px;
color: #666;
font-size: 14px;
transition: all 0.25s;
margin:0 16px 16px 0;
}
.active {
border-color: var(--themeColor);
color: var(--themeColor);
}
}
}
.menu-btn-box {
height: 56px;
border-top: 1px solid rgba(220, 222, 224, 0.7);
padding: 10px 16px;
box-sizing: border-box;
display: grid;
grid-template-columns: repeat(2, 162px);
align-items: center;
justify-content: space-between;
.van-button {
height: 36px;
}
}
</style>