<template>
	<uni-popup ref="popupRef" background-color="#fff" type="left" class="popup-container">
		<view>
			<uni-icons type="left" size="30" @click="handleBack"></uni-icons>
			<text>成绩</text>
		</view>
		<w-swiper :list="list" :swiperHeight="300" :positionIndex="current">
			<template v-slot:default="{item,index}">
				<view class="body" v-if="item.mta_show">
					{{item}}
					
					<danxuan :question="item" showError v-if="item.type == '1'"></danxuan>
					<panduan :question="item" showError v-if="item.type == '2'"></panduan>
					<tiankong :question="item" showError v-if="item.type == '3'"></tiankong>
					<!-- 答案解析 -->
					<button @click="showJiexiPopup(item)">show</button>
					
					<!-- 答案 -->
					<view>答案{{showAnswerResult(item)}}</view>
					<!-- 你的答案 -->
					<view>您的答案:{{showAnswerReply(item)}}</view>
				</view>
			</template>
		</w-swiper>

		<!-- 解析浮层数据 -->
		<questionJiexi ref="jiexiRef"></questionJiexi>
	</uni-popup>
</template>

<script setup>
	import questionJiexi from '@/components/questionJiexi/questionJiexi.vue';
	import wSwiper from '@/components/wSwiper/wSwiper.vue';
	import danxuan from "@/components/question/danxuan.vue";
	import panduan from "@/components/question/panduan.vue";
	import tiankong from "@/components/question/tiankong.vue";
	import {
		useQuestionTools
	} from "@/components/question/useQuestionTools.js";
	
	const {
		getLetterByIndex
	} = useQuestionTools();

	import {
		ref
	} from "vue";

	const props = defineProps({
		list: {
			type: Array,
		},
		jieId: {
			type: [String, Number]
		},
		zhangId: {
			type: [String, Number]
		},
		nianji: {
			type: [String, Number]
		},
		xueqi: {
			type: [String,Number]
		}
	})

	const current = ref(0)
	const popupRef = ref(null)
	const jiexiRef = ref(null);

	// 切换成绩
	function showPopup() {
		popupRef.value.open()
	}

	// 展示
	function showJiexiPopup(data) {
		jiexiRef.value.showPopup(data);
	}

	function handleBack() {
		// 从 单元测试 到 岛 的路由参数
		uni.navigateTo({
			url: `/pages/study/index?nianji=${props.nianji}&xueqi=${props.xueqi}&zhangId=${props.zhangId}&jieId=${props.jieId}`
		})
	}

	function showAnswerResult(item) {
		if (item.type == 1) {
			// 单选题
			return getLetterByIndex(item.result)
		} else if (item.type == 3){
			if (item.result == 1) {
				return '正确'
			} else {
				return '错误'
			}
		} else {
			return item.result
		}
	}
	
	
	function showAnswerReply(item) {
		if (item.type == 1) {
			// 单选题
			return getLetterByIndex(item.reply)
		} else if (item.type == 3){
			if (item.reply == 1) {
				return '正确'
			} else {
				return '错误'
			}
		} else {
			return item.reply
		}
	}

	defineExpose({
		showPopup
	})
</script>

<style lang="scss">
	.popup-container {
		::v-deep .uni-popup__wrapper.left {
			width: 100vw;
		}
	}
</style>