<template>
	<view class="web_box vflex active jbetween">
		<view class="" >
			<u-navbar height="44" leftIcon="arrow-left" leftIconColor="#000" leftText="题目解析" @leftClick="leftClick" :autoBack="true" bgColor="#fff">
			</u-navbar>
			<view class="box">
				<view class="hflex acenter jend">
					<view class="text_style1" v-if="examPaper.log_info.length == 0"><span style="font-size: 40rpx;">{{index}}</span>/{{examPaper.log_info.length}}</view>
					<view class="text_style1" v-else><span style="font-size: 40rpx;">{{index + 1}}</span>/{{examPaper.log_info.length}}</view>
				</view>
				<view class="hflex acenter jbetween">
					<view class="hflex acenter">
						<view class="name">{{examPaper.name}}</view>
					</view>
					<view class="hflex acenter">
						<view class="answer">
							<u-icon name="order" color="#333333" size="22" @click="open"></u-icon>
						</view>
						<u-icon v-if="examPaper.log_info[index].is_collection == 1" name="star-fill" color="#FA6400" size="22" @click="collect(0)"></u-icon>
						<u-icon v-else name="star" color="#333333" size="22" @click="collect(1)"></u-icon>
					</view>
				</view>
			</view>
			<view class="box" v-if="examPaper.log_info.length !== 0">
				<!-- <view class="type">{{examPaper.log_info[index].type ==1}}单选题</view> -->
				<view class="type" v-if="examPaper.log_info[index].type == 1">单选题</view>
				<view class="type" v-else-if="examPaper.log_info[index].type == 2">多选题</view>
				<view class="type" v-else-if="examPaper.log_info[index].type == 3">判断题</view>
				<view class="content">
					<u-parse :content="examPaper.log_info[index].title"></u-parse>
				</view>
				<view class="">
					<block v-for="(item,inx) in examPaper.log_info[index].items" :key="inx">
						<view class="hflex acenter cell">
							<view v-if="examPaper.log_info[index].type == 2" class="options" :class="examPaper.log_info[index].success_answer.indexOf(item.ladder_title) != -1 ? 'active' : ''">{{item.ladder_title}}</view>
							<view v-else class="options" :class="item.ladder_title == examPaper.log_info[index].success_answer ? 'active' : ''">{{item.ladder_title}}</view>
							<view class="options_value">{{item.ladder_num}}</view>
						</view>
					</block>
				</view>
			</view>
			<view class="box" v-if="examPaper.log_info.length !== 0">
				<view class="answer_bg hflex acenter jbetween">
					<view class="text_style2">正确答案：{{examPaper.log_info[index].success_answer}}</view>
					<view class="text_style2">你的答案：{{examPaper.log_info[index].member_answer}}</view>
				</view>
			</view>
			<view class="box vflex acenter jcenter" v-if="examPaper.log_info.length == 0 && state == 1">
				<image src="../../../static/images/common/see_none.png"  class="img_none"></image>
				<view class="text_none">
					满分答卷
				</view>
			</view>
		</view>
		<view class="bottom hflex acenter jcenter" >
			<view v-if="index === examPaper.log_info.length || index === examPaper.log_info.length - 1" class="btn1" @click="result">返回</view>
			<view v-else class="btn1" @click="nextExam">下一题</view>
		</view>
		<!-- 答题卡 -->
		<u-popup :show="showSheet" @close="close" mode="bottom" :round="10">
			<view class="popup_sheet vflex acenter jcenter">
				<view class="hflex acenter jbetween" style="width: 100%;">
					<view></view>
					<view class="popup_title">答题卡</view>
					<u-icon name="close" color="#333333" size="18" @click="close"></u-icon>
				</view>
				<view class="hflex acenter fwrap">
					<block v-for="(item,index) in examPaper.log_info" :key="index">
						<view class="options options_item active" @click="toTest(index)">{{index + 1}}</view>
					</block>
				</view>
				<view class="sheet_bottom">
					<view class="sheet_submit" @click="result">返回</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import $api from '@/static/js/api.js'
	export default {
		data() {
			return {
				examPaper: {},
				index: 0,
				showSheet:false,
				state: 0,
				log_id: 1,
			}
		},
		onLoad(options) {
			this.state = options.state
			this.log_id = options.log_id
			this.sellQuestionsLog()
		},
		methods: {
			leftClick() {
				
			},
			sellQuestionsLog() {
				var that = this
				$api.req({
					url: '/api/User/sellQuestionsLog',
					data: {
						log_id: that.log_id,
						state: that.state
					}
				}, function(res) {
					console.log("解析",res)
					if (res.code == 1) {
						that.examPaper = res.data
					}
				})
			},
			// 收藏题目
			collect(type) {
				var that = this
				var questions_id = that.examPaper.log_info[that.index].questions_id
				var info_id = that.examPaper.log_info[that.index].id
				$api.req({
					url: '/api/User/collectionQuestions',
					data: {
						id: that.examPaper.course_id,
						questions_id: questions_id,
						info_id: info_id,
						type: type
					}
				}, function(res) {
					console.log(res);
					$api.info(res.msg)
					that.sellQuestionsLog()
				})
				// this.examPaper.exam[this.index].collect = !this.examPaper.exam[this.index].collect
			},
			// 下一题
			nextExam() {
				this.values = []
				this.index ++;
			},
			// 打开答题卡
			open() {
				this.showSheet = true
			},
			// 关闭答题卡
			close() {
				this.showSheet = false
			},
			// 答题卡
			toTest(inx) {
				this.index = inx
				this.close()
			},
			// 返回
			result() {
				$api.jump(-1)
			}
		}
	}
