<template>
	<view>
		<!-- <u-navbar title="模拟考试" @rightClick="rightClick" :autoBack="true">
		</u-navbar> -->
		<j-navbar :isDefineBack="true" @toBack="toBack">{{title}}</j-navbar>
		<Question ref="question" :tabsList="tabsList" v-model:isSubmit="isSubmit" :type="type" :isShowAll="isShowAll" @changeTab="changeTab" />
	</view>
</template>

<script>
	import {
		mapState,
		mapActions
	} from 'pinia' //引入映射函数
	import useQuestionStore from '@/jtools/store/question' //引入store
	import useUserStore from '@/jtools/store/user'
	import {
		getTestQuestion,
		queryQuestionId
	} from '@/jtools/api/question';
	import storage from '@/jtools/storage';
	import Question from './components/Question.vue';
	export default {
		components: {
			Question
		},
		data() {
			return {
				type: '',
				collectList: storage.get(`collectList_subject${this.subject}`) || [],
				questionArr: [],
				isShowAll: true,
				title: "模拟考试",
				subject: 1,
				isSubmit: false,
				tabsList: [{
					label: "模拟考试",
					value: 0
				}, {
					label: "考前秘卷",
					value: 1
				}]
			}
		},
		onLoad(op) {
			if (op.title) {
				this.title = op.title
			}
			if (op.subject) {
				this.subject = op.subject
				const param = {}
				if (op.isExam1) {
					param.isExam1 = op.isExam1
				}
				if (op.needVip) {
					this.isShowAll = op.needVip
				}
				let arr = []
				arr = [...this[`orderQuestion_subject${this.subject}`]]
				let questionObj = {}
				arr.forEach(item => {
					item.isChoose = false
					questionObj[item.questionId] = item
				})
				if (op.questionIdList) {
					const idList = JSON.parse(op.questionIdList)
					if (idList && idList.length > 0) {
						idList.forEach(item => {
							this.questionArr.push(questionObj[item])
						})
					}
				}
				this.type = 'exam'
				this.$refs.question.getQuestionList(JSON.stringify(this.questionArr), this.title,this.subject)
			}
		},
		computed: {
			...mapState(useUserStore, ["vipOnList", "token"]),
			...mapState(useQuestionStore, ["orderQuestion_subject1", "orderQuestion_subject4", "version"]), //映射函数，取出tagslist
		},
		methods: {
			...mapActions(useUserStore, ['searchUserVip']),
			toBack() {
				this.$refs.question.submitPaper()
			},
			async changeTab(val) {
				if (val == 1) {
					await this.searchUserVip()
					const result = this.vipOnList.some(item => item.subjects.includes(this.subject))
					if (result) {
						uni.navigateTo({
							url: "/pages/index/secretPapers?subject=" + this.subject
						})
					} else {
						uni.navigateTo({
							url: "/pages/index/videoVip?subject=" + this.subject
						})
					}
				}
			}
		}
	}
</script>

<style scoped>
	::v-deep .u-count-down {
		font-size: 28rpx;
		color: #fff !important;
		display: inline-block !important;
	}

	::v-deep .u-count-down__text {
		font-size: 28rpx;
		color: #fff !important;
	}

	::v-deep .balckColor .u-count-down__text {
		font-size: 28rpx;
		color: #333 !important;
	}
</style>