
import * as _ from 'lodash';
export const PropertyMixin = {

    watch: {
        currentEditInstanceKey (n, o) {
            // init
            this.initCurrtField();
        },
        // getInstanceData(n, o) {
        //     // init
        //
        // },
    },
    props: {
        instanceInfo: Object,
        editor: Object
    },
    data () {
        return {
            name:"",
            field: null,
            value: ''
        };
    },
    computed: {
        getField(){
            return this.field
        },
        getInstanceData(){
          return this.instanceInfo.vm.$data;;
        },
        currentEditInstanceKey () {
            let currentEditInstanceKey = this.$store.state.viewport.currentEditInstanceKey;
            return currentEditInstanceKey;
        }
    },
    methods: {
        setInstanceProps (value) {
            this.$store.commit('viewport/setInstanceProps', {
                vm: this.instanceInfo.vm,
                key: this.field,
                value
            });
        },
        initCurrtField () {
            if(this.instanceInfo&&this.instanceInfo.vm){
                let props = this.instanceInfo.vm.$data;
                let val = _.get(props, this.field);
                if (val !== undefined) {//改为undefined,校验boolean类型false错误
                    this.value = val;
                }
            }

        }
    },
    mounted () {
        if (this.editor&&this.editor.field) {
            this.field = this.editor.field;
        }
    },

}
;
