<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>
				<view class="box">
					<view class="hflex acenter jbetween">
						<view class="hflex acenter">
							<view class="name">{{examPaper[index].name}}</view>
						</view>
						<view class="hflex acenter">
							<view class="answer">
								<view class="text_style1"><span style="font-size: 40rpx;">{{index + 1}}</span>/{{examPaper.length}}</view>
							</view>
							<u-icon v-if="examPaper[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">
					<view class="type">{{examPaper[index].type_name}}</view>
					<view class="content">
						<u-parse :content="examPaper[index].title"></u-parse>
					</view>
					<view class="">
						<block v-for="(item2,inx2) in examPaper[index].items" :key="inx">
							<view class="hflex acenter cell" @click="select(inx2)">
								<view class="options" :class="choice.indexOf(item2.ladder_title) !== -1 ? 'active' : ''">{{item2.ladder_title}}</view>
								<view class="options_value">{{item2.ladder_num}}</view>
							</view>
						</block>
					</view>
				</view>
			</view>
			<view class="box" v-if="examPaper[index].state">
				<view class="answer_bg hflex acenter jbetween">
					<view class="text_style2">正确答案：{{examPaper[index].success_answer}}</view>
					<view class="text_style2">你的答案：{{values.answer}}</view>
				</view>
			</view>
		</view>
		<view class="bottom hflex acenter jcenter">
			<view v-if="index + 1 == examPaper.length" class="btn1" @click="result">返回</view>
			<view v-else class="btn1" @click="nextExam">下一题</view>
		</view>
	</view>
</template>

<script>
	import $api from '@/static/js/api.js'
	export default {
		data() {
			return {
				examPaper: [],
				index: 0,
				values: [],
				course_id: 0,
				choice: '',
			}
		},
		onLoad(options) {
			this.course_id = options.id
			this.getCollectList()
		},
		methods: {
			leftClick() {
				
			},
			// 获取收藏详情
			getCollectList() {
				var that = this
				$api.req({
					url: '/api/User/collectionQuestionsDetailList',
					data: {
						course_id: that.course_id
					}
				}, function(res) {
					console.log(res)
					if(res.code == 1) {
						that.examPaper = res.data
					}
				})
			},
			/// 收藏题目
			collect(type) {
				var that = this
				var questions_id = that.examPaper[that.index].questions_id
				var info_id = that.examPaper[that.index].info_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.getCollectList()
				})
				// this.examPaper.exam[this.index].collect = !this.examPaper.exam[this.index].collect
			},
			
			// 选择答案
			select(val) {
				var that = this
				var index = that.index
				if (that.examPaper[index].type !== 2) {
					that.choice = that.examPaper[index].items[val].ladder_title
					that.values = {
						id: that.index,
						answer: that.choice
					}
					that.examPaper[index].state = true
				} else {
					that.choice = that.choice + that.examPaper[index].items[val].ladder_title + '、'
					that.values = {
						id: that.index,
						answer: that.choice
					}
					setTimeout(function() {
						that.examPaper[index].state = true
					},1000) 
					// that.examPaper[index].state = true
				}
				// if (that.examPaper[index].type !== 2) {
				// 	that.examPaper[index].value = that.values[length]
				// 	that.examPaper[index].state = true
				// } else {
				// 	let values = that.values.join(',')
				// 	that.examPaper[index].value = values
				// 	setTimeout(function() {
				// 		that.examPaper[index].state = true
				// 	},1000) 
				// }
				
			},
			// 下一题
			nextExam() {
				this.values = []
				this.index ++;
			},
			result() {
				uni.navigateBack({
					delta: 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;
		}
	}
</style>