<template>
	<view class="page-view">
		<top-return text="评测练习"></top-return>

		<view class="icon-view">
			<view class="icon-card">
				<view class="t-icon t-icon-naozhong1" style="margin-right: 10rpx;"></view>
				<view class="time-title">练习时间</view>
				<u-count-down :time="60 * 60 * 1000" format="mm:ss"></u-count-down>
			</view>
			<view class="icon-card" style="margin-left: auto;">
				<view :class="signList.includes(curr)?'t-icon t-icon-ding-copy':'t-icon t-icon-ding'"
					@click="addToSignList"></view>
				<view :class="showNoteBox? 't-icon t-icon-bianji1-copy':'t-icon t-icon-bianji1'"
					@click="showNoteBox = !showNoteBox"></view>
				<view :class="answerSheet? 't-icon t-icon-cengji-copy':'t-icon t-icon-cengji'"
					@click="answerSheet = !answerSheet" style="margin-right: 0;"></view>
			</view>
		</view>

		<view class="note-view" catchtouchmove="true" v-if="showNoteBox">
			<view class="note-box">
				<th-autograph :is-download="false" canvas-id="autograph">
				</th-autograph>
			</view>
		</view>

		<swiper class="swiper-box" :style="{height: clientHeight?clientHeight+'px':'auto'}" :current="curr"
			@change="setCurr">
			<swiper-item v-for="(item,i) in practiceData" :key="i">
				<scroll-view :style="{height: clientHeight?clientHeight+'px':'auto'}">
					<view class="item-card" :id="'card' + i">
						<view class="flex-baseline">
							<view class="YS-title">{{examPractice[cardIndex].title}}{{examPractice[cardIndex].modality}}
							</view>
							<view class="title" style="color: #4169E1;margin-left: 10rpx;">{{i+1}}</view>
							<view class="subtitle" style="margin: 0 10rpx;">/</view>
							<view class="subtitle">{{examPractice[cardIndex].amount}}</view>
							<view class="YS-title" style="margin-left: 10rpx;">题</view>
						</view>

						<view class="tag-fill" style="margin-top: 40rpx;">
							<view class="tag-text">{{item.type}}</view>
						</view>

						<view class="content">{{item.content}}</view>

						<view class="answer-container">
							<view class="answer-box" v-for="(x,y) in item.options" :key="y">
								<view :class="answerList[i].answer == x.option?'answer-tag-select':'answer-tag'"
									@click="selectOption(i,y)">
									<view class="tag-text">{{x.option}}</view>
								</view>
								<view class="answer-content" @click="selectOption(i,y)">{{x.answer}}</view>
							</view>
						</view>
					</view>
				</scroll-view>
			</swiper-item>
			<!-- 答题卡 -->
			<swiper-item>
				<scroll-view :style="{height: clientHeight?clientHeight+'px':'auto'}">
					<view class="item-card">
						<view class="tag-list">
							<view :class="item.answer != ''?'answer-tag-select':'answer-tag'"
								v-for="(item,index) in answerList" :key="index" @click="navTopic(index)"
								style="margin: 40rpx 20rpx;">

								<view class="sign-icon" v-if="signList.includes(index)">
									<view class="t-icon t-icon-ding-copy"></view>
								</view>

								<view class="tag-text">{{item.index + 1}}</view>
							</view>
						</view>
						<view class="btn">
							<view class="btn-text">交卷</view>
						</view>
					</view>
				</scroll-view>
			</swiper-item>
		</swiper>
		<u-action-sheet :show="answerSheet" @close="answerSheet = false" title="答题卡" :round="6">
			<view style="margin: 20rpx 50rpx;">
				<view class="tag-list">
					<view :class="item.answer != ''?'answer-tag-select':'answer-tag'" v-for="(item,index) in answerList"
						:key="index" @click="navTopic(index)" style="margin: 40rpx 20rpx;">

						<view class="sign-icon" v-if="signList.includes(index)">
							<view class="t-icon t-icon-ding-copy"></view>
						</view>

						<view class="tag-text">{{item.index + 1}}</view>
					</view>
				</view>
				<view class="btn">
					<view class="btn-text">交卷</view>
				</view>
			</view>
		</u-action-sheet>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	import thAutograph from "../../components/th-autograph/th-autograph.vue"
	export default {
		components: {
			thAutograph
		},
		computed: {
			...mapState('m_children', ['examPractice'])
		},
		watch: {
			curr: {
				handler(newValue) {
					if (this.curr <= (this.practiceData.length - 1))
						this.getSwiperHeight()
				},
				immediate: true
			},
		},
		data() {
			return {
				cardIndex: '',
				clientHeight: '',
				curr: 0,
				showNoteBox: false,
				answerSheet: false,
				signList: [],
				answerList: '',
				practiceData: [{
						content: '题目内容一的外号对哦奥委会的卡号大家看上课进度吧，阿玛尼的卡乌诺迪克兰的三大我看啦到哪里扣篮代码是你',
						type: '单选题',
						options: [{
								option: 'A',
								answer: '模拟答案一'
							},
							{
								option: 'B',
								answer: '模拟答案二'
							},
							{
								option: 'C',
								answer: '模拟答案三'
							},
							{
								option: 'D',
								answer: '模拟答案四'
							}
						]
					},
					{
						content: '打完就都i阿娇的罗马里克电脑i经常兄长，达瓦ui带坏我很单纯进行只能催啊挖好的快回家，没齿难忘i垃圾我i的急啊离开你们死定了埃及低洼降低AMD扩散低洼会加大科技那么快。3192087jhcuyastgdjahkgsduyagwd',
						type: '单选题',
						options: [{
								option: 'A',
								answer: '模拟答案一'
							},
							{
								option: 'B',
								answer: '模拟答案二'
							},
							{
								option: 'C',
								answer: '模拟答案三'
							},
							{
								option: 'D',
								answer: '模拟答案四'
							}
						]
					},
					{
						content: '打完就都i阿娇的罗马里克电脑i经常兄长，达瓦ui带坏我很单纯进行只能催啊挖好的快回家，没齿难忘i垃圾我i的急啊离开你们死定了埃及低洼降低AMD扩散低洼会加大科技那么快。h217893y1jahsdbyugcjhzxbcytfu1231',
						type: '单选题',
						options: [{
								option: 'A',
								answer: '模拟答案一'
							},
							{
								option: 'B',
								answer: '模拟答案二'
							},
							{
								option: 'C',
								answer: '模拟答案三'
							},
							{
								option: 'D',
								answer: '模拟答案四'
							}
						]
					},
					{
						content: '打完就都i阿娇的罗马里克电脑i经常兄长，达瓦ui带坏我很单纯进行只能催啊挖好的快回家，没齿难忘i垃圾我i的急啊离开你们死定了埃及低洼降低AMD扩散低洼会加大科技那么快32189371298hjahdsu。',
						type: '单选题',
						options: [{
								option: 'A',
								answer: '模拟答案一dkajghcjxzncuktwiajkjbsuydgi2uyhqjkn'
							},
							{
								option: 'B',
								answer: '模拟答案二'
							},
							{
								option: 'C',
								answer: '模拟答案三312897319hjkabcjhxz'
							},
							{
								option: 'D',
								answer: '模拟答案四'
							}
						]
					},
					{
						content: '打完就都i阿娇的罗马里克电脑i经常兄长，达瓦ui带坏我很单纯进行只能催啊挖好的快回家，没齿难忘i垃圾我i的急啊离开你们死定了埃及低洼降低AMD扩散低洼会加大科技那么快。2318209uasiohsdjkaxnczuiywa',
						type: '单选题',
						options: [{
								option: 'A',
								answer: '模拟答案一123i7auhcjkzxgczx'
							},
							{
								option: 'B',
								answer: '模拟答案二'
							},
							{
								option: 'C',
								answer: '模拟答案三31289dyasjkdhciuxcz'
							},
							{
								option: 'D',
								answer: '模拟答案四'
							}
						]
					}, {
						content: '打完就都i阿娇的罗马里克电脑i经常兄长，达瓦ui带坏我很单纯进行只能催啊挖好的快回家，没齿难忘i垃圾我i的急啊离开你们死定了埃及低洼降低AMD扩散低洼会加大科技那么快。adnauiychkajnwyiujagdhjabyuczxg2',
						type: '单选题',
						options: [{
								option: 'A',
								answer: '模拟答案一'
							},
							{
								option: 'B',
								answer: '模拟答案二'
							},
							{
								option: 'C',
								answer: '模拟答案三'
							},
							{
								option: 'D',
								answer: '模拟答案四'
							}
						]
					}, {
						content: '打完就都i阿娇的罗马里克电脑i经常兄长，达瓦ui带坏我很单纯进行只能催啊挖好的快回家，没齿难忘i垃圾我i的急啊离开你们死定了埃及低洼降低AMD扩散低洼会加大科技那么快。',
						type: '单选题',
						options: [{
								option: 'A',
								answer: '模拟答案一'
							},
							{
								option: 'B',
								answer: '模拟答案二'
							},
							{
								option: 'C',
								answer: '模拟答案三'
							},
							{
								option: 'D',
								answer: '模拟答案四'
							}
						]
					}, {
						content: '打完就都i阿娇的罗马里克电脑i经常兄长，达瓦ui带坏我很单纯进行只能催啊挖好的快回家，没齿难忘i垃圾我i的急啊离开你们死定了埃及低洼降低AMD扩散低洼会加大科技那么快。',
						type: '单选题',
						options: [{
								option: 'A',
								answer: '模拟答案一'
							},
							{
								option: 'B',
								answer: '模拟答案二'
							},
							{
								option: 'C',
								answer: '模拟答案三'
							},
							{
								option: 'D',
								answer: '模拟答案四'
							}
						]
					}, {
						content: '打完就都i阿娇的罗马里克电脑i经常兄长，达瓦ui带坏我很单纯进行只能催啊挖好的快回家，没齿难忘i垃圾我i的急啊离开你们死定了埃及低洼降低AMD扩散低洼会加大科技那么快。',
						type: '单选题',
						options: [{
								option: 'A',
								answer: '模拟答案一'
							},
							{
								option: 'B',
								answer: '模拟答案二'
							},
							{
								option: 'C',
								answer: '模拟答案三'
							},
							{
								option: 'D',
								answer: '模拟答案四'
							}
						]
					}, {
						content: '打完就都i阿娇的罗马里克电脑i经常兄长，达瓦ui带坏我很单纯进行只能催啊挖好的快回家，没齿难忘i垃圾我i的急啊离开你们死定了埃及低洼降低AMD扩散低洼会加大科技那么快。',
						type: '单选题',
						options: [{
								option: 'A',
								answer: '模拟答案一'
							},
							{
								option: 'B',
								answer: '模拟答案二'
							},
							{
								option: 'C',
								answer: '模拟答案三'
							},
							{
								option: 'D',
								answer: '模拟答案四'
							}
						]
					}, {
						content: '打完就都i阿娇的罗马里克电脑i经常兄长，达瓦ui带坏我很单纯进行只能催啊挖好的快回家，没齿难忘i垃圾我i的急啊离开你们死定了埃及低洼降低AMD扩散低洼会加大科技那么快。',
						type: '单选题',
						options: [{
								option: 'A',
								answer: '模拟答案一'
							},
							{
								option: 'B',
								answer: '模拟答案二'
							},
							{
								option: 'C',
								answer: '模拟答案三'
							},
							{
								option: 'D',
								answer: '模拟答案四'
							}
						]
					}, {
						content: '打完就都i阿娇的罗马里克电脑i经常兄长，达瓦ui带坏我很单纯进行只能催啊挖好的快回家，没齿难忘i垃圾我i的急啊离开你们死定了埃及低洼降低AMD扩散低洼会加大科技那么快。',
						type: '单选题',
						options: [{
								option: 'A',
								answer: '模拟答案一'
							},
							{
								option: 'B',
								answer: '模拟答案二'
							},
							{
								option: 'C',
								answer: '模拟答案三'
							},
							{
								option: 'D',
								answer: '模拟答案四'
							}
						]
					}, {
						content: '打完就都i阿娇的罗马里克电脑i经常兄长，达瓦ui带坏我很单纯进行只能催啊挖好的快回家，没齿难忘i垃圾我i的急啊离开你们死定了埃及低洼降低AMD扩散低洼会加大科技那么快。',
						type: '单选题',
						options: [{
								option: 'A',
								answer: '模拟答案一'
							},
							{
								option: 'B',
								answer: '模拟答案二'
							},
							{
								option: 'C',
								answer: '模拟答案三'
							},
							{
								option: 'D',
								answer: '模拟答案四'
							}
						]
					}, {
						content: '打完就都i阿娇的罗马里克电脑i经常兄长，达瓦ui带坏我很单纯进行只能催啊挖好的快回家，没齿难忘i垃圾我i的急啊离开你们死定了埃及低洼降低AMD扩散低洼会加大科技那么快。',
						type: '单选题',
						options: [{
								option: 'A',
								answer: '模拟答案一'
							},
							{
								option: 'B',
								answer: '模拟答案二'
							},
							{
								option: 'C',
								answer: '模拟答案三'
							},
							{
								option: 'D',
								answer: '模拟答案四'
							}
						]
					}, {
						content: '打完就都i阿娇的罗马里克电脑i经常兄长，达瓦ui带坏我很单纯进行只能催啊挖好的快回家，没齿难忘i垃圾我i的急啊离开你们死定了埃及低洼降低AMD扩散低洼会加大科技那么快。',
						type: '单选题',
						options: [{
								option: 'A',
								answer: '模拟答案一'
							},
							{
								option: 'B',
								answer: '模拟答案二'
							},
							{
								option: 'C',
								answer: '模拟答案三'
							},
							{
								option: 'D',
								answer: '模拟答案四'
							}
						]
					},
				],
			}
		},
		onLoad(param) {
			this.cardIndex = param.index
			this.getAnswerList()
		},
		methods: {
			//生成自适应高度swiper
			getSwiperHeight() {
				let query = uni.createSelectorQuery().in(this)
				query.select('#card' + this.curr).boundingClientRect(data => {
					this.clientHeight = data.height + 40
					console.log('swiper高度', this.clientHeight);
				}).exec();
			},
			setCurr(e) {
				let thisCurr = e.detail.current || 0;
				this.curr = thisCurr;
			},
			//生成答题卡
			getAnswerList() {
				if (this.answerList === '') {
					this.answerList = []
					this.practiceData.forEach((item, index) => {
						let answer = {
							index: index,
							answer: ''
						}
						this.answerList.push(answer)
					})
					console.log(this.answerList);
				}
			},
			//选择选项
			selectOption(i, y) {
				this.answerList[i].answer = this.practiceData[i].options[y].option
				if (this.curr <= (this.practiceData.length - 1)) {
					setTimeout(() => {
						this.curr = i + 1
					}, 300);
				}
			},
			//导航到题目
			navTopic(index) {
				this.curr = index
				this.answerSheet = false
			},
			//标记题目
			addToSignList() {
				if(this.curr <= (this.practiceData.length - 1)){
					if (this.signList.includes(this.curr)) {
						this.signList = this.signList.filter(x => x != this.curr)
					} else {
						this.signList.push(this.curr)
					}
				}
			}
		}
	}
