<template>
	<view class="course-detail-index">
		<view class="banner-box">
			<image src="../../static/article1.png"></image>
		</view>
		<view class="tab-box acea-row row-around" :class="isFixedTop?'fixed':''">
			<view class="tab-item" :class="active == '0' ? 'tab-item-active' : ''" @click="handelScroll('content1','0')">榜单介绍</view>
			<view class="tab-item" :class="active == '1' ? 'tab-item-active' : ''" @click="handelScroll('content2','1')">时间安排</view>
			<view class="tab-item"  :class="active == '2' ? 'tab-item-active' : ''" @click="handelScroll('content3','2')">奖惩规则</view>
		</view>
		
		<view class="content-box" bindscroll="scroll">
			<scroll-view scroll-y="true" scroll-with-animation="true" style="height:100%;" :scroll-into-view="toView" >
				
				<view class="course-desc-box" id="content1">
					<view class="title-box acea-row row-middle">
						<view class="left-line"></view>
						<span>课程简介</span>
					</view>
					<text class="desc">
						抱朴书院孕育自华夏优秀传统文化，以“博学致用抱朴含虚”为院训，以“弘扬国粹，利益社会”为动力。\n
						抱朴书院孕育自华夏优秀传统文化，以“博学致用抱朴含虚”为院训，以“弘扬国粹，利益社会”为动力。
					</text>
				</view>
				
				<view class="course-desc-box content" id="content2">
					<view class="title-box acea-row row-middle">
						<view class="left-line"></view>
						<span>时间安排</span>
					</view>
					<view class="course-card-list">
						<view class="course-card-item acea-row row-middle">
							<view class="label">开始时间：</view>
							<view class="info">2021.5.31 - 2021.6.3</view>
						</view>
						<view class="course-card-item acea-row row-middle">
							<view class="label">截止时间：</view>
							<view class="info">2021.5.31 - 2021.6.3</view>
						</view>
						<view class="course-card-item acea-row row-middle">
							<view class="label">打榜周期：</view>
							<view class="info">每日打卡（七天/周）</view>
						</view>
						<view class="course-card-item acea-row row-middle">
							<view class="label">打卡时间：</view>
							<view class="info">06:00-22:00</view>
						</view>
					</view>
				</view>
				
				<view class="course-desc-box" >
					<view class="title-box acea-row row-middle">
						<view class="left-line"></view>
						<span>奖惩规则</span>
					</view>
					<view class="course-card-list">
						<view class="course-card-item acea-row-nowrap row-middle">
							<view class="label">积分奖惩：</view>
							<view class="info">30积分</view>
						</view>
						<view class="course-card-item acea-row-nowrap row-middle row-top">
							<view class="label">积分用途：</view>
							<view class="info">可用于兑换积分商城内商品并抵扣一定款项（1积分=1元）</view>
						</view>
						<view class="course-card-item acea-row-nowrap row-middle row-top">
							<view class="label">奖惩机制：</view>
							<view class="info">积极打卡满21天可获得全部积分，消极应对无积分奖励。积极打卡满21天可获得全部积分，消极应对无积分奖励。积极打卡满21天可获得全部积分，消极应对无积分奖励。</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
		<view class="signin-btn" @click="submitSignin">立即报名</view>
	</view>
</template>

<script>
	// import WucTab from '@/components/wuc-tab/wuc-tab.vue';
	export default {
		data() {
			return {
				active: '0',
				toView: '',
				heightArr:[],
				tabInitTop:'',
				isFixedTop: false,
				dialog:false
			}
		},
		onLoad() {
			//获取节点距离顶部的距离
			uni.createSelectorQuery().select('.tab-box').boundingClientRect((res) => {
				console.log(res);
				if (res && res.top > 0) {
					var tabInitTop= res.top;
					this.tabInitTop= tabInitTop
				}
			}).exec();
		},
		mounted() {
			this.getHeightArr()
		},
		methods: {
			signInClick(){
				this.dialog = true
			},
			submitSignin(){
				this.$yrouter.push({
					path:'/pages/study/dabang'
				})
			},
			handelScroll(id,idx){
				uni.createSelectorQuery().select('#'+id).boundingClientRect(function(res){
					uni.pageScrollTo({
							scrollTop:res.top,
							duration: 300
					});
				}).exec()
				this.active = idx;
				this.toView = id
			},
			getHeightArr(){
			  let h=0;
			  let heightArr = [];
			  //selectAll会选择所要含有该类名的盒子
			  uni.createSelectorQuery().selectAll('.content').boundingClientRect((rect) => {
			  }).exec((res) => {
					console.log(res)
			    res[0].forEach((item)=>{
			      h+=item.height;
			      heightArr.push(h);
			    })
					this.heightArr = heightArr;
			  })
			},
			 onPageScroll(res) {
				 let scrollTop = res.scrollTop;
				 let scrollArr = this.heightArr;
				 for  (let  i = 0; i < scrollArr.length; i++) {
				   if  (scrollTop >= 0  && scrollTop < scrollArr[0]) {
				     this.active = 0;
				   } else if (scrollTop >= (scrollArr[i - 1]) && scrollTop < scrollArr[i]) {
				     this.active= i;
				   }
				 }
				var isSatisfy = scrollTop >= this.tabInitTop? true : false;
				//只有处于吸顶的临界值才会不相等
				if (this.isFixedTop === isSatisfy) {
					return false;
				}
				this.isFixedTop = isSatisfy
			},
		}
	}
</script>

<style scoped lang="less">
.course-detail-index{
	width: 100%;
	background: #fff;
	padding-bottom: 70rpx;
	box-sizing: border-box;
	.banner-box{
		width: 100%;
		height: 286rpx;
		image{
			width: 100%;
			height: 100%;
		}
	}
	.course-info-box{
		box-sizing: border-box;
		padding: 30rpx 30rpx 50rpx;
		background: #fff;
		.course-title{
			font-size: 40rpx;
			font-weight: 500;
			color: #333333;
			line-height: 56rpx;
			margin: 0rpx 0 20rpx;
		}
		.tips-box{
			display: flex;
			.tip-item{
				min-width: 60rpx;
				height: 34rpx;
				text-align: center;
				line-height: 34rpx;
				font-size: 24rpx;
				margin-left: 20rpx;
				padding: 0 5rpx;
			}
			.blue{
				color: #6E85EB;
				border: 1px solid #6E85EB;
				background: #EDEFF8;
			}
			.orange{
				color: #EF644E;
				border: 1px solid #EF644E;
				background: #FFF4F2;
			}
		}
	}
	.tab-box{
		white-space: nowrap;
		width: 100%;
		background: #fff;
		padding: 18rpx 34rpx 0;
		.tab-item{
			width: 33%;
			text-align: center;
			display: inline-block;
			padding-bottom: 18rpx;
			font-size: 32rpx;
			color: #222;
		}
		.tab-item-active{
			font-size: 40rpx;
			font-weight: bold;
			border-bottom: 4rpx solid #EB5744;
		}
	}
	.fixed{
		position: -webkit-sticky;
		position: sticky;
		top: 0;
		z-index: 99;
	}

	.content-box{
		width: 100%;
		box-sizing: border-box;
		background: #F5F6F7;
		padding: 24rpx 22rpx;
		.teacher-info-box,.course-desc-box{
			width: 100%;
			background:#fff;
			border-radius: 8rpx;
			padding: 18rpx 24rpx 30rpx;
			margin-bottom: 20rpx;
		}
		.desc{
			text-indent: 2em;
			font-size: 28rpx;
			color: #666666;
			line-height: 24px;
		}
		.info-box{
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			image{
				width: 100rpx;
				height: 100rpx;
				border-radius: 25px;
			}
			.name{
				font-size: 32rpx;
				color: #3C464F;
				line-height: 44rpx;
			}
			.tip{
				font-size: 24rpx;
				color: #999999;
				line-height: 34px;
			}
		}
		.title-box{
			font-size: 36rpx;
			font-weight: bold;
			color: #3C464F;
			line-height: 50rpx;
			margin-bottom: 20rpx;
			.left-line{
				width: 6rpx;
				height: 32rpx;
				background-color: #EB5744;
				margin-right: 16rpx;
			}
		}
		.course-card-item{
			font-size: 32rpx;
			color: #666666;
			margin-bottom: 10rpx;
			image{
				width: 30rpx;
				height: 30rpx;
			}
			.label{
				width: 160rpx;
				line-height: 34rpx;
			}
			.info{
				width: calc(100% - 160rpx);
				line-height: 46rpx;
			}
		}
	}

	.signin-btn{
		width: 680rpx;
		height: 88rpx;
		background: linear-gradient(180deg, #F7D08E 0%, #E2B35D 100%);
		border-radius: 44rpx;
		text-align: center;
		line-height: 88rpx;
		margin: 78rpx auto 0;
		color: #fff;
	}
}
</style>
