<template>
	<view>
		<view class="top">
			<navigator url="/pages2/bank/question_statistics">
				<view class="left">
					<view class="title">做题统计</view>
					<view class="progress">
						<view class="item-left">
							<view class="desc">
								<text>总进度</text>
							</view>
							<view class="percent">
								68
								<text class="per">%</text>
							</view>
						</view>
						<view class="item-right">
							<view class='up'>
								<text class="orange">58</text>
								<text>/100</text>
							</view>
							
							<view class='down'>
								<text class="orange">已答</text>
								<text>/未答</text>
							</view>
						</view>
					</view>
				</view>
			</navigator>
			<view class="right">
				<view class="title">
					错题集 >
				</view>
				<view class="number">
					35
				</view>
			</view>
			<view class="right">
				<view class="title">
					收藏集 >
				</view>
				<view class="number">
					1
				</view>
			</view>
		</view>
		<view class="title-list">
			<view class="content">
				<view class="list" v-for="(item1,index1) in bankList" :key="index1">
					<template v-if="item1.type==1">
						<view class="moduleItem" @click="clickModule(item1.majorId,index1)">
							<view class="courseName">{{item1.name}}</view>
							<view>
								<image src="/static/icon/up.png" class="icon_up" v-if="!item1.showList"></image>
								<image src="/static/icon/down.png" class="icon_up" v-if="item1.showList"></image>
							</view>
						</view>
						
						<template v-if="item1.showList">
							<view v-for="(item2,index2) in item1.list" :key="index2" >
								<view class="section" @click="changeItem(index1,item2.chapterExamId,item1.type)">
									<image src="/static/icon/up1.png" class="icon_up" v-if="!item2.showList"></image>
									<image src="/static/icon/down1.png" class="icon_up" v-if="item2.showList"></image>
									{{item2.name}}
								</view>
								<view  v-if="item2.showList">
									<view class="article" :class="{active:index3 == 0}"  v-for="(article,index3) in item2.list" :key="index3">
										<view class="flex_auto">{{article.examName}}</view>
										<navigator :url="'/pages2/bank/questionBank?id='+article.examId+'&goodsid='+goodsData.goodsId">
											<view class="btn">做题</view>
										</navigator>
									</view>
								</view>
								<u-line></u-line>
							</view>
						</template>
						
						
					</template>
					
					<template v-if="item1.type ==2">
						<view class="section" @click="changeItem(index1,item1.majorId,item1.type)">
							<image src="/static/icon/up1.png" class="icon_up" v-if="!item1.showList"></image>
							<image src="/static/icon/down1.png" class="icon_up" v-if="item1.showList"></image>
							{{item1.name}}
						</view>
						<view v-if="item1.showList" >
							<view class="article" :class="{active:index2 == 0}"  :key="index3" v-for="(article,index2) in item1.list">
								<view class="flex_auto">{{item1.name}}</view>
								<navigator :url="'/pages2/bank/questionBank?id='+article.majorId+'&goodsid='+goodsData.goodsId">
									<view class="btn">做题</view>
								</navigator>
								
							</view>
						</view>
					</template>
					
					<template v-if="item1.type ==3">
						<view class="article active" >
							<view class="flex_auto">{{item1.name}}</view>
							<navigator :url="'/pages2/bank/questionBank?id='+item1.majorId+'&goodsid='+goodsData.goodsId">
								<view class="btn">做题</view>
							</navigator>
							
						</view>
					</template>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { mapGetters } from 'vuex';
export default {
	data() {
		return {
			goodsData:{},
			bankList:[],
			id:'',
		};
	},
	onUnload() {
		
	},
	computed: { ...mapGetters(['userInfo']) },
	onLoad(option) {
		this.id = option.id
		this.getDetail();
		this.goodsBankList()
	},
	onShow() {
		
	},
	methods: {
		getDetail(){
			this.$api.commonGoodsDetail(this.id).then(res => {
				console.log(res)
				this.goodsData = res.data.data;
				 
			})
		},
		
		goodsBankList() {
			this.$api.goodsBankList({
				goodsId:this.id
			}).then(res => {
				console.log(res)
				this.bankList = res.data.data;
			})
		},
		clickModule(id,index) {
			
			
			if(this.bankList[index].list) {
				this.$set(this.bankList[index],'showList',!this.bankList[index].showList)
				return;
			}
			
			this.$api.goodsChapterList({
				moduleExamId:id
			}).then(res => {
				this.$set(this.bankList[index],'showList',true)
				this.$set(this.bankList[index],'list',res.data.data)
				 
			})
		},
		changeItem(index1,id,type) {
			
			if(type == 1) {
				if(this.bankList[index1].list[index2].list) {
					this.$set(this.bankList[index1].list[index2],'showList',!this.bankList[index1].list[index2].showList)
					return;
				}
				
				this.$api.goodsExamList({
					chapterExamId:id
				}).then(res => {
					
					this.$set(this.bankList[index1].list[index2],'showList',true)
					this.$set(this.bankList[index1].list[index2],'list',res.data.data)
					
					 
				})
				
			} else if(type == 2) {
				if(this.bankList[index1].list) {
					this.$set(this.bankList[index1],'showList',!this.bankList[index1].showList)
					return;
				}
				
				this.$api.goodsExamList({
					chapterExamId:id
				}).then(res => {
					
					this.$set(this.bankList[index1],'showList',true)
					this.$set(this.bankList[index1],'list',res.data.data)
					
					 
				})
			}
			
			
			
		}
	}
};
</script>
<style >
	page{
		background-color: #EAEEF1;
	}
