export default {
    data() {
        return {
            screenHeight: window.innerHeight,
        };
    },
    computed: {
        width() {
            return this.conf.width;
        },
        height() {
            if (typeof this.conf.height == "function") {
                let ph = this.getParentHeight() || this.mainHeight;
                return this.conf.height.call(this, ph);
            } else {
                // 对话框时获取父高度
                return this.conf.height || this.getParentHeight();
            }
        },
        mainHeight() {
            let height = this.screenHeight;//
            if (this.$HCBIRT && this.$HCBIRT.tabHeight) {
                height -= this.$HCBIRT.tabHeight;
            }
            if (this.isShowToolBar()) {
                height -= 60;
            }
            return height;
        },
    },
    watch: {
        screenHeight(val) {
            if (!this.timer) {
                this.screenHeight = val;
                this.timer = true;
                const me = this;
                setTimeout(function () {
                    me.timer = false;
                }, 400);
            }
        },
    },
    methods: {
        autoWidth() {
            return "100%";
        },
        autoHeight() {
            if (this.height) {
                return this.height;
            } else {
                return this.mainHeight;
            }
        },
        registerResize() {
            const me = this;
            window.onresize = () => {
                return (() => {
                    me.screenHeight = window.innerHeight;
                })();
            };
        },
        getParentHeight() {
            let parent = this.$parent;
            while (parent) {
                if (parent.autoHeight) {
                    let parentHeight = parent.autoHeight();
                    if (parentHeight)
                        return parentHeight;
                }
                parent = parent.$parent;
            }
        },
    },
    mounted() {
        this.registerResize();
    },
}