import Throttle from '$utils/tool/throttle';
import {nextTick} from 'vue';
export default <LibMixins>{

    methods:{

        sendMessageScroll:function () {

            // 获取判断
            if (this.$refs.scroll && this.rangEndDistance >= this.$refs.scroll.getScrollEndDistance()) {
                this.scrollToEnd();
            }

        },

        scrollToEnd(setOpacity:boolean=false){
            nextTick(()=>{
                this.$refs.scroll.scrollToEnd();

                if (setOpacity && this.opactiy !== 1) {
                    setTimeout(()=>{
                        this.opacity = 1;
                    },16);
                }
            });
        }

    },
    created() {

        // 当在底部多少范围内，收到消息直接跳转到最底部
        this.rangEndDistance = 300;

        this.throttle = new Throttle({
            type:'queueWait',
            delay: 300,
            mustDelay:300,
            handle: this.scrollToEnd,
            call: this
        });

        this.scrollToEnd = this.throttle.supper;

    },

    beforeUnmount(){
        this.throttle && this.throttle.destroy();
    }

}
