﻿<template>
    <div v-if="mode==='query'&&nullable" :title="mode">
        <select class="form-control" :id="name" :name="currentName" v-model="currentValue">
            <option :value="null">请选择</option>
            <option value="true">是</option>
            <option value="false">否</option>
        </select>
    </div>
    <div v-else>
        <input type="checkbox" :style="'height:16px;width:16px;'+(mode==='query'?'margin:11px 0;':'margin:6px 0;')" :name="name" v-model="currentValue" />
    </div>
</template>
<script>
    export default {
        props: ['mode', 'prefix', 'title', 'name', 'value', 'nullable', 'data'],
        data: function () {
            return {
                currentName: this.prefix ? (this.prefix + '.' + this.name) : this.name,
                currentValue: this.value
            };
        },
        watch: {
            currentValue(val) {
                this.$emit('update:value', val);
                this.$emit('change', this.name);
            }
        },
        mounted: function () {
            if (this.mode !== 'query' && this.nullable && this.value === null) {
                this.$emit('update:value', false);
            }
        }
    };
</script>