export default {

    data(){
        return {
            triggered: false,
            scrollTop:0,
            look:false
        }
    },

    methods:{

        /* 开启下拉刷新的时候触发 */
        refreshHandle:function () {
            this.triggered = true;
            return this.$emit('refresh',this.stop);
        },

        /* 停止下拉刷新 */
        stop:function () {
            if (this.triggered) {
                return this.triggered = false;
            }
        },

        getHeight(){
            if(this.look) return;
            this.look = true;

            var query = uni.createSelectorQuery().in(this);
            query.select('#scroll-height').boundingClientRect();
            query.exec((res) => {
                if (res && res[0]) {
                    this.height = res[0].height
                }
                this.look = false;
            })
        },

        scroll(e) {
            if (!this.paging || this.bottomLoading) return;

            let detail = e.detail;
            let diff = detail.scrollHeight - detail.scrollTop - this.height;
            if (this.height <= 0) { this.getHeight() }

            if (diff <= this.threshold)  {
                this.bottomLoading = true;
                this.$emit('bottom');
                return setTimeout(()=>{
                    this.bottomLoading = false;
                },500);
            }
        }


    },

    created() {
        this.height = 0;
        this.stop = this.stop.bind(this);
    },
    mounted() {

        this.getHeight();

    }

}