cuiqian2004
2025-03-14 7b15bbf1363982a03dd33c95f3ccdfdcfb7c1d47
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
<template>
    <view class="oi-form-checkbox">
        <!-- 复选框 -->
        <checkbox-group v-if="model" :class="data.disabled?'input-disabled':''" :disabled="data.disabled"
            @change="onChange">
            <label v-for="(item) in data.selections" :key="item.value" class="checkbox-item">
                <checkbox :value="item.value" :checked="model[data.fieldId].includes(item.value)" />
                <text>{{item.label}}</text>
            </label>
        </checkbox-group>
        <checkbox-group v-else :class="data.disabled?'input-disabled':''" :disabled="data.disabled" @change="onChange">
            <label v-for="(item) in data.selections" :key="item.value" class="checkbox-item">
                <checkbox :value="item.value" :checked="data.value.includes(item.value)" />
                <text>{{item.label}}</text>
            </label>
        </checkbox-group>
    </view>
</template>
 
<script>
    export default {
        name: "OIFormCheckbox",
        props: {
            data: {
                type: Object,
                required: true,
            },
            model: Object,
        },
        methods: {
            onChange(e) {
                let val = this.data.value = e.detail.value || []
                if (this.model) {
                    this.model[this.data.fieldId] = val
                }
                this.data.value = val
                this.$emit("change", val)
            },
 
        }
    };
</script>
 
<style lang="less" scoped>
    .oi-form-checkbox {
        width: 100%;
        .checkbox-item{
            vertical-align: middle;
            margin-left: 10rpx
        }
        .input-disabled {
            background-color: #f3f3f3 !important;
        }
    }
</style>