forked from N3-components/N3-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
n3CheckboxGroup.vue
executable file
·109 lines (99 loc) · 1.99 KB
/
n3CheckboxGroup.vue
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>
<div class="{{prefixCls}}-btn-group {{prefixCls}}-checkbox-group">
<template v-if="options">
<n3-checkbox
v-if="type==='checkbox'"
v-for="item in options"
:value="item.value"
:checked="item.checked"
:disabled="item.disabled">
{{item.label}}
</n3-checkbox>
<n3-checkbox-btn
v-if="type==='button'"
v-for="item in options"
:value="item.value"
:checked="item.checked"
:disabled="item.disabled">
{{item.label}}
</n3-checkbox-btn>
</template>
<template v-else>
<slot></slot>
</template>
<validate
:name="name"
:rules="rules"
:valid-status.sync="validStatus"
:custom-validate="customValidate"
:value="value"
:results.sync="validateResults">
</validate>
</div>
</template>
<script>
import n3Checkbox from './n3Checkbox'
import n3CheckboxBtn from './n3CheckboxBtn'
import valMixin from './valMixin'
import validate from './validate'
import type from './utils/type'
export default {
mixins: [valMixin],
props: {
value: {
type: Array,
default () {
return []
}
},
type: {
type: String,
default: 'checkbox'
},
options: {
type: Array
},
onChange: {
type: Function
},
prefixCls: {
type: String,
default: 'n3'
}
},
methods: {
init () {
let children = this.$children
let ret = []
children.forEach((item) => {
item.checked ? ret.push(item.value) : ''
})
this.value = ret
}
},
events: {
'n3@checkboxChange' (val) {
this.init()
}
},
watch: {
value () {
this.$broadcast('n3@checkboxgroupChange', this.value)
if (type.isFunction(this.onChange)) {
this.onChange(this.value)
}
},
options () {
this.init()
}
},
ready () {
this.init()
},
components: {
n3Checkbox,
n3CheckboxBtn,
validate
}
}
</script>