<template>
	<view>
		<!-- 导航区域 -->
		<customNavbarVue title="摄像头确认" :show-back-btn="true" @back="handleBack"></customNavbarVue>
		
		<zhuapaiConfirm ref="zhuapaiConfirmRef" @success="zpConfirmSuccess" key="1"></zhuapaiConfirm>
			
		<button @click="zpConfirmSuccess">确认</button>	
	</view>
</template>

<script setup>
	import {
		onLoad,
		onShow,
		onHide
	} from "@dcloudio/uni-app";
	import {
		ref,nextTick
	} from "vue";
	import zhuapaiConfirm from "@/components/zhuapaiConfirm/index.vue";
	import customNavbarVue from "@/components/custom-navbar/custom-navbar.vue";

	const opt = ref(null);
	const zhuapaiConfirmRef = ref(null);

	onLoad((options) => {
		opt.value = options;
		setTimeout(() => {
			zhuapaiConfirmRef.value.showDialog()
		},1000)
	})

	function zpConfirmSuccess() {
		uni.redirectTo({
			url: `/pages/client/Kaoshi/exam?ksId=${opt.value.ksId}&zhuapai=${opt.value.zhuapai}&userKaozhengId=${opt.value.userKaozhengId}&from=${opt.value.from}`
		})
	}

	function zpConfirmError(e) {
    uni.showToast({
      icon: 'none',
      title: '考试环境异常请检测摄像头是否正常',
      duration: 3000,
      mask: true // 防止触摸穿透
    })
    setTimeout(() => {
      handleBack();
    }, 3000)
	}

	function zpConfirmCancel() {
		handleBack();
	}

	function handleBack() {
		const pages = getCurrentPages();
		if (pages.length > 1) {
			uni.navigateBack()
		} else {
			history.back();
		}
	}
</script>

<style>

</style>