2016-09-09 14:29:19 +08:00
|
|
|
<template>
|
|
|
|
<div :class="classes">
|
|
|
|
<slot></slot>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
2017-03-09 11:14:40 +08:00
|
|
|
import Emitter from '../../mixins/emitter';
|
2016-09-09 14:29:19 +08:00
|
|
|
const prefixCls = 'ivu-checkbox-group';
|
|
|
|
|
|
|
|
export default {
|
2017-03-02 17:40:19 +08:00
|
|
|
name: 'CheckboxGroup',
|
2017-03-09 11:14:40 +08:00
|
|
|
mixins: [ Emitter ],
|
2016-09-09 14:29:19 +08:00
|
|
|
props: {
|
2017-03-01 17:58:40 +08:00
|
|
|
value: {
|
2016-09-09 14:29:19 +08:00
|
|
|
type: Array,
|
2016-11-15 11:24:28 +08:00
|
|
|
default () {
|
2016-12-25 22:49:42 +08:00
|
|
|
return [];
|
2016-11-15 11:24:28 +08:00
|
|
|
}
|
2016-09-09 14:29:19 +08:00
|
|
|
}
|
|
|
|
},
|
2017-03-01 17:58:40 +08:00
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
currentValue: this.value
|
|
|
|
};
|
|
|
|
},
|
2016-09-09 14:29:19 +08:00
|
|
|
computed: {
|
|
|
|
classes () {
|
|
|
|
return `${prefixCls}`;
|
|
|
|
}
|
|
|
|
},
|
2017-03-01 17:58:40 +08:00
|
|
|
mounted () {
|
2016-09-09 14:29:19 +08:00
|
|
|
this.updateModel(true);
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
updateModel (update) {
|
2017-03-01 17:58:40 +08:00
|
|
|
const value = this.value;
|
2016-09-09 14:29:19 +08:00
|
|
|
|
|
|
|
this.$children.forEach((child) => {
|
2017-03-01 17:58:40 +08:00
|
|
|
child.model = value;
|
2016-09-09 14:29:19 +08:00
|
|
|
|
|
|
|
if (update) {
|
2017-03-01 17:58:40 +08:00
|
|
|
child.currentValue = value.indexOf(child.label) >= 0;
|
2016-09-09 14:29:19 +08:00
|
|
|
child.group = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
change (data) {
|
2017-03-01 17:58:40 +08:00
|
|
|
this.currentValue = data;
|
|
|
|
this.$emit('input', data);
|
2016-09-09 14:29:19 +08:00
|
|
|
this.$emit('on-change', data);
|
2017-03-09 11:14:40 +08:00
|
|
|
this.dispatch('FormItem', 'on-form-change', data);
|
2016-09-09 14:29:19 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
2017-03-01 17:58:40 +08:00
|
|
|
value () {
|
2016-12-21 20:48:11 +08:00
|
|
|
this.updateModel(true);
|
2016-09-09 14:29:19 +08:00
|
|
|
}
|
|
|
|
}
|
2016-12-25 22:49:42 +08:00
|
|
|
};
|
|
|
|
</script>
|