<template>
	<view class="content">
		<view class="content__titletop">
			<view class="content__title">试卷名称-综合素质测评</view>
			<view class="content__subtitle">(满分: 100分)</view>
		</view>

		<view class="content__info">
			<text>姓名: 测试者</text>
			<text>分数: 85分</text>
			<text>考试时间: 2024-12-30</text>
		</view>

		<view class="content__sign">
			<view style="margin-right: 10rpx">签字: </view>
			<u-image width="120rpx" height="70rpx" model="widthFix" src="https://img.alicdn.com/img/i1/131787161/O1CN01z67Qvv22lnCzgPob4_!!0-saturn_solar.jpg_.webp" />
		</view>

		<view class="counter">
			当前试题: <text style="color: orange">{{ current + 1 }}</text
			>/{{ questionList.length }}
		</view>

		<view class="topic">
			<view class="title">
				<text class="tag_title">
					{{ handleCalcQuestType(questionList[current].questiontype) }}
				</text>
				{{ current + 1 }}.
				<text>{{ questionList[current].questiondry }}</text>
			</view>
			<view v-if="questionList[current].questiontype === '1'" class="options">
				<view v-for="(item, index) in ['A', 'B', 'C', 'D']" :key="index" :class="['item', questionList[current].answer === item ? 'active' : '']">
					<text class="option">{{ item }}</text>
					<text class="text">
						{{ questionList[current]['option' + item.toLocaleLowerCase()] }}
					</text>
				</view>
			</view>
			<view v-if="questionList[current].questiontype === '2'" class="options">
				<view v-for="(item, index) in ['A', 'B', 'C', 'D']" :key="index" :class="['item', questionList[current].answer && questionList[current].answer.indexOf(item) !== -1 ? 'active' : '']">
					<text class="option">{{ item }}</text>
					<text class="text">
						{{ questionList[current]['option' + item.toLocaleLowerCase()] }}
					</text>
				</view>
			</view>
			<view v-if="questionList[current].questiontype === '3'" class="options">
				<view v-for="(item, index) in ['A', 'B']" :key="index" :class="['item', questionList[current].answer === item ? 'active' : '']">
					<text class="option">
						{{ questionList[current]['option' + item.toLocaleLowerCase()] }}
					</text>
					<text class="text"></text>
				</view>
			</view>
			<view class="correct-answer">
				<text>正确答案</text>
				<view v-if="questionList[current].questiontype === '3'">
					{{ questionList[current].answerright === 'A' ? '对' : '错' }}
				</view>
				<view v-else>{{ questionList[current].answerright || '无' }}</view>
        <text>权威解读</text>
        <view>{{ questionList[current].descr || "无" }}</view>
			</view>
		</view>

		<view class="footer">
			<block v-if="current !== 0">
				<u-button
					shape="circle"
					:custom-style="{
						width: current === questionList.length - 1 ? '100%' : '45%'
					}"
					text="上一题"
					@click="current--"
				/>
			</block>
			<block v-if="current !== questionList.length - 1">
				<u-button
					shape="circle"
					type="primary"
					:custom-style="{
						width: current === 0 ? '100%' : '45%',
						marginLeft: current === 0 ? '0' : '10%'
					}"
					text="下一题"
					@click="current++"
				/>
			</block>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			pageSize: 10,
			currentPage: 1,
			totalPage: 0,
			questionList: [],
			// 新增当前激活的题目索引
			current: 0,
			questionTypeMap: {
				1: '单选题',
				2: '多选题',
				3: '判断题',
				4: '填空题',
				5: '简答题'
			}
		}
	},

	onShow() {
		this.resetList()
	},

	mounted() {},

	methods: {
		async getData() {
			this.questionList = [
				{
					stageexamrecordId: '7cea826c3c974cb69028dd0624b632ba',
					stageexampaperId: null,
					stageexamId: null,
					questionId: null,
					userId: null,
					answer: 'B',
					answerright: 'B',
					creator: null,
					createTime: null,
					operator: null,
					operatTime: null,
					isDelete: null,
					corpinfoId: null,
					studytaskId: null,
					paperId: null,
					classId: null,
					studentId: null,
					paperQuestionId: 'c413570fac8b49d8bd3ac27e223beb48',
					questionnumber: null,
					questiontype: '1',
					questiondry: '发生生产安全事故以后，单位负责人应当在（  ）小时内向当地县级应急管理部门和负有安全生产监督管理职责的有关部门报告。',
					optiona: '2',
					optionb: '1',
					optionc: '4',
					optiond: '半',
					descr: '17',
					score: '50.0',
					labelType: '6a8577ad5cf84e259f6a601a0c253726',
					coursewarename: '测试40秒',
					labelTypeName: '规范标准',
					checkList: null,
					count: null,
					videocoursewareId: null
				},
				{
					stageexamrecordId: '956a9175accc4c96b062eac68a5cdc28',
					stageexampaperId: null,
					stageexamId: null,
					questionId: null,
					userId: null,
					answer: 'C',
					answerright: 'C',
					creator: null,
					createTime: null,
					operator: null,
					operatTime: null,
					isDelete: null,
					corpinfoId: null,
					studytaskId: null,
					paperId: null,
					classId: null,
					studentId: null,
					paperQuestionId: 'b8203efc27c04afc8b692fc2c82095ca',
					questionnumber: null,
					questiontype: '2',
					questiondry: '发生生产安全事故以后，单位负责人应当在（  ）小时内向当地县级应急管理部门和负有安全生产监督管理职责的有关部门报告。',
					optiona: '2',
					optionb: '1',
					optionc: '4',
					optiond: '半',
					descr: '17',
					score: '50.0',
					labelType: '2c0f587e982641c7965182826f9c41ac',
					coursewarename: '测试40秒',
					labelTypeName: '法律法规',
					checkList: null,
					count: null,
					videocoursewareId: null
				}
			]
			this.totalPage = 2
			this.totalCount = this.questionList.length
		},
		resetList() {
			this.pageSize = 10
			this.currentPage = 1
			this.questionList = []
			this.getData()
		},
		handleCalcQuestType(type) {
			return `(${this.questionTypeMap[type]})`
		}
	}
}
</script>

