import unit from "$utils/unit/unit";
import popup from "$utils/tool/popup";
import {PopupExportComponent} from "$popup/popup-export/const";

export default <LibMixins>{

    data(){
        return {
            vValue:false,
            vItem:{},
            width: unit.unitPx(120),
            height:unit.unitPx(110),
            vX:0,
            vY:0,
            diff:10
        }
    },

    watch:{
        value:{
            handler:function (){
                return this.setValue(this.value);
            },
            immediate:true
        },
        x:{
            handler:function () {
                this.setTargetValue(this.x,'vX');
            },
            immediate:true
        },
        y:{
            handler:function () {
                this.setTargetValue(this.y,'vY');
            },
            immediate:true
        },
        item:{
            handler:function () {
                this.setItem(this.item,'vItem');
            },
            immediate:true
        },
    },

    methods:{

        setTargetValue(number,key){
            if (this.value === false) return null;
            let diff = Math.abs(this[key] - number);
            if (diff >= this.diff) {
                this.setItem(number,key);
            }
        },

        setItem(item,key){

            if (this.value === false) return null;
            if (this[key] !== item ) {
                this[key]= item;
            }

        },

        setValue(value){
            if (this.vValue !== value) {
                this.vValue = value;

                if (value) {
                    this.stroageAttrs = Object.assign({},this.$attrs);
                    this.setItem(this.number,'vNumber');
                }

                if (this.value !== value) {
                    return this.$emit('update:value',value);
                }
            }
        }

    },

}