index.js
2.0 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
import { VantComponent } from '../common/component';
VantComponent({
field: true,
relation: {
name: 'checkbox-group',
type: 'ancestor'
},
classes: ['icon-class', 'label-class'],
props: {
value: null,
disabled: Boolean,
labelDisabled: Boolean,
labelPosition: String,
shape: {
type: String,
value: 'round'
},
useIconSlot: Boolean
},
computed: {
iconClass: function iconClass() {
var _this$data = this.data,
disabled = _this$data.disabled,
value = _this$data.value,
shape = _this$data.shape;
return this.classNames('van-checkbox__icon', "van-checkbox__icon--" + shape, {
'van-checkbox__icon--disabled': disabled,
'van-checkbox__icon--checked': value
});
}
},
methods: {
emitChange: function emitChange(value) {
var parent = this.getRelationNodes('../checkbox-group/index')[0];
if (parent) {
var parentValue = parent.data.value.slice();
var name = this.data.name;
if (value) {
if (parent.data.max && parentValue.length >= parent.data.max) {
return;
}
/* istanbul ignore else */
if (parentValue.indexOf(name) === -1) {
parentValue.push(name);
parent.$emit('input', parentValue);
parent.$emit('change', parentValue);
}
} else {
var index = parentValue.indexOf(name);
/* istanbul ignore else */
if (index !== -1) {
parentValue.splice(index, 1);
parent.$emit('input', parentValue);
parent.$emit('change', parentValue);
}
}
} else {
this.$emit('input', value);
this.$emit('change', value);
}
},
toggle: function toggle() {
if (!this.data.disabled) {
this.emitChange(!this.data.value);
}
},
onClickLabel: function onClickLabel() {
if (!this.data.disabled && !this.data.labelDisabled) {
this.emitChange(!this.data.value);
}
}
}
});