<template>
	<view class="center">
		<view class="english">various courses for children</view>
		<scroll-view scroll-y="true" class="list">
			<view v-for="(item,index) in courseList" :key="index" class="listBox" @click="nav(index)">
				<view class="bg"></view>
				<view class="title">暑假培训阅读精品课</view>
				<view class="teacher">授课科目：{{ item.subject}} {{ item.teacher}}</view>
				<view class="bzr">{{ item.bzr }}</view>
				<view class="button">请假</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import { getCourse } from '@/api/course.js'
	export default {
		data() {
			return {
				page: 1,
				limit: 10,
				loadingType: 'more',
				courseList: [
					
				],
			}
		},
		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
				}
				//获取课程
				getCourse({
					page: obj.page,
					limit: obj.limit
				}).then(e => {
					
					obj.courseList = obj.courseList.concat(e.data.data);
					console.log(obj.courseList);
					//判断是否还有下一页，有是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();
						}
					}
				})
			},
			nav(index){
				uni.navigateTo({
					url: '/pages/leave/leave?id='+ this.courseList[index].id +'&ifyid='+this.courseList[index].ifyid + '&grade_id=' + this.courseList[index].grade_id + '&subject_id=' + this.courseList[index].subject_id
				})
			}
		}
	}
</script>

<style lang="scss">
page,
.center {
	width: 100%;
	height: 100%;
	background-color: #f8f8f8;
}
.english {
	padding-left: 41rpx;
	font-size: 25rpx;
	font-family: Source Han Sans CN;
	font-weight: 400;
	color: #C2C2C2;
}
.list {
	height: 1100rpx;
}
.listBox {
	position: relative;
	width: 90%;
	height: 250rpx;
	margin: 0 auto;
	margin-top: 34rpx;
	box-shadow: 0rpx 5rpx 16rpx 0rpx rgba(253, 90, 84, 0.48);
	border-radius: 28rpx;
	.bg {
		width: 100%;
		height: 100%;
		position: absolute;
		left: 0;
		top: 0;
		background-color: #4EADFA;;
		border-radius: 28rpx;
	}
	.title {
		position: relative;
		padding-top: 36rpx;
		padding-left: 36rpx;
		font-size: 36rpx;
		font-weight: bold;
		color: #FFFFFF;
		z-index: 1;
	}
	.teacher {
		position: relative;
		margin-top: 56rpx;
		margin-left: 36rpx;
		font-size: 24rpx;
		font-weight: 500;
		color: #FFFFFF;
		z-index: 1;
	}
	.bzr {
		position: relative;
		margin-left: 36rpx;
		font-size: 24rpx;
		font-weight: 500;
		color: #FFFFFF;
		z-index: 1;
	}
	.button {
		position: absolute;
		right: 26rpx;
		bottom: 35rpx;
		width: 160rpx;
		height: 57rpx;
		background: #FFFFFF;
		border-radius: 28rpx;
		text-align: center;
		line-height: 57rpx;
		font-size: 27rpx;
		font-weight: bold;
		color: #FD5954;
	}
}
</style>

