<template>
	<view class="container">
		<!-- 课程banner图 -->
		<view class="courseBannerBox"></view>
		<!-- 课程详情图 -->
		<view class="courseTitleContent">
			<view class="courseTitle">
				<h4>{{courseInfo.fileTitle}}</h4>
				<view class="shareF">
					<view></view>
					<!-- <view>送好友</view> -->
				</view>
			</view>
			<view class="dataBox">
				<strong>￥{{courseInfo.coursePrice}}</strong>
				<text>{{courseInfo.salesNumber}}人购买</text>
			</view>
		</view>
		<!-- 课程介绍，相关课程，讲师 -->
		<view class="courseProBox">
			<!-- tab区域 -->
			<view class="tab">
				<text :class="{'actived': tabType===1}" @click="switchTab(1)">介绍</text>
				<text :class="{'actived': tabType===2}" @click="switchTab(2)">相关课程</text>
				<text :class="{'actived': tabType===3}" @click="switchTab(3)">讲师</text>
			</view>
			<!-- tabContent区域 -->
			<view class="tabContent">
				<!-- 课程介绍 -->
				<view class="courseIntroContent" v-if="tabType===1">
					<view v-html="courseInfo?.fileIntroduce" class="richTextContent"></view>
				</view>
				<!-- 相关课程列表 -->
				<view class="relationCourseListsContent" v-if="tabType===2">
					<view class="totalCourseCount">共{{relatedCoursesLists ?  relatedCoursesLists.length : 0}}节</view>
					<view class="courseItemContent" v-for="(item,index) in relatedCoursesLists" :key="item.fileId">
						<view class="courseInfoContent">
							<h4>{{index + 1}}.{{item.fileTitle}}</h4>
							<view class="timeContent">
								<view class="">00:00/{{secondsTransferPipe(Number(item.courseTotalTime))}}</view>
							</view>
						</view>
						<view class="statusBtnContent">
							试听
						</view>
					</view>
				</view>
				<!-- 讲师介绍 -->
				  <view class="lecturerContent" v-if="tabType===3">
					<view class="lecturerIntro">
					  <view class="lecturerUrl">
						<!-- <img :src="{{lecturerInfo.lecturerUrl}}" alt="" srcset=""> -->
					  </view>
					  <view>
						<p><text class="lecturerName">{{lecturerInfo.lecturerName}}</text></p>
						<template v-if="lecturerInfo?.lecturerRankNames">
						  <p v-for="item in lecturerInfo.lecturerRankNames.split(',')"  class="lecturerTitle"><text>{{item}}</text></p>
						</template> 
					  </view>
					</view>
					<h4>
					  <text>讲师介绍</text>
					</h4>
					<view v-html="lecturerInfo?.lecturerIntroduce" class="lecturerText richTextContent"></view>
				  </view>
				  <!-- 购买按钮 -->
				  <view class="buyBox" @click="buy()">
					  <text>购买</text>
				  </view>
			</view>
		</view>
	</view>
</template>

<script>
	import api from "../../api/api";
	import dataHandling from "@/util/dataHandling";
	export default {
		data() {
			return {
				fileId:null,
				lecturerId:null,
				tabType:3,
				lecturerInfo:{},
				courseInfo:{}
			};
		},
		methods:{
			// 切换tab
		  switchTab(type) {
		    this.tabType = type;
		    if (type === 3) {
		      this.lecturerQuery();
		    } else if (type == 2) {
		      this.relatedCoursesList()
		    } else {
		      this.courseDetail()
		    }
		  },
			// 讲师信息查询
			lecturerQuery(){
				api.lecturerQuery({id:this.lecturerId}).then(res=>{
					console.log('讲师信息',res);
					if(res['success']){
						this.lecturerInfo = res['data']['lecturerInfos'][0];
					}else{
						uni.showToast({
							title: res['message'],
							duration: 2000,
							icon: 'none'					
						})
					}
				})
			},
			// 课程详情页面
			courseDetail(){
				api.courseDetail({fileId:this.fileId}).then(res=>{
					console.log('课程详情',res);
					if(res['success']){
						this.courseInfo =  res['data']['data'];
						this.lecturerId = res['data']['data']['fileLecturerId'];
						this.lecturerQuery();
					}
				})
			},
			// 相关课程查询
			relatedCoursesList(){
				api.relatedCoursesList({fileId:this.fileId}).then(res=>{
					console.log('相关课程详情',res);
					if(res['success']){
						this.relatedCoursesLists =  res['data']['data'];
					}
				})
			},
			// 秒转时分秒格式
			secondsTransferPipe(value){
				return dataHandling.secondsTransferPipe(value)
			},
			// 购买
			buy(){
				uni.navigateTo({
					url:`/pages/orderConfirm/orderConfirm?fileId=${this.fileId}`
				})
			}
			
		
		},
		mounted(){
			this.switchTab(1)
		},
		onLoad(option){
			this.fileId = option.fileId;
			this.courseDetail();
		}
	}
