<template>
    <div class="weui-cell">
        <div class="label">
            <slot></slot>
        </div>
        <option-img
            checkbox
            v-bind="minmax"
            v-model="checked"
            :option="listItem.option"
            @change="change"
        ></option-img>
    </div>
</template>

<script>
import common from '@/common/formRender/mixin/common.js'
import checkbox from '@/common/formRender/mixin/checkbox.js'
export default {
    name: 'FormCheckboxImg',
    mixins: [common, checkbox],
    components: {
        OptionImg: () => import('./components/OptionImg')
    },
    props: {
        listItem: { type: Object, default: () => ({}) },
        formItem: { type: Object, default: () => ({}) }
    },
    data () {
        return {
            visible: false
        }
    },
    created () {
        this.verifyInit()
        this.change(this.checked)
    },
    methods: {
        // 同步 value
        change (checked) {
            this.formItem.value = checked.map(value => {
                const obj = this.listItem.option.list.find(item => item.value === value)
                return { value: obj.name, img: obj.img }
            })
            this.clearValidate()
        },
        // 校验
        verify () {
            return this.validate({ value: this.formItem.value })
        }
    }
}
</script>

<style lang="less" scoped>
</style>
