<template>
 <view>
	 考试
 </view>
</template>

<script setup>
	import {
		getExamList,
		kaoShiApply,
		getClientKaoshiInfo
	} from "@/api/exam.js";
	import {
		onReady,
	} from "@dcloudio/uni-app"
	import {
		reactive,
		ref
	} from "vue";
	import kaoshixuzhi from "@/components/kaoshixuzhi/kaoshixuzhi.vue"

	const activeKs = ref(null);
	const scrollRef = ref(null);
	const examNoticeInfo = ref(null);
	const ksxzRef = ref(null);

	const tabData = [{
			label: "可以考试",
			value: 1,
		},
		{
			label: "已结束",
			value: 4,
		}
	]

	function goKaoshiPage(data) {
		/* uni.redirectTo({
			url: `/pages/exam/exam?ksId=${data.ksId}&zhuapai=${data.zhuapai}`
		}) */
		uni.navigateTo({
			url: `/pages/exam/exam?ksId=${data.ksId}&zhuapai=${data.zhuapai}`
		})
	}
	
	function handleConfirm() {
		goKaoshiPage(activeKs.value)
	}

	function showKaoshiXuzhi() {
		const option = {
			ksId: activeKs.value.ksId
		}
		getClientKaoshiInfo(option).then(res => {
			examNoticeInfo.value = res.data;
			// 校验抓拍
			doCheckZhuapai()
		})

	}

	function doCheckZhuapai() {
		if (examNoticeInfo.value.zhuapai) {
			// 存在抓拍
		} else {
			// 不存在抓拍
			ksxzRef.value.showDialog(examNoticeInfo.value)
		}
	}

	function handleClick(data) {
		activeKs.value = data;
		if (data.status == 0) {
			// 未开始
			// goKaoshiPage(data);
			showKaoshiXuzhi()
		}
		if (data.status == 1) {
			// 可以考试
			// goKaoshiPage(data);
			showKaoshiXuzhi()
		}
		if (data.status == 2) {
			// 再次考试
			// goKaoshiPage(data);
			showKaoshiXuzhi()
		}
		if (data.status == 3) {
			// 考试中
			// goKaoshiPage(data);
			showKaoshiXuzhi()
		}
		if (data.status == 4) {
			// 已结束
			uni.showToast({
				title: '考试已结束',
				icon: 'none'
			})
		}
		if (data.status == 5) {
			// 未报名
			kaoShiApply({
				ksId: data.ksId
			}).then(res => {
				uni.showToast({
					title: '报名成功',
					icon: 'none'
				})
				scrollRef.value.onRefresh()
			})
		}

	}

</script>

<style lang="scss">

</style>