<template>
	<view class="shouye-card-box kaoshi-card-box">
		<!-- card title -->
		<view class="card-head-box">
			<view class="card-line-title">考试</view>
			<view class="card-more" @click="checkMore" v-if="data.count">更多<text class="more-num">{{data.count}}</text><icon class="more-jt"></icon></view>
		</view>
		
		<!-- kaoshi title -->
		<view class="card-name-box"> 	
			<view class="card-name" v-if="data.zyName"><icon></icon>{{data.zyName}}</view>
			<text class="card-level">{{data.zyLevelName}}</text>
			<!-- <view class="card-name"><icon></icon>考试名称</view>
			<text class="card-level">初级</text> -->
		</view>
		<!-- 内容区域 -->
		<view class="card-content-box kaoshi-content-box">
			<view class="card-content-item">
				<icon :style="{ backgroundImage: 'url(' + data.iconsArr.timeIcon + ')' }"></icon>
				<view class="content-text-box">
					<text>时间</text>
					<view>{{data.totalTm}}分钟</view>
				</view>
			</view>
			<view class="card-content-item">
				<icon :style="{ backgroundImage: 'url(' + data.iconsArr.numIcon + ')' }"></icon>
				<view class="content-text-box">
					<text>次数</text>
					<view>{{data.maxTimes ? data.loseTimes:'不限'}}次</view>
				</view>
			</view>
			<view class="card-content-item">
				<icon :style="{ backgroundImage: 'url(' + data.iconsArr.sumIcon + ')' }"></icon>
				<view class="content-text-box">
					<text>总分</text>
					<view>{{data.ksScore}}分</view>
				</view>
			</view>
			<view class="card-content-item">
				<icon :style="{ backgroundImage: 'url(' + data.iconsArr.jgIcon + ')' }"></icon>
				<view class="content-text-box">
					<text>及格分</text>
					<view>{{data.okScore}}分</view>
				</view>
			</view>
		</view>
		<!-- 底部 -->
		<view class="card-bottom-box">
			<button type="default" class="index-card-btn" v-if="data.status == 1" @click="handleStart(data)">进行考试</button>
			<button type="default" class="index-card-btn" v-if="data.status == 2" @click="handleStart(data)">进行考试</button>
			<button type="default" class="index-card-btn" v-if="data.status == 3" @click="handleContinue(data)">考试中</button>
		</view>
		
		<!-- 考试须知 -->
		<kaoshixuzhiVue ref="ksxzRef" @confirm="handleConfirmKs" key="1"></kaoshixuzhiVue>
		<!-- 身份确认 -->
		<identificationVue ref="shenfenRef" @confirm="handleConfirmIdent" @changeData="handleChangeIdentification" key="2"></identificationVue>
	</view>
</template>

<script setup>
	import kaoshixuzhiVue from "@/components/kaoshixuzhi/kaoshixuzhi.vue";
	import identificationVue from "@/components/identification/identification.vue";
	import {useIdentificationTools} from "@/utils/examTools.js"
	import * as kaoshiApi from "@/api/kaoshi.js"
	import { ref } from "vue"
	
	const {	saveIdentCache, getIdentCache, removeIdentCache } = useIdentificationTools();
	defineProps({
		data: {
			type: Object,
		}
	})
	const ksxzRef = ref(null)
	const shenfenRef = ref(null)
	const activeks = ref(null);
	
	function checkMore() {
		uni.navigateTo({
			url: '/pages/client/Kaoshi/list?from=shouye'
		})
	}
	
	// 修改身份
	function handleChangeIdentification() {
		uni.navigateTo({
			url:'/pages/client/my/myInfo?from=shouye'
		})
	}
	
	function handleConfirmIdent(data) {
		saveIdentCache(activeks.value.ksId, true);
		ksxzRef.value.showDialog(activeks.value)
	}
	
	
	function handleStart(data) {
		activeks.value = data;
		const result = getIdentCache(data.ksId);
		if (result) {
			ksxzRef.value.showDialog(data)
		} else {
			kaoshiApi.getClientUserInfo({ksId: data.ksId}).then(res => {
				shenfenRef.value.showDialog(res.data);
			})
		}
	
	}
	
	function handleConfirmKs(data) {
		checkKaoshi(data)
	}
	
	function checkKaoshi(item) {
		uni.navigateTo({
			url: `/pages/client/Kaoshi/examCamera?ksId=${item.ksId}&zhuapai=${activeks.value.zhuapai}&userKaozhengId=${activeks.value.userKaozhengId}&from=shouye`
		})
	}
	
	function handleContinue(data) {
		activeks.value = data;
		// 考试中 直接进入考试
		checkKaoshi(data)
	}
</script>

<style>
</style>