</script>

<style scoped lang="scss">
	.web_box::v-deep {
		
		.u-navbar {
			width: 100%;
			box-sizing: border-box;
			padding: 36px 16px 58rpx 0;
		}
		.box {
			width: 100%;
			box-sizing: border-box;
			padding: 30rpx;
			margin-top: 20rpx;
			background: #FFFFFF;
		}
		.name {
			font-size: 34rpx;
			font-weight: 500;
			color: #999999;
		}
		.text_style1 {
			font-size: 26rpx;
			font-weight: 400;
			color: #999999;
		}
		.answer {
			padding-right: 38rpx;
		}
		.type {
			width: 126rpx;
			height: 40rpx;
			background: #2988FE;
			border-radius: 16px;
			font-size: 26rpx;
			font-weight: 500;
			color: #FFFFFF;
			line-height: 40rpx;
			text-align: center;
		}
		.content {
			width: 100%;
			box-sizing: border-box;
			padding: 16rpx 0 60rpx;
		}
		.options {
			width: 72rpx;
			height: 72rpx;
			border: 1px solid #979797;
			border-radius: 50%;
			font-size: 40rpx;
			font-weight: 600;
			color: #666666;
			text-align: center;
			line-height: 72rpx;
		}
		.options_value {
			font-size: 36rpx;
			font-weight: 400;
			color: #333333;
			letter-spacing: 1px;
			padding-left: 26rpx;
		}
		.cell {
			padding: 20rpx;
		}
		.active {
			background: #2988FE;
			color: #FFFFFF !important;
		}
		.answer_bg {
			width: 690rpx;
			height: 94rpx;
			background: #F8F8F8;
			border-radius: 32rpx;
			font-size: 32rpx;
			font-weight: 400;
			color: #333333;
			box-sizing: border-box;
			padding: 0 64rpx;
		}
		.bottom {
			width: 100%;
			height: 83px;
			background: #FFFFFF;
			margin-top: 20rpx;
		}
		.btn1 {
			width: 690rpx;
			height: 80rpx;
			background: linear-gradient(135deg, #53BDFF 0%, #2988FE 100%);
			border-radius: 40rpx;
			font-size: 36rpx;
			font-weight: 500;
			color: #FFFFFF;
			text-align: center;
			line-height: 80rpx;
		}
		.popup_sheet {
			width: 100%;
			background: #FFFFFF;
			border-radius: 24px;
			box-sizing: border-box;
			padding: 28rpx 32rpx;
		}
		.popup_title {
			font-size: 40rpx;
			font-weight: 500;
			color: #2988FE;
		}
		.options {
			width: 72rpx;
			height: 72rpx;
			border: 1px solid #979797;
			border-radius: 50%;
			font-size: 40rpx;
			font-weight: 600;
			color: #666666;
			text-align: center;
			line-height: 72rpx;
		}
		.options_item {
			margin: 60rpx 66rpx 0 0;
		}
		.options_item:nth-child(5n) {
			margin: 60rpx 0 0 0;
		}
		.sheet_bottom {
			margin-top: 106rpx;
		}
		.sheet_submit {
			width: 690rpx;
			height: 80rpx;
			background: linear-gradient(135deg, #53BDFF 0%, #2988FE 100%);
			border-radius: 40rpx;
			font-size: 36rpx;
			font-weight: 500;
			color: #FFFFFF;
			text-align: center;
			line-height: 80rpx;
		}
		.text_none {
			font-size: 32rpx;
			color: #333333;
			margin-top: 44rpx;
		}
		.img_none {
			margin-top: 300rpx;
			width: 524rpx;
			height: 308rpx;
		}
	}
</style>