<template> 
<div v-show="myConfig.visible"  class="efuture-checkbox"  :style="myConfig.divStyle">
    <Checkbox  ref="myControl"  v-model="value" :size="myConfig.size"  :true-value="myConfig.trueValue" :false-value="myConfig.falseValue" :disabled="readOnly||myConfig.readOnly" @on-change="setFatherValue">
        <template v-if="showTextFlag" #default>
            <span  style="margin-left: 10px;" v-text="myConfig.showText"/>
        </template>
    </Checkbox>
</div>
</template>
<script>
    import Base from '@/components/base/controlbase.vue';
    export default {
        name: 'checkbox',
        extends: Base,
        data () {
            return {
                myConfig: {
                    trueValue:'Y',
                    falseValue:'N',
                    defaultValue:'N',
                    showText:'',
                    divStyle:{}
                },
                value:'N',
                showTextFlag: false
            };
        },
        methods: {
            customInit() {
                if (this.myConfig.showText) {
                    this.showTextFlag = true;
                }
            },
            watchCustomFatherValue() {
                if (this.value !== this.myConfig.trueValue) {
                    this.value = this.myConfig.falseValue;
                    this.oldValue = this.myConfig.falseValue;
                }
            },
            setFatherValue(e) {
                let flag = true;
                this.value = e;
                let para = this._valueToFatherValue();
                para.name = this.myConfig.name;
                this.$emit('inputValue', para);
                if (this.myConfig.valueChanged) {
                    if (para.value !== this.oldValue) {
                        let oldValue = this.oldValue;
                        this.$nextTick(() =>{
                            flag = this.myConfig.valueChanged(para);
                            if (flag === undefined) {
                                flag = true;
                            }
                            if (!flag) {
                                this.$nextTick(() => {
                                    this.value = oldValue;
                                    let para = this._valueToFatherValue();
                                    para.name = this.myConfig.name;
                                    this.$emit('inputValue', para);
                                });
                            }
                        });
                    }
                }
            },
            setFocus(value) {
                if (value) {
                    this.$refs.myControl.$el.focus();
                } else {
                    this.$refs.myControl.$el.blur();
                }
            }
            
        }
    };
</script>