<template>
	<view class="container">
		<view class="top">
			<image class="bg " style="height: 600rpx;" :src="learncourse.imgUrl" mode="scaleToFill"></image>
			<view class="top-box">
				<view class="title">{{learncourse.courseName}}</view>
				<view class="txt">
					<image src="https://hst2-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/learn1.png"></image>
					<text>共{{learnList.length}}节课</text>
				</view>
			</view>
		</view>
		<view class="container-body">

			<view class="list" v-for="(item,index) in learnList" :key="index">
				<view class="img-box">
					<view class="sub">第{{index+1}}课</view>
					<image :src="item.videoImgUrl || 'https://hst2-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/no-img.png'" mode="aspectFill"></image>
				</view>
				<view class="right">
					<view class="title">{{item.title}}</view>
					<view class="bottom">
						<!-- <view class="tip">
							<image src="https://hst2-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/learn3.png" mode="widthFix"></image>
							<text>答题送金币+200</text>
						</view> -->
						<!-- <view @click="goLive(item)" class="btn" v-if="item.stauts==0">已学习4%</view> -->
						<view @click="goLive(item)" class="btn-red">去学习</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { compile } from "vue";
import {
		courseList,
		courseListB
	} from '@/api/class.js'
	
	export default {
		data() {
			return {
				courseId: null,
				tabList: [{
					name: '详情'
				}, {
					name: '课程目录'
				}],
				learnList: [],
				learncourse:{},
				type:null,
			}
		},
		computed: {

		},
		onLoad(options) {
			// 接收传递的课程 ID
			if (options.courseId) {
				console.log(options.courseId)
				this.courseId = options.courseId;
				if(options.type==1){
					this.getCourseList()
				}else{
					this.getCourseListb()
				}
			}
			
		},
		mounted() {
		},
		methods: {
			goLive(item) {
				console.log("id",item)
				const id=item.videoId
				const videoitem = {
					videoId:item.videoId,
					courseId:this.courseId
				}
				uni.navigateTo({
					url: '/pages_course/video?videoitem='+JSON.stringify(videoitem)
					// url: '/pages_course/video'
				})
			},
			getCourseListb() {
				//私域看课
				courseListB().then(res => {
					console.log("课程列表", res)
					if (res.code == 200) {
						// 1. 根据 courseId 找到对应的课程
						const course = res.data.find(item => item.courseId == this.courseId);
						if (course && course.fsUserCourseVideoList) {
							// 2. 映射数据到 learnList 格式
							this.learncourse=course
							this.learnList = course.fsUserCourseVideoList
							console.log("learnList是多少》》", this.learnList)
							console.log("learnList是多少", this.learncourse)
							
						} else {
							console.warn("未找到课程或视频列表");
							this.learnList = [];
						}
					} else {
						uni.hideLoading();
						uni.showToast({
							title: res.msg,
							icon: 'none'
						});
					}
				})
			},
			getCourseList() {
				courseList().then(res => {
					console.log("课程列表", res)
					if (res.code == 200) {
						// 1. 根据 courseId 找到对应的课程
						const course = res.data.find(item => item.courseId == this.courseId);
						if (course && course.fsUserCourseVideoList) {
							// 2. 映射数据到 learnList 格式
							this.learncourse=course
							this.learnList = course.fsUserCourseVideoList
							console.log("learnList是多少》》", this.learnList)
							console.log("learnList是多少", this.learncourse)
							
						} else {
							console.warn("未找到课程或视频列表");
							this.learnList = [];
						}
					} else {
						uni.hideLoading();
						uni.showToast({
							title: res.msg,
							icon: 'none'
						});
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		padding: 0 0 30rpx;
		background-color: #f0f4f7;

		.top {
			position: relative;

			.bg {
				width: 100%;
			}

			.top-box {
				position: absolute;
				bottom: -90rpx;
				width: 100%;
				padding: 30rpx;
				background: linear-gradient(to bottom,
						rgba(255, 255, 255, 0.5) 0%,
						rgba(255, 255, 255, 0.9) 20%,
						rgba(255, 255, 255, 1) 100%);
				border-radius: 16rpx;

				.title {
					font-size: 34rpx;
				}

				.txt {
					margin-top: 20rpx;
					display: flex;
					align-items: center;

					image {
						width: 36rpx;
						height: 36rpx;
						margin: 0 8rpx;
					}

					text {
						font-size: 28rpx;
						color: #595959;
					}
				}
			}
		}

		.container-body {
			margin-top: 110rpx;
			padding: 0 24rpx;

			.center-box {
				background-color: #ffffff;
				padding: 10rpx 24rpx 50rpx;
				border-radius: 16rpx;

				.progress-box {
					display: flex;
					align-items: center;
					margin: 50rpx 0 30rpx;

					image {
						width: 38rpx;
						height: 38rpx;
					}

					.title {
						margin: 0 10rpx 0 4rpx;
						font-size: 34rpx;
					}

					.txt {
						font-size: 28rpx;
						color: #595959;
					}
				}

				.progress {
					display: flex;
					align-items: center;

					text {
						font-size: 26rpx;
						margin-left: 12rpx;
					}
				}
			}

			.list {
				padding: 20rpx;
				background-color: #ffffff;
				border-radius: 16rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				box-sizing: border-box;
				margin-top: 20rpx;

				.img-box {
					width: 240rpx;
					height: 150rpx;
					border-radius: 16rpx;
					overflow: hidden;
					position: relative;
					flex-shrink: 0;

					.sub {
						background-color: rgba(0, 0, 0, 0.8);
						padding: 4rpx 16rpx;
						color: #ffffff;
						position: absolute;
						top: 0;
						left: 0;
						font-size: 24rpx;
						border-radius: 8rpx;
					}

					image {
						width: 100%;
						height: 100%;
					}
				}

				.right {
					height: 150rpx;
					margin-left: 20rpx;
					flex: 1;
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					min-width: 0;

					.title {
						font-size: 30rpx;
						font-weight: 500;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-line-clamp: 2;
						/* 控制显示行数 */
						-webkit-box-orient: vertical;
						word-break: break-all;
						/* 允许单词内换行 */
						max-height: 80rpx;
						/* 根据字体大小调整 */
						line-height: 40rpx;
						/* 行高与字体大小匹配 */
						width: 100%;
						/* 确保宽度占满容器 */
					}

					.bottom {
						display: flex;
						// flex-direction: column;
						justify-content: flex-end;
						align-items: center;
						font-size: 26rpx;

						.tip {
							background: linear-gradient(to right, #fcecd0, #ffffff);
							padding: 8rpx 12rpx;
							border-radius: 22rpx;
							color: #f2931d;

							image {
								width: 36rpx;
								height: 36rpx;
								margin-right: 4rpx;
							}

							text {}
						}

						.btn {
							background-color: #fdf0e7;
							padding: 8rpx 16rpx;
							color: #f38600;
							border-radius: 12rpx;
						}

						.btn-red {
							background-color: #ff512f;
							padding: 8rpx 18rpx;
							color: #ffffff;
							border-radius: 12rpx;
						}
					}
				}

			}
		}
	}
</style>