<template>
	<view class="study-type">
		<!-- 导航栏 -->
		<zs-header :background="background"></zs-header>
		<image class="banner" :src="bg" mode=""></image>
		
		<!-- 横向 -->
		<view v-for="(item,index) in pageContent" :key="item.id">
			<view class="type-title" v-if="item.pages.length">
				{{item.columnName}}
			</view>
			<!-- type-box横向 type-box1纵向 -->
			<view :class="item.templateType == 1?'type-box1':'type-box'">
				<view class="type-item" v-for="(i,d) in item.pages" :key="i.id" @click="goTypeList(i.id,i.columnName)">
					<view class="glass" :style="{'--bg':i.colour}">
						<view class="title">
							{{i.columnName}}
						</view>
						<view class="type">
							{{i.columnMsg}}
						</view>
					</view>
					<image class="icon" :src="i.columnImg" mode=""></image>
				</view>
			</view>
			
			<!-- 纵向 -->
			<!-- <view class="type-box1">
				<view class="type-item" v-for="(i,d) in item.pages" :key="i.id" @click="goTypeList(i.id,i.columnName)">
					<view class="glass">
						<view class="title">
							{{i.columnName}}
						</view>
						<view class="type">
							{{i.columnMsg}}
						</view>
					</view>
					<image class="icon" :src="i.columnImg" mode=""></image>
				</view>
			</view> -->
		</view>
		
		<template>
			<view class="type-title" v-if="list.length||list1.length">
				科普视频
			</view>
			<!-- 列表 -->
			<zs-list class="store-box" mt="0" @load="loadMore" :status="status">
				<view class="left">	
					<view class="store-item" v-for="(item,index) in list" :key="index" @click="goCourse(item.id)">
						<image class="play-icon" src="../static/play.png" mode="widthFix"></image>
						<zs-img :src="item.courseImg" width="344rpx" height="256rpx"></zs-img>
						<view class="info">
							<view class="title">
								{{item.courseName}}
							</view>
							<view class="user-info">
								<image class="head" src="../static/logo.png" mode=""></image>
								<view class="user-name">
									研学官方账号
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="right">
			
					<view class="store-item" v-for="(item,index) in list1" :key="index" @click="goCourse(item.id)">
						<image class="play-icon" src="../static/play.png" mode=""></image>
						<zs-img :src="item.courseImg" width="344rpx" height="256rpx"></zs-img>
						<view class="info">
							<view class="title">
								{{item.courseName}}
							</view>
							<view class="user-info">
								<image class="head" src="../static/logo.png" mode=""></image>
								<view class="user-name">
									研学官方账号
								</view>
							</view>
						</view>
					</view>
				</view>
			
			</zs-list>
		</template>
		
	</view>
</template>

<script>
	import {getMenu,getPage,videoList} from '@/api/study.js';
	export default {
		data() {
			return {
				bg:'',
				background:false,
				pageContent:[],
				status: 'more',
				list: [],
				list1: [],
				query:{
					columnId:0,
					currentPage:1,
					pageSize:10,
				}
			}
		},
		methods: {
			goTypeList(id,title){
				uni.navigateTo({
					url:`/study/studyList?id=${id}&title=${title}`
				})
			},
			goDetail(){},
			// 去课程详情页
			goCourse(id){
				uni.navigateTo({
					url:'./courseDetail?id='+id
				})
			},
			loadMore() {
				this.videoList()
			},
			// 获取顶部栏目
			getPage(columnId){
				getPage({currentPage:1,pageSize:10,columnId,status:1}).then(res=>{
					if(res.state == 'Success'){
						this.pageContent = res.content
					}
				})
			},
			// 课程视频
			videoList(){
				this.status = 'loading'
				videoList(this.query).then(res=>{
					if(res.state == 'Success'){
						let list = []
						let list1 = []
						res.content.records.map((item,index)=>{
							if(index%2){
								list1.push(item)
							}else{
								list.push(item)
							}
						})
						this.list = this.list.concat(list)
						this.list1 = this.list1.concat(list1)
						let total = this.list.length+this.list1.length
						if(total>=res.content.total){
							this.status = 'noMore'
						}else{
							this.status = 'more'
							this.query.currentPage++
						}
					}
				})
			}
			
		},
		onLoad(options) {
			this.query.columnId = options.id
			this.getPage(options.id)
			let that = this
			const eventChannel = this.getOpenerEventChannel();
			if(JSON.stringify(eventChannel) !=='{}'){
				eventChannel.on('img', function(data) {
					that.bg = data
				})
			}
		},
		onPageScroll(e) {
				if(e.scrollTop >= 30){
					this.background = true
				}else{
					this.background = false
				}
		},
	}
