import _ from 'lodash';
data() {
return {
loading: false,
form: {
pageNo: 0,
pageSize: 10,
},
eventList:[],
totalPages: 0,
}
},
mounted() {
window.addEventListener('scroll', this.throttleScroll, true);
},
beforeDestroy() {
window.removeEventListener('scroll', this.throttleScroll);
},
methods: {
async getEventList() {
this.form.pageNo = this.form.pageNo + 1;
if(this.totalPages !== 0 && this.form.pageNo > this.totalPages) return;
this.loading = true;
try {
const res = await bossEventApi.eventList(this.form);
if (res.code !== responseCode.SUCCESS) throw new Error(res.message || res.msg || '发生错误');
const list = res.data && res.data.records
const eventList = list || [];
this.eventList = this.eventList.concat(eventList)
this.totalPages = res.data.pages || 0;
} catch (err) {
console.error(err);
}
this.loading = false;
},
throttleScroll: _.throttle(function() {
this.handlerScroll();
}, 200),
handlerScroll() {
if(this.loading) return;
const scrollTop = this.$refs.longList.scrollTop;
const clientHeight = this.$refs.longList.clientHeight;
const scrollHeight = this.$refs.longList.scrollHeight;
if(scrollHeight - scrollTop - clientHeight < 200) {
this.getEventList();
}
},
}