<template>
</template>

<script>
import { getLeave } from '@/api/course.js'
export default {
	data() {
		return{
			page: 1,
			limit: 10,
			loadingType: 'more',
			leaveList:[]
		}
	},
	onLoad() {
		this.loadData()
	},
	//下拉刷新
	onPullDownRefresh() {
		this.loadData('refresh');
	},
	//监听页面是否滚动到底部加载更多
	onReachBottom() {
		this.loadData();
	},
	methods: {
		async loadData(type = 'add', loading){
			let obj = this;
			if (type === 'add') {
				if (obj.loadingType === 'nomore') {
					return;
				}
				obj.loadingType = 'loading';
			} else {
				obj.loadingType = 'more';
			}
			if (type === 'refresh') {
				// 清空数组
				obj.courseList = [];
				obj.page = 1
			}
			//获取反馈列表
			getLeave({
				page: obj.page,
				limit: obj.limit
			}).then(e => {
				
				obj.leaveList = obj.leaveList.concat(e.data.data);
				console.log(obj.leaveList)
				//判断是否还有下一页，有是more  没有是nomore
				if (obj.limit==e.data.length) {
					obj.page++
					obj.loadingType='more'
				} else{
					obj.loadingType='nomore'
				}
				if (type === 'refresh') {
					if (loading == 1) {
						uni.hideLoading();
					} else {
						uni.stopPullDownRefresh();
					}
				}
			})
		},
		
	}
}
</script>

<style lang="scss">
</style>