</style>
<style lang="scss" scope>
	
	.top {
		padding:16rpx 16rpx 0;
		display: flex;
		justify-content: space-between;
		.left {
			width: 326rpx;
			height: 180rpx;
			background: #FFFFFF;
			box-shadow: 0px 0px 16rpx 4rpx rgba(145, 156, 178, 0.1);
			border-radius: 16rpx;
			background:#fff;
			padding:20rpx;
			
			.title {
				font-size: 24rpx;
				line-height: 24rpx;
				color: #333333;
			}
			
			.progress {
				margin-top:10rpx;
				display: flex;
				
				.item-left {
					flex:1;
					border-right:1rpx solid #EEEEEE;
					.desc {
						text {
							line-height: 24rpx;
							font-size: 24rpx;
							color: #999999;
						}
					}
					
					.percent {
						margin-top:10rpx;
						line-height: 64rpx;
						font-size: 64rpx;
						font-weight: bold;
						color: #007AFF;
					}
					
					.per {
						font-size: 30rpx;
						color: #007AFF;
					}
				}
				
				.item-right {
					padding-left:10rpx;
					flex:1;
					
					text {
						
						line-height: 24rpx;
						font-size: 24rpx;
						color: #999999;
					}
					
					.orange {
						line-height: 24rpx;
						font-size: 24rpx;
						font-weight: bold;
						color: #FF9500;
					}
					
					.down {
						margin-top:40rpx;
					}
				}
			}
		}
		
		.right {
			width: 180rpx;
			height: 180rpx;
			background: #FFFFFF;
			box-shadow: 0px 0px 16rpx 4rpx rgba(145, 156, 178, 0.1);
			background:#fff;
			padding:20rpx;
			
			.title {
				font-size: 24rpx;
				line-height: 24rpx;
				color: #333333;
			}
			
			.number {
				font-weight: bold;
				text-align: center;
				margin-top:46rpx;
				font-size: 64rpx;
				line-height: 64rpx;
				color: #007AFF;
			}
		}
	}
	
	
	.courseName{
		white-space:nowrap;
		overflow:hidden;
		text-overflow:ellipsis; 
	}
	
	
	.moduleItem{
		height: 80rpx;
		color: #333333;
		font-size: 32rpx;
		line-height: 80rpx;
		font-weight: bold;
		display: flex;
		justify-content: space-between;
	
	}
	
	.icon_up{
		width: 32rpx;
		height: 32rpx;
	}
	
	.title-list {
		background: #EAEEF1;
		padding:16rpx 16rpx 124rpx;
		.content {
			
			.list {
				background:#fff;
				margin-bottom:30rpx;
				overflow: hidden;
				border-radius: 16rpx;
				padding:10rpx 16rpx;
				
				.module {
					font-size: 30rpx;
					color: #333333;
					
					.icon {
						margin-right:10rpx;
					}
				}
				
				.section {
					font-size: 30rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #333333;
					white-space:nowrap;
					overflow:hidden;
					text-overflow:ellipsis; 
					margin: 20rpx 0;
					display: flex;
					align-items: center;
				}
				
				.article {
					height:80rpx;
					display: flex;
					align-items: center;
					margin-left:72rpx;
					font-size: 24rpx;
					color: #666666;
					border-bottom: 1rpx solid #EEEEEE;
					display: flex;
					
					.flex_auto{
						flex:1;
					}
					
					&:nth-last-of-type(1) {
						border:0;
					}
					
					&.active {
						color:#007AFF;
						
						
						.btn {
							width: 96rpx;
							height: 48rpx;
							line-height: 48rpx;
							text-align: center;
							color:#fff;
							font-size: 30rpx;
							border-radius:24rpx;
							background: #007AFF;
							margin-left:36rpx;
							border-radius: 24rpx;
						}
					}
				}
			}
		}
	}
	
</style>
