<template>
	<view class="center">
		<scroll-view scroll-y="true" class="list">
			<view v-for="(item,index) in courseList" :key="index" class="listBox" @click="nav(index)">
				<view class="type">待完成</view>
				<view class="top flex">
					<image src="../../static/img/indexMycourse.png"></image>
					<view class="font">
						<view class="title">奥数能力提升班</view>
						<view class="time">{{item.start_time}}</view>
					</view>
				</view>
				<view class="main">
					<view class="left">
						<view class="font">授课科目: {{item.subject}}</view>
						<view class="font">班主任:</view>
					</view>
					<view class="right">
						<view class="font">授课老师: {{item.teacher}}</view>
						<view class="font">电话：</view>
					</view>
				</view>
				<view class="button">请假</view>
			</view>
			<uni-load-more :status="loadingType"></uni-load-more>
		</scroll-view>
	</view>
</template>

<script>
	import { getCourse } from '@/api/course.js';
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import { mapState, mapMutations } from 'vuex';
	import { saveUrl, interceptor } from '@/utils/loginUtils.js';
	export default {
		computed: {
			...mapState(['hasLogin', 'userInfo', 'baseURL', 'urlFile'])
		},
		components: {
			uniLoadMore
		},
		data() {
			return {
				page: 1,
				limit: 10,
				loadingType: 'more',
				courseList: [
					
				],
			}
		},
		onLoad() {
			if (this.hasLogin) {
				console.log(this.userInfo)
				this.loadData();
			}else{
				uni.showModal({
					title: '登录',
					content: '您未登录，是否马上登陆?',
					success: e => {
						console.log(e)
						if (e.confirm) {
							console.log("1111")
							interceptor();
						}
					},
					fail: e => {
						console.log(e);
					}
				});
				return;
			}
		},
		//下拉刷新
		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.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;
}

.listBox {
	position: relative;
	padding-left: 28rpx;
	padding-top: 42rpx;
	margin: 0 auto;
	margin: 20rpx;
	padding-bottom: 20rpx;
	background: #FFFFFF;
	box-shadow: 0px 5rpx 24rpx 0px rgba(4, 0, 0, 0.06);
	border-radius: 15rpx;
	.type {
		position: absolute;
		top: 38rpx;
		right: 32rpx;
		width: 97rpx;
		height: 38rpx;
		text-align: center;
		background: #FFDEDF;
		border-radius: 5rpx;
		font-size: 22rpx;
		font-weight: 500;
		color: #FF5850;
		line-height: 38rpx;
	}
	.top {
		justify-content: start;
		margin-bottom: 34rpx;
		image {
			width: 76rpx;
			height: 60rpx;
		}
		.font {
			margin-left: 10rpx;
			.title {
				font-size: 32rpx;
				font-weight: bold;
				color: #333333;
			}
			.time {
				font-size: 24rpx;
				font-weight: 400;
				color: #808080;
			}
		}
	}
	.main {
		display: flex;
		justify-content: start;
		.left {
			width: 50%;
			.font{
				font-size: 28rpx;
				font-weight: 500;
				color: #808080;
			}
		}
		.right {
			padding-left: 10rpx;
			.font{
				font-size: 28rpx;
				font-weight: 500;
				color: #808080;
			}
		}
	}
	.button {
		margin-top: 40rpx;
		margin-left: 500rpx;
		width: 145rpx;
		height: 48rpx;
		border: 1rpx solid #FF8219;
		border-radius: 24rpx;
		font-size: 26rpx;
		font-weight: 500;
		color: #FF8219;
		text-align: center;
		line-height: 48rpx;
	}
}
</style>


