<template>
	<view class="center">
		<view v-for="(item,index) in homeList" :key="index">
			
		</view>
	</view>
</template>

<script>
	import { gethomework } from '@/api/homework.js'
	export default {
		data(){
			return{
				homeList: [],
				limit: 10,
				page: 1,
				loadingType: 'more'
			}
		},
		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
				}
				//获取反馈列表
				gethomework({
					page: obj.page,
					limit: obj.limit
				}).then(e => {
					
					obj.homeList = obj.homeList.concat(e.data.data);
					console.log(obj.homeList)
					//判断是否还有下一页，有是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>
</style>
