2022-01-17 20:02:06 +08:00

88 lines
2.8 KiB
TypeScript

/**
* +----------------------------------------------------------------------
* | 「e家宜业」 —— 助力物业服务升级,用心服务万千业主
* +----------------------------------------------------------------------
* | Copyright (c) 2020-2022 https://www.chowa.cn All rights reserved.
* +----------------------------------------------------------------------
* | Licensed 未经许可不能去掉「e家宜业」和「卓瓦科技」相关版权
* +----------------------------------------------------------------------
* | Author: concat@chowa.cn
* +----------------------------------------------------------------------
*/
import { useParent } from '../common/relation';
import { CwComponent } from '../common/component';
function emit(target, value) {
target.$emit('input', value);
target.$emit('change', value);
}
CwComponent({
field: true,
relation: useParent('checkbox-group'),
classes: ['icon-class', 'label-class'],
props: {
name: null,
value: Boolean,
disabled: Boolean,
useIconSlot: Boolean,
checkedColor: String,
labelPosition: {
type: String,
value: 'right'
},
labelDisabled: Boolean,
shape: {
type: String,
value: 'round'
},
iconSize: {
type: null,
value: 20
}
},
data: {
parentDisabled: false
},
methods: {
emitChange(value) {
if (this.parent) {
this.setParentValue(this.parent, value);
} else {
emit(this, value);
}
},
toggle() {
const { parentDisabled, disabled, value } = this.data;
if (!disabled && !parentDisabled) {
this.emitChange(!value);
}
},
onClickLabel() {
const { labelDisabled, parentDisabled, disabled, value } = this.data;
if (!disabled && !labelDisabled && !parentDisabled) {
this.emitChange(!value);
}
},
setParentValue(parent, value) {
const parentValue = parent.data.value.slice();
const { name } = this.data;
const { max } = parent.data;
if (value) {
if (max && parentValue.length >= max) {
return;
}
if (parentValue.indexOf(name) === -1) {
parentValue.push(name);
emit(parent, parentValue);
}
} else {
const index = parentValue.indexOf(name);
if (index !== -1) {
parentValue.splice(index, 1);
emit(parent, parentValue);
}
}
}
}
});