<template>
	<view class="content">
		<u-tabs-swiper ref="uTabs" :list="list" :is-scroll="false" active-color="#FF4600" :current="current" @change="tabsChange"
		 :bold="false" swiperWidth="750"></u-tabs-swiper>
		 <view class="empty" v-if="(perCourse.length==0 && current==0) || (!perCourse.length&& current==0)">
		 	<u-empty text="暂无私教课程" mode="favor" ></u-empty>
		 </view>
		 <view class="empty"v-if="course.length==0 && current==1 ">
		 	<u-empty text="暂无课程" mode="favor" ></u-empty>
		 </view>
		 <view class="per_course" v-for="(item,index) in perCourse" :key="index" v-if="current==0">
		 	<view class="per_name">
		 		<text class="name">{{item.card.name}}</text>
		 		<text class="course_type">私教课</text>
		 	</view>
		 	<view class="per_row">
		 		<text class="lable">总共预约</text>
		 		<text class="num">{{item.use_nums}}次</text>
		 	</view>
		 	<view class="per_row">
		 		<text class="lable">总次数</text>
		 		<text class="num">{{item.card.nums}}次</text><text class="num" style="margin-left: 10px;">(剩余{{item.card.nums-item.use_nums}}次)</text>
		 	</view>
			<view class="time_row">
				<text class="lable">课程名称:</text>
				<text class="time">{{item.swimming_type_text}}</text>
			</view>
			<view class="time_row">
				<text class="lable">学员姓名:</text>
				<text class="time">{{item.child.name}}</text>
			</view>
		 	<view class="time_row">
		 		<text class="lable">到期时间:</text>
		 		<text class="time">{{item.expiration_time}}</text>
		 	</view>
		 </view>
		 <view class="train" v-for="(item,index) in course" :key="index" v-if="current==1">
		 	<view class="train_name">
		 		<text class="name">{{item.course.name}}</text>
		 		<text class="course_type">培训班</text>
		 	</view>
			<view class="time_row">
				<view class="left">
					<text class="lable">教练名称:</text>
					<text class="time">{{item.coach.name}}</text>
				</view>
			</view>
			<view class="time_row">
				<view class="left">
					<text class="lable">学员姓名:</text>
					<text class="time">{{item.child.name}}</text>
				</view>
				<view class="right">
				</view>
			</view>
		 	<view class="train_row">
		 		<text class="lable">开班时间</text>
		 		<text class="num">{{item.start_time}}~{{item.end_time}}</text>
		 	</view>
		 	<view class="train_row">
		 		<text class="lable">上课时间</text>
		 		<text class="num">{{item.course.start}}~{{item.course.end}}</text>
		 	</view>
		 	
		 
		 </view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [{
					name: '私教课'
				}, {
					name: '培训班'
				}],
				current: 0,
				swiperCurrent: 0,
				tran_courseName: "儿童六一蛙泳培训课",
				course: [],
				perCourse: [], //私教列表
				page:1,
				last:false
			}
		},
		onShow() {
			this.page = 1
			this.last = false
			this.course=[]
			console.log(this.page,'show')
		},
		onLoad() {
			this.getPer()
		},
		onReachBottom() {
			if (!this.last) {
				this.page++
			}
			if (this.current == 0) {
				this.getPer()
			} else if (this.current == 1) {
				this.getCourse()
			}
		},
		methods: {
			//获取课程里表
			getCourse() {
				let params = {
					page: this.page,
					type: 1
				}
				this.$u.get('/user/course', params).then(res => {
					console.log(res, 'course1')
					let data = res.data.data
					if (this.page > 1 && data.length == 0) {
						uni.showToast({
							title: '暂无更多'
						})
						this.last = true
					} else {
						this.course = this.course.concat(data)
					}
				})
			},
			//获取私教列表
			getPer() {
				let params = {
					page: this.page,
					shop_id:this.vuex_user.shop_id
				}
				this.$u.get('/user/card', params).then(res => {
					console.log(res.data, 'percourse')
					if(!res.data.data) return
					let data = res.data.data
					if (this.page > 1 && data.length == 0) {
						uni.showToast({
							title: '暂无更多'
						})
						this.last = true
					} else {
						this.perCourse = this.perCourse.concat(data)
					}
					// this.perCourse = res.data
					// console.log(this.perCourse.length,'length')
					
					
				})
			},
			//tabs通知swiper切换
			tabsChange(index) {
				console.log(index, 'tabsChange')
				this.current = index
				this.page=1
				this.last=false
				if(index==0){
					this.perCourse=[]
					this.getPer()
				}else if(index==1){
					this.course=[]
					this.getCourse()
				}
			},
		
			
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F5F5F5;

.empty{
	margin-top: 40%;
}
			.per_course {
					margin: 12px 12px 0;
				background-color: #FFFFFF;
				color: #333333;
				padding: 12px;
				border-radius: 12px;

				.per_name {
					display: flex;
					justify-content: space-between;
					align-items: center;

					.name {
						font-size: 17px;
						font-weight: bold;
					}

					.course_type {
						background-color: #E5FAF3;
						width: 54px;
						height: 24px;
						line-height: 24px;
						color: #00A421;
						font-size: 14px;
						text-align: center;
					}
				}

				.per_row {
					margin-top: 6px;

					.lable {
						width: 55px;
						height: 21px;
						display: inline-block;
						line-height: 21px;
						text-align: center;
						background-color: #F5F5F5;
						font-size: 12px;
						margin-right: 7px;
					}

					.num {
						font-size: 15px;
						color: #FF4600;
					}
				}

				.time_row {
					margin-top: 6px;

					.lable {
						display: inline-block;
						width: 60px;
						height: 21px;
						line-height: 21px;
						text-align: center;
						font-size: 12px;
					}

					.time {
						font-size: 14px;
						font-weight: bold;
					}
				}
			}

	


			.train {
				min-height: 160px;
				margin: 12px 12px 0;
				background-color: #FFFFFF;
				color: #333333;
				padding: 12px;
				border-radius: 8px;

				.train_name {
					display: flex;
					justify-content: space-between;
					align-items: center;

					.name {
						font-size: 17px;
						font-weight: bold;
					}

					.course_type {
						background-color: #DCE7FF;
						width: 54px;
						height: 24px;
						line-height: 24px;
						color: #4A80FF;
						font-size: 14px;
						text-align: center;
					}
				}

				.courseName {
					display: inline-block;
					color: #999999;
					font-size: 14px;
					margin-top: 6px;
				}

				.train_row {
					margin-top: 6px;

					.lable {
						width: 55px;
						height: 21px;
						display: inline-block;
						line-height: 21px;
						text-align: center;
						background-color: #F5F5F5;
						font-size: 12px;
						margin-right: 7px;
					}

					.num {
						font-size: 14px;
						font-weight: bold;
						// color: #FF4600;
					}
				}

				.time_row {
					margin-top: 6px;
					display: flex;
					justify-content: space-between;

					.lable {
						display: inline-block;
						width: 60px;
						height: 21px;
						line-height: 21px;
						text-align: center;
						font-size: 12px;
						// margin-right: 7px;
						// box-sizing: content-box;
					}

					.time {
						font-size: 14px;
						font-weight: bold;
					}
				}
			}
	
	}
</style>