<style scoped lang="scss">
.content {
	padding: 16rpx;

	.content__titletop {
		text-align: center;

		.content__title {
			font-size: 34rpx;
			font-weight: 600;
		}

		.content__subtitle {
			margin-top: 8rpx;
			font-size: 24rpx;
		}
	}

	.content__info {
		font-size: 34rpx;
		margin-top: 36rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.content__sign {
		margin-top: 18rpx;
		font-size: 34rpx;
		display: flex;
		align-items: center;
	}

	.counter {
		font-size: 28rpx;
		margin: 15rpx 0;
		text-align: end;
	}

	.topic {
		box-sizing: border-box;

		.tag_title {
			font-size: 28rpx;
			background-color: #94f0bd;
			color: #5ac725;
			border-radius: 8rpx;
			padding: 2rpx 8rpx;
			margin-right: 10rpx;
		}

		.title {
			font-size: 32rpx;
			font-weight: 600;

			.question-type {
				border-radius: 40rpx;
				padding: 4rpx 14rpx;
				border: 1rpx solid #3c9cff;
				font-size: 28rpx;
				color: #3c9cff;
			}
		}

		.options {
			margin-top: 40rpx;

			.item {
				position: relative;
				margin-top: 40rpx;
				color: #696868;

				&.active {
					color: #3c9cff;

					.option {
						background-color: #3c9cff;
						color: #fff;
					}
				}

				.option {
					background-color: #eee;
					border-radius: 80rpx;
					width: 65rpx;
					height: 65rpx;
					line-height: 65rpx;
					text-align: center;
					font-size: 30rpx;
					display: inline-block;
				}

				.text {
					margin-left: 30rpx;
					height: 60rpx;
					line-height: 60rpx;
				}
			}
		}

		.correct-answer {
			margin-top: 40rpx;

			text {
				display: inline-block;
				margin-top: 40rpx;
				color: #696868;
				font-size: 30rpx;
				font-weight: bold;
			}

			view {
				margin-top: 20rpx;
				color: #333;
				padding: 20rpx;
				background-color: #eee;
				border-radius: 10rpx;
				font-size: 30rpx;
			}
		}
	}

	.footer {
		position: fixed;
		bottom: 0;
		width: 100%;
		left: 0;
		padding: 20rpx;
		box-sizing: border-box;
		background: #fff;
		text-align: center;
		display: flex;
	}
}
</style>