</script>

<style lang="scss">
	.icon-view {
		margin: 120rpx 20rpx 0 20rpx;
		display: flex;
		align-items: center;

		.icon-card {
			display: flex;
			align-items: center;
			padding: 20rpx;
			height: 50rpx;
			border-radius: $border-radius;
			background-color: #FFF;

			.t-icon {
				margin-right: 40rpx;
				width: 50rpx;
				height: 50rpx;
			}

			.time-title {
				font-size: 30rpx;
				line-height: 30rpx;
				margin-right: 10rpx;
			}

			.u-count-down__text.data-v-463368ae {
				line-height: 30rpx !important;
			}
		}
	}

	.item-card {
		margin: 20rpx;
		padding: 40rpx 40rpx 80rpx 40rpx;
		border-radius: $border-radius;
		background-color: #FFF;

		.content {
			margin-top: 20rpx;
			line-height: 60rpx;
			font-size: 35rpx;
			color: $title;
			word-break: break-all;
		}

		.YS-title {
			line-height: 38rpx;
			font-size: 38rpx;
		}

		.tag-fill {
			background-color: #d8deff;
			width: fit-content;
			margin-left: 0;
			padding: 6rpx 12rpx;

			.tag-text {
				font-size: 28rpx;
				color: #4169E1;
			}
		}

		.answer-container {
			display: flex;
			flex-direction: column;

			.answer-box {
				margin-top: 40rpx;
				display: flex;
				align-items: center;

				.answer-content {
					margin-left: 40rpx;
					font-size: 35rpx;
					line-height: 60rpx;
					color: $title;
					word-break: break-all;
				}
			}
		}
	}

	.answer-tag {
		display: flex;
		flex-shrink: 0;
		align-items: center;
		justify-content: center;
		height: 66rpx;
		width: 66rpx;
		border-radius: 50%;
		border: 2rpx solid $subtitle;

		.tag-text {
			font-size: 35rpx;
			line-height: 35rpx;
			color: $subtitle;
		}
	}

	.answer-tag-select {
		display: flex;
		flex-shrink: 0;
		align-items: center;
		justify-content: center;
		height: 70rpx;
		width: 70rpx;
		border-radius: 50%;
		background-color: #4169E1;

		.tag-text {
			font-size: 35rpx;
			line-height: 35rpx;
			color: #FFF;
		}
	}

	.tag-list {
		display: flex;
		align-items: center;
		align-content: flex-start;
		justify-content: space-between;
		flex-wrap: wrap;

		.sign-icon {
			position: relative;
			left: 20rpx;
			top: -60rpx;
			width: 0rpx;
			height: 0rpx;

			.t-icon {
				height: 50rpx;
				width: 50rpx;
			}
		}
	}

	.btn {
		margin: 40rpx 20rpx 0 20rpx;
		height: 80rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: #4169E1;
		border-radius: 40rpx;

		.btn-text {
			color: #FFF;
			line-height: 36rpx;
			font-size: 36rpx;
			font-family: YSfont;
		}
	}

	.note-view {
		width: 100%;
		height: 550rpx;
		margin: 20rpx 0 5rpx 0;

		.note-box {
			width: 710rpx;
			height: 100%;
			margin: 0 20rpx;
			border-radius: $border-radius;
			overflow: hidden;
			background-color: #FFF;
		}
	}
</style>
