<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="title-box">
				<view class="type-title" v-if="item.list.length">
					{{item.title}}
				</view>
				<view class="more" @click="goTypeList(item.id,item.title)">
					更多
				</view>
			</view>
			<!-- type-box横向 type-box1纵向 -->
			<view class="type-box">
				<view class="type-item" v-for="(i,d) in item.list" :key="i.goodsId" @click="goGoodsDetail(i.goodsId)">
					<zs-img :src="i.logoPath" width="344rpx" height="344rpx" mode=""></zs-img>
					<view class="info">
						<view class="title">
							{{i.goodsName||'冬季北疆·阿勒泰将军山喀纳斯-天木-白哈巴...'}}
						</view>
						<view class="desc">
							{{i.goodsDescribe||'了解中国古代印染工艺非遗传承的现状'}}
						</view>
						<view class="price-box">
							<view class="left">
								<!-- <view class="unit">
									￥
								</view> -->
								<view class="price">
								￥{{i.realPrice||50}}
								</view>
							</view>
							
							<view class="right">
								销量{{i.saleNum||999}}
							</view>
						</view>
					</view>
				</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,studyGoods} from '@/api/study.js';
	export default {
		data() {
			return {
				bg:'',
				background:false,
				pageContent:[],
				status: 'more',
				list: [],
				list1: [],
				query:{
					columnId:0,
					currentPage:1,
					pageSize:10,
				}
			}
		},
		methods: {
			// 去商品详情
			goGoodsDetail(id){
				uni.navigateTo({
					url:'/study/studyGoodsDetail?id='+id
				})
			},
			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){
				return new Promise((resolve,reject)=>{
					getPage({currentPage:1,pageSize:10,columnId,status:1}).then(res=>{
						if(res.state == 'Success'){
							res.content.map(item=>{
								let obj = {
									id:item.id,
									title:item.columnName,
									list:[]
								}
								this.pageContent.push(obj)
							})
							console.log(this.pageContent);
							resolve()
						}
					})
				})
			},
			// 课程视频
			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++
						}
					}
				})
			},
			getStudyGoods(){
				this.pageContent.map(item=>{
					studyGoods({columnId:item.id,currentPage:1,pageSize:4}).then(res=>{
						if(res.state == 'Success'){
							item.list = res.content.records
						}
					})
				})
			}
			
		},
		onLoad(options) {
			this.query.columnId = options.id
			this.getPage(options.id).then(()=>{
				this.getStudyGoods()
			})
			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;
	background: #F9F9F9;
	.banner{
		width: 750rpx;
		height: 420rpx;
		vertical-align: bottom;
		position: relative;
		left: -20rpx;
	}
	.title-box{
		display: flex;
		align-items: center;
		justify-content: space-between;
		.more{
			font-size: 20rpx;
			color: #AAAAAA;
		}
	}
	
	.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{
			width: 340rpx;
			margin-bottom: 20rpx;
			// box-shadow: 0rpx 0rpx 24rpx 2rpx rgba(0, 0, 0, 0.08);
			border-radius: 16rpx;
			background: #fff;
			
			.icon {
				width: 100%;
				height: 300rpx;
				border-radius: 16rpx 16rpx 0 0;
			}
			
			.info{
				flex: 1;
				padding: 16rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				position: relative;
				.title{
					font-size: 28rpx;
					font-weight: bold;
					width: 100%;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
					margin-top: 10rpx;
				}
				
				.desc{
					font-size: 24rpx;
					color: #AAAAAA;
					overflow: hidden;
					text-overflow: ellipsis;
					/* 弹性伸缩盒子模型显示 */
					display: -webkit-box;
					/* 限制在一个块元素显示的文本的行数 */
					-webkit-line-clamp: 2;
					/* 设置或检索伸缩盒对象的子元素的排列方式 */
					-webkit-box-orient: vertical;
					margin-top: 12rpx;
				}
				
				.price-box{
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-top: 12rpx;
					.left{
						display: flex;
						align-items: flex-end;
						.unit{
							font-size: 20rpx;
							color: $uni-color-primary;
							font-weight: bold;
						}
						.price{
							font-size: 32rpx;
							color: $uni-color-primary;
							font-weight: bold;
						}
					}
					.right{
						font-size: 24rpx;
						color: #AAAAAA;
					}
				}
				
			}
		}
	}
	
	.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>