</script>

<style lang="scss">
	.courseBannerBox{
		height: 300rpx;
		background-color: #ebebeb;
	}
	.courseTitleContent{
		height: 150rpx;
		background-color: #fff;
		margin-bottom: 10rpx;
		padding: 20rpx 30rpx;
		box-sizing: border-box;
		.courseTitle{
			display: flex;
			justify-content: space-between;
			margin-bottom: 16rpx;
			h4{
				font-size: 40rpx;
			}
		}
		.dataBox{
			strong{
				font-size: 30rpx;
				color: #F15A1F;
				margin-right: 30rpx;
			}
			text{
				font-size: 28rpx;
				color: #333;
			}
		}
	}
	.courseProBox{
		.tab{
			display: flex;
			justify-content: space-between;
			padding: 40rpx 30rpx 0;
			background-color: #fff;
			color: #666;
			font-size: 32rpx;
			text.actived{
				border-bottom: 2px solid #20269B;
				color: #333;
			}
		}
		.tabContent{
			padding-bottom: 200rpx;
			background-color: #fff;
		  .lecturerContent{
				.lecturerIntro{
					display: flex;
					padding: 40rpx 50rpx;
					border-bottom: 2rpx solid #fbfbfb;
					.lecturerUrl{
						width: 200rpx;
						height: 200rpx;
						border-radius: 50%;
						background-color: #ccc;
						overflow: hidden;
						margin-right: 40rpx;
					}
					.lecturerName{
						display: inline-block;
						background: #5359CD;
						border-radius: 10rpx;
						color: #fff;
						font-size: 28rpx;
						padding: 4rpx 20rpx;
					}
					.lecturerTitle{
						font-size: 28rpx;
						color: #5359CD;
						margin-top: 16rpx;
					}
				}
				h4{
					padding-left: 30rpx;
					padding-top: 10rpx;
					padding-bottom: 20rpx;
					background-color: #fff;
					text{
						border-bottom: 1px solid #333;
						font-size: 30rpx;
					}
				}
				.lecturerText{
					padding: 0 28rpx;
					background-color: #fff;
					white-space: pre-wrap;
					width: 100%;
					box-sizing: border-box;
				}
				  
			}
			.courseIntroContent,.relationCourseListsContent{
				padding: 0 28rpx;
				background-color: #fff;
				white-space: pre-wrap;
				width: 100%;
				box-sizing: border-box;
			}
			.relationCourseListsContent{
				.totalCourseCount{
					color: #20269B;
					font-size: 1rem;
					padding: 0.1875rem 0;
					border: 1px solid #fbfbfb;
					border-left: none;
					border-right: none;
				}
				.courseItemContent{
					padding: 16rpx 0;
					border-bottom: 1px solid #fbfbfb;
					display: flex;
					align-items: center;
					justify-content: space-between;
					.courseInfoContent{
						h4{
							color: #666;
						}
						.timeContent{
							color: #999;
							padding-left: 28rpx;
							
						}
					}
				}
				
			}
			.buyBox{
				position: fixed;
				bottom: 0;
				left: 0;
				right: 0;
				border-radius: 80rpx;
				background-color: #20269B;
				color: #fff;
				font-size: 36rpx;
				padding: 20rpx 90rpx;
				text-align: center;
				max-width: 60%;
				margin: 0 auto;
			}
		}
	}
</style>
