<template>
	<view class="container">
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption"
			:up="upOption">
			<view class="box">
				<view class="list-item" v-for="(item,index) in dataList" :key="index" @click="handleDetail(item)">
					<view class="list-con border-line">
						<view class="list-itemtxt">
							<text class="list-title textOne">{{item.courseName}}</text>
							<text class="list-desc textTwo">{{item.title}}</text>
						</view>
						<image :src="item.courseUrl" mode="aspectFill"></image>
					</view>
					<view class="list-footer">
						<view style="flex: 1;overflow: hidden;">
							<!-- <image :src="item.imageUrl" mode="aspectFill"></image> -->
							<text class="list-time textOne">{{item.qwUserName}}</text>
						</view>
						<text class="list-time">过期时间：{{item.updateTime}}</text>
					</view>
				</view>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
	import { getSopCourseStudyList } from "@/api/courseAnswer.js"
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], 
		data() {
			return {
				mescroll:null,
				downOption: {   //下拉刷新
				 	use:true,
					auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
				},
				upOption: {
					onScroll:false,
					use: true, // 是否启用上拉加载; 默认true
					page: {
						pae: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
						size: 10 // 每页数据的数量,默认10
					},
					noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					textNoMore:"已经到底了",
					empty: {
						icon:'https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/app/newImages/empty_icon.png',
						tip: '暂无数据'
					}
				},
				dataList: []
			}
		},
		methods: {
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*下拉刷新的回调 */
			downCallback(mescroll) {
				mescroll.resetUpScroll()
			},
			upCallback(page) {
				//联网加载数据
				let that = this;
				let data = {
					pageNum: page.num,
					pageSize: page.size
				};
				getSopCourseStudyList(data).then(res => {
					if(res.code==200){
						//设置列表数据
						if (page.num == 1) {
							that.dataList = res.data.list; 
							
						} else {
							that.dataList = that.dataList.concat(res.data.list);
							 
						}
						that.mescroll.endBySize(res.data.list.length, res.data.total);
						
					}else{
						uni.showToast({
							icon:'none',
							title: "请求失败",
						});
						that.dataList = null;
						that.mescroll.endErr();
					}
				});
			},
			handleDetail(item) {
				if(item.appRealLink) {
					uni.navigateTo({
						url: item.appRealLink
					})
				}else {
					uni.showToast({
						icon:'none',
						title: "暂无看课链接",
					});
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	@mixin u-flex($flexD, $alignI, $justifyC) {
		display: flex;
		flex-direction: $flexD;
		align-items: $alignI;
		justify-content: $justifyC;
	}

	.container {
		padding: 24rpx;
	}

	.list {
		&-con {
			width: 100%;
			padding: 24rpx;
			box-sizing: border-box;
			@include u-flex(row, flex-start, space-between);
		}
		&-item {
			background: #FFFFFF;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			margin-bottom: 20rpx;
			box-sizing: border-box;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 32rpx;
			color: #333333;
			line-height: 38rpx;

			image {
				flex-shrink: 0;
				width: 180rpx;
				height: 136rpx;
				margin-left: 16rpx;
				background: #F5F6F6;
				border-radius: 10rpx 10rpx 10rpx 10rpx;
				overflow: hidden;
			}
		}

		&-itemtxt {
			flex: 1;
			overflow: hidden;
			word-break: break-all;
			display: block;
		}

		&-title {
			word-break: break-all;
			display: block;
		}

		&-desc {
			margin-top: 16rpx;
			font-size: 26rpx;
			color: #999999;
		}

		&-time {
			font-size: 22rpx;
			color: #999999;
		}
		&-footer {
			padding: 20rpx 24rpx;
			box-sizing: border-box;
			@include u-flex(row, center, space-between);
			position: relative;
			view {
				@include u-flex(row, center, flex-start);
			}
			image {
				height: 50rpx;
				width: 50rpx;
				border-radius: 50%;
				margin: 0 10rpx 0 0;
			}
		}
	}



</style>