</script>

<style lang="scss" >
.study-type{
	padding: 0 20rpx;
	.banner{
		width: 750rpx;
		height: 420rpx;
		vertical-align: bottom;
		position: relative;
		left: -20rpx;
	}
	
	.type-title{
		font-weight: bold;
		color: #222222;
		font-size: 32rpx;
		margin: 30rpx 0 20rpx;
	}
	.type-box{
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
		.type-item{
			position: relative;
			margin-bottom: 16rpx;
			.glass{
				position: absolute;
				bottom: 0%;
				left: 0%;
				width: 100%;
				height: 72rpx;
				padding-left: 16rpx;
				box-sizing: border-box;
				border-radius:0 0 16rpx 16rpx;
				background: linear-gradient(180deg, rgba(0,188,255,0) 0%, var(--bg) 100%);
				.title{
					font-weight: bold;
					color: #FFFFFF;
					font-size: 24rpx;
					margin-top: 8rpx;
					width: 100%;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}
				.type{
					font-weight: 400;
					color: #FFFFFF;
					font-size: 16rpx;
					margin-top: 8rpx;
					width: 100%;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}
			}
			.icon{
				width: 224rpx;
				height: 124rpx;
				border-radius: 16rpx;
				vertical-align: bottom;
			}
		}
	}
	
	.type-box1{
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
		.type-item{
			position: relative;
			margin-bottom: 16rpx;
			.glass{
				position: absolute;
				bottom: 0%;
				left: 0%;
				width: 100%;
				height: 72rpx;
				padding-left: 16rpx;
				box-sizing: border-box;
				border-radius:0 0 16rpx 16rpx;
				backdrop-filter: blur(6px);
				.title{
					font-weight: bold;
					color: #FFFFFF;
					font-size: 24rpx;
					margin-top: 8rpx;
					width: 100%;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}
				.type{
					font-weight: 400;
					color: #FFFFFF;
					font-size: 16rpx;
					margin-top: 8rpx;
					width: 100%;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}
			}
			.icon{
				width: 224rpx;
				height: 298rpx;
				border-radius: 16rpx;
				vertical-align: bottom;
			}
		}
	}
	
	.swiper {
		height: 272rpx;
		border-radius: 16rpx;
		margin-top: 28rpx;
		.swiper-item {
			width: 100%;
			height: 100%;
			border-radius: 16rpx;
			object-fit: cover;
		}
	}
	
	.zs-list {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		.left {
			
		}
	
		.right {
			
		}
		
		.store-item{
			box-shadow: 0rpx 0rpx 24rpx 2rpx rgba(0,0,0,0.08);
			border-radius: 16rpx;
			width: 344rpx;
			margin-top: 20rpx;
			position: relative;
			.play-icon{
				position: absolute;
				top: 20rpx;
				right: 30rpx;
				width: 30rpx;
				height: 30rpx;
				z-index: 2;
			}
			.info{
				padding: 20rpx;
				.title{
					color: #222222;
					font-size: 24rpx;
					width: 100%;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;      /* 显示的最大行数 */
					overflow: hidden;
				}
				.user-info{
					display: flex;
					align-items: center;
					margin-top: 20rpx;
					.head{
						width: 40rpx;
						height: 40rpx;
						border-radius: 50%;
					}
					.user-name{
						color: #AAAAAA;
						font-size: 20rpx;
						margin-left: 12rpx;
					}
				}
			}
		}
	}
	
}
</style>