<template>
	<view>
		<view class="training-camp">
			<view class="training-camp-btn" @click="choose">{{title}}</view>
		</view>
		<u-picker ref="upicker" :show="show" :columns="columns" title="训练营选择" keyName="courseName" @confirm="confirm" @cancel="cancel"></u-picker>
		<view class="container-body x-start" :style="{height: contentH}">
			<!-- <view class="container-left">
				<view class="classification active">全部</view>
				<view class="classification">测试</view>
			</view> -->
			<view class="container-right">
				<mescroll-body top="0"  bottom="0" ref="mescrollRef" @init="mescrollInit" :down="downOption" :up="upOption" @down="downCallback" @up="upCallback">
					<view class="list">
						<courseItem :from="'course'" :activeTab="0" v-for="(item,index) in dataList" :key="index" :info="item" />
					</view>
				</mescroll-body>
			</view>
		</view>
	</view>
</template>

<script>
	import { getFsCourseList,getCourseVdieoList } from "@/api/courseManage.js"
	import courseItem from "../components/courseItem.vue"
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], 
		components: {
			courseItem
		},
		data() {
			return {
				title: '请选择训练营',
				contentH: 0,
				show: false,
				columns: [[]],
				mescroll:null,
				downOption: {
					use:true,
					auto: false
				},
				upOption: {
					onScroll:false,
					use: true, // 是否启用上拉加载; 默认true
					auto: false,
					page: {
						pae: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
						size: 10 // 每页数据的数量,默认10
					},
					noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					textNoMore:"已经到底了",
					empty: {
						icon:'https://cos.his.cdwjyyh.com/fs/20240423/cf4a86b913a04341bb44e34bb4d37aa2.png',
						tip: '暂无数据'
					}
				},
				dataList: [],
				user: {},
				courseList: [],
				chooseIndex: [0],
				courseId: ''
			}
		},
		mounted() {
			console.log("======cou")
			const windowHeight = uni.getSystemInfoSync().windowHeight
			this.contentH = `calc(${windowHeight}px - 52px - 56px)`
			this.user = uni.getStorageSync("companyUserInfo") ? JSON.parse(uni.getStorageSync("companyUserInfo")) : {}
			this.getFsCourseList()
		},
		methods: {
			choose() {
				this.show = true
				this.$refs.upicker.setIndexs(this.chooseIndex)
			},
			cancel() {
				this.show = false
			},
			confirm(e) {
				this.chooseIndex = e.indexs
				this.courseId = e.value[0].courseId
				this.title = e.value[0].courseName
				this.show = false
				this.mescroll.resetUpScroll()
			},
			// 训练营
			getFsCourseList() {
				const day = uni.$u.timeFormat(new Date(), 'yyyy-mm-dd')
				const param = {
					companyId: this.user.companyId,
					companyUserId: this.user.userId,
					type: this.user.userType=='00' ? 0 : 1, // 0:经销商/1:群管
				}
				getFsCourseList(param).then(res=>{
					if(res.code==200){
						this.courseList = res.data || []
						this.columns = [this.courseList]
						this.courseId = this.courseList && this.courseList.length > 0 ? this.courseList[0].courseId : ''
						this.title = this.courseList && this.courseList.length > 0 ? this.courseList[0].courseName : '请选择训练营'
						this.mescroll.resetUpScroll()
					}else{
						uni.showToast({
							icon:'none',
							title: res.msg,
						});
					}
				})
			},
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*下拉刷新的回调 */
			downCallback(mescroll) {
				mescroll.resetUpScroll()
			},
			upCallback(page) {
				//联网加载数据
				var that = this;
				var data={
					courseId:this.courseId,
					status: '',
					pageNum: page.num,
					pageSize: page.size
				};
				uni.showLoading({
					title:"加载中..."
				})
				getCourseVdieoList(data).then(res => {
					uni.hideLoading()
					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();
					}
				});
			},
		}
	}
</script>

<style>
	page {
		background-color: #f5f4f5;
	}
</style>
<style lang="scss" scoped>
	.training-camp {
		padding: 10px;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 14px;
		color: #222222;
		&-btn {
			font-size: 15px;
			width: 100%;
			height: 32px;
			line-height: 32px;
			text-align: center;
			background-color: #fff;
			border-radius: 50px;
			border: 1px solid #ccc;
		}
	}
	.container-left {
		flex-shrink: 0;
		background-color: #fff;
		width: 80px;
		height: 100%;
		overflow-y: auto;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 14px;
		color: #222222;
		.active {
			background-color: #f5f4f5;
			font-weight: bold;
			position: relative;
			&::after {
				content: "";
				height: 15px;
				width: 4px;
				background-color: #1677ff;
				position: absolute;
				top: 50%;
				left: 0;
				transform: translateY(-50%);
			}
		}
		.classification {
			padding: 20px 16px;
			box-sizing: border-box;
		}
	}
	.container-right {
		flex: 1;
		height: 100%;
		overflow-y: auto;
		.list {
			padding: 10px;
			box-sizing: border-box;
			width: 100%;
		}
	}
</style>