<template>
	<view class="w100" style="width: 100%;">
		<view class="header-nav" :style="{height: `calc(88rpx + ${statusBarHeight}px)`,paddingTop: statusBarHeight + 'px'}">
			<u-icon name="arrow-left" size="28" @click="tosales" v-if="appToken"></u-icon>
			<view class="header-title" :style="{width:menuButtonLeft + 'px',height:menuButtonH+'px',lineHeight:menuButtonH+'px'}">{{courseInfo.title}}</view>
		</view>
		<view>
			<image  class="video-poster" :src="courseInfo.imgUrl" mode="aspectFill">
			<view class="title-content" id="title-content">
				<!-- 答题时展示小节课程名，其他展示课程名 -->
				<!-- 小节课程名 -->
				<view class="subtitlebox " >
					{{courseInfo.title}}
				</view>
				<!-- 课程名字 -->
				<view class="base-color-6 fs24">
					{{courseInfo.courseName}}
				</view>
			</view>
		</view>
		<view class="btns">
			<view class="author-btn" @click="comecourse">进入课程</view>
		</view>
	</view>
</template>

<script>
	import {
		getH5CourseByVideoId,
	} from "@/api/courseLook.js"
	export default{
		data(){
			return{
				videoId:3450,
				courseInfo:'',
				projectCode:'',
				sendType:'',
				courselist:{},
				statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
			}
		},
		onLoad(option) {
			console.log(option)
			const keys = decodeURIComponent(Object.keys(option)[0]);
			this.courselist=JSON.parse(keys.split('course=')[1])
			this.videoId=this.courselist.videoId
			this.projectCode=this.courselist.projectCode
			console.log(keys)
			console.log(this.courselist)
			// if(this.videoId){
			// 	this.getH5CourseByVideo()
			// }
		},
		onShow() {
			this.getHeight()
			this.utils.getDomain({projectCode:this.projectCode}).then(res=>{
				if(res.code == 200) {
					if (this.videoId) {
						this.sendType=uni.getStorageSync('sendType')
						this.getH5CourseByVideo()
						// this.utils.getConfigKey()
					}
				}
			})
		},
		methods:{
			getHeight() {
				this.$nextTick(() => {
					const query = uni.createSelectorQuery().in(this);
					query
						.select("#title-content")
						.boundingClientRect((data) => {
							this.height =
								`calc(100vh - ${data.height}px - 420rpx - ${this.statusBarHeight}px - 120rpx )`
						})
						.exec();
				})
			},
			comecourse(){
				if(this.sendType==1){
					uni.navigateTo({
						url:'/pages_course/videovip?course='+JSON.stringify(this.courselist)
					})
				}else{
					
				}
				
			},
			getH5CourseByVideo() {
				const data={
					videoId:this.videoId
				}
				getH5CourseByVideoId(data).then(res=>{
					if (res.code == 200) {
						this.courseInfo = res.data
						uni.setNavigationBarTitle({
							title: this.courseInfo && this.courseInfo.title ? this.courseInfo.title : ''
						});
					}else{
						
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.header-nav {
		height: 88rpx;
		// @include u-flex(row, center, flex-start);
		display: flex;
		justify-content: center;
		align-items: center;
		overflow: hidden;
		background-color: #fff;
		box-sizing: border-box;
		.header-title {
			text-align: center;
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
			padding: 0 10rpx 0rpx;
			font-family: PingFang SC,PingFang SC;
			font-weight: 500;
			font-size: 15px;
			color: #000;
			box-sizing: border-box;
		}
	}
	.video-poster{
		width: 100%;
	}
	.title-content{
		padding: 20rpx;
		.subtitlebox{
			font-size: 32rpx;
			font-weight: bold;
		}
	}
	.btns{
		position: fixed;
		padding: 40rpx 20rpx;
		bottom: 0;
		width: calc(100% - 40rpx);
	}
	.author-btn{
			z-index:100;
			width: 100%;
			height: 80rpx;
			background: #ff5c03;
			border-radius: 40rpx;
			font-size: 36rpx;
			font-family: PingFang SC;
			font-weight: 500;
			text-align: center;
			line-height: 80rpx;
			color: rgba(255, 255, 255, 1);
		}
</style>