<template>
	<view>
		<view class="box-nav">
			<image style="width: 100%;"
				src="https://oss-bq.ahduima.com/%E5%B0%8F%E7%A8%8B%E5%BA%8F/%E5%9B%BE%E7%89%87/%E9%A6%96%E9%A1%B5_20230830213855.png">
			</image>
			<view class="center-box flex jc-sb ai-c">
				<view class="box-item flex ai-c jc-c">
					<view class="flex jc-c ai-c relative" style="width: 230rpx;height: 230rpx;" @tap="toAnswer('顺序答题',false)">
						<image style="width: 230rpx;height: 230rpx;position: absolute;left: 0;top: 0;"
							src="../../../static/image/index/green_bg.png"></image>
						<view class="btn-item flex ai-c jc-c">
							<view class="text-center cor-fff" style="line-height: 40rpx;">
								<view class="fs16">顺序练习</view>
								<text
									class="fs14">{{getDoNum}}/{{subject=='1'?orderQuestion_subject1.length:orderQuestion_subject4.length}}</text>
							</view>
						</view>
					</view>
				</view>
				<view class="box-item flex ai-c jc-c">
					<view class="flex jc-c ai-c relative" style="width: 230rpx;height: 230rpx;" @tap="toExams('模拟考试')">
						<image style="width: 230rpx;height: 230rpx;position: absolute;left: 0;top: 0;"
							src="../../../static/image/index/orange_bg.png"></image>
						<view class="btn2-item flex ai-c jc-c">
							<view class="text-center cor-fff" style="line-height: 40rpx;">
								<view class="fs16">模拟考试</view>
								<text class="fs14">去考试</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view style="padding: 0 28rpx;margin-top: calc(100% - 718rpx);">
			<view class="tabs-box">
				<view class="wp33 flex ai-c jc-c" @tap="toVip">
					<view class="text-center wp100">
						<image style="width: 72rpx;height: 72rpx;margin: 0 auto" src="../../static/image/index/vipicon.png">
						</image>
						<view class="mt5">VIP课程</view>
					</view>
				</view>
				<view class="wp33 flex ai-c jc-c" @tap="toAnswer(`精简${titleNum}题`,true)">
					<view class="text-center wp100">
						<image style="width: 72rpx;height: 72rpx;margin: 0 auto" src="../../static/image/index/500icon.png">
						</image>
						<view class="mt5">精简{{titleNum}}题</view>
					</view>
				</view>
				<view class="wp33 flex ai-c jc-c" @tap="toExclusive">
					<view class="text-center wp100">
						<image style="width: 72rpx;height: 72rpx;margin: 0 auto" src="../../static/image/index/zxicon.png">
						</image>
						<view class="mt5">专项练习</view>
					</view>
				</view>
				<view class="wp33 flex ai-c jc-c" @tap="toTestRoom">
					<view class="text-center wp100">
						<image style="width: 72rpx;height: 72rpx;margin: 0 auto;" src="../../static/image/index/realicon.png">
						</image>
						<view class="mt5">真实考场模拟</view>
					</view>
				</view>
				<view class="wp33 flex ai-c jc-c" @tap="toExams('考前秘卷')">
					<view class="text-center wp100">
						<image style="width: 72rpx;height: 72rpx;margin: 0 auto" src="../../static/image/index/testbeforeicon.png">
						</image>
						<view class="mt5">考前秘卷</view>
					</view>
				</view>
				<view class="wp33 flex ai-c jc-c" @tap="toWrongList">
					<view class="text-center wp100">
						<image style="width: 72rpx;height: 72rpx;margin: 0 auto" src="../../static/image/index/worryicon.png">
						</image>
						<view class="mt5">错题收藏</view>
					</view>
				</view>
			</view>
		</view>
		<!-- <view style="padding: 0 28rpx;margin-top: 30rpx;" @tap="toClass">
			<view class="video-box">
				<view class="flex jc-sb ai-c wp100">
					<text style="color: #05C341;font-size: 36rpx;">科{{subject==1?'一':'四'}}精品视频课</text>
				</view>
				<view class="flex ai-c mt20">
					<view class="contain-box relative">
						<image class="contain-box" src="../../../static/image/index/jpsp.png"></image>
						<image class="play_btn_2" src="../../static/image/index/play.png" />
					</view>
					<view class="ml15 text-center">
						<u-button :customStyle="{width:'200rpx',height:'66rpx',borderRadius: '33rpx'}" iconColor="#fff" text="去看视频"
							color="linear-gradient(90deg, #11DF20 0%, #00B74F 100%)" icon="play-circle">
						</u-button>
						<view class="cor-333 fs15 fw600 mt10">科{{subject==1?'一':'四'}}易错试题</view>
					</view>
				</view>
			</view>
		</view> -->
	</view>
</template>

<script>
	import {
		mapState,
		mapActions
	} from 'pinia' //引入映射函数
	import useUserStore from '@/jtools/store/user'
	import storage from '@/jtools/storage';
	import useQuestionStore from '@/jtools/store/question' //引入store
	import {
		querySysConfig,
		queryQuestionId,
		getTestQuestionId
	} from '@/jtools/api/question';
	export default {
		props: {
			subject: {
				type: [String, Number],
			},
			rightList: {
				type: Array
			},
			wrongList: {
				type: Array
			}
		},
		data() {
			return {
				titleNum:500,
				allQuestionNum: 0,
			}
		},
		mounted() {
			this.getTitle()
		},
		computed: {
			...mapState(useUserStore, ["vipOnList", "token"]),
			...mapState(useQuestionStore, ["orderQuestion_subject1", "orderQuestion_subject4", "version"]), //映射函数，取出tagslist
			getDoNum() {
				return this.rightList.length + this.wrongList.length
			}
		},
		methods: {
			...mapActions(useUserStore, ['searchUserVip']),
			...mapActions(useQuestionStore, ['getOrderQuestion_sub1', 'getOrderQuestion_sub4', 'getAllQuestion']),
			getTitle(){
				const carId=storage.get('carType') || '1001'
				querySysConfig(carId,'SimplifyQuestionNum').then(resp=>{
					if(resp.code==='0000'){
						const list = JSON.parse(resp.data.configJson)
						this.titleNum=list.find(item=>item.subject==this.subject).num
					}
				})
			},
			async toTestRoom() {
				// uni.navigateTo({
				// 	url:"/pages/index/trueTest"
				// })
				if (this.token) {
					await this.searchUserVip()
					const res = this.vipOnList.some(item => item.subjects.includes(this.subject))
					if (!res) {
						uni.navigateTo({
							url: "/pages/index/videoVip?subject=" + this.subject
						})
					} else {
						getTestQuestionId({
								versionId: this.version,
								carTypeId: storage.get('carType') || '1001',
								subject: this.subject,
							}).then(async (resp) => {
								if (resp.code === '0000') {
									if(resp.data&&resp.data.length){
										const arr = resp.data
										const listJson = JSON.stringify(arr)
										uni.navigateTo({
											url: "/pages/index/trueTest?subject="+ this.subject + "&questionIdList=" + listJson
										})
									}else{
										uni.showToast({
											title: '暂无题目',
											icon: 'none'
										})
									}
								} else if (resp.code === '4001') {
									uni.showToast({
										title: '当前题库非最新版，请更新~',
										icon: 'none'
									})
									this.getAllQuestion()
								}
							})
					}
				} else {
					uni.redirectTo({
						url: '/pages/login/login'
					});
				}
			},
			async toVip() {
				if (this.token) {
					await this.searchUserVip()
					const res = this.vipOnList.some(item => item.subjects.includes(this.subject))
					if (!res) {
						uni.navigateTo({
							url: "/pages/index/videoVip?subject=" + this.subject
						})
					} else {
						uni.navigateTo({
							url: "/pages/me/vip"
						})
					}
				} else {
					uni.redirectTo({
						url: '/pages/login/login'
					});
				}
			},
			toClass() {
				uni.showToast({
					title: '敬请期待',
					icon: 'none'
				})
			},
			toAnswer(title, val) {
				if (title == `精简${this.titleNum}题`) {
					queryQuestionId({
						versionId: this.version,
						carTypeId: storage.get('carType') || '1001',
						subject: this.subject,
						isVip: '1'
					}).then(async (resp) => {
						if (resp.code === '0000') {
							if (this.token) {
								await this.searchUserVip()
								const result = this.vipOnList.some(item => item.subjects.includes(this.subject))
								let arr = []
								if (result) {
									if(resp.data&&resp.data.length){
										const listJson = JSON.stringify(resp.data)
										uni.navigateTo({
											url: "/pages/questionBank/questionBank?navTitle=" + title + "&subject=" + this.subject +
												"&needVip=" + !result + "&questionIdList=" + listJson
										})
									}else{
										uni.showToast({
											title: '暂无题目',
											icon: 'none'
										})
									}
								} else {
									if (resp.data && resp.data.length > 3) {
										arr = resp.data.slice(0, 3)
									} else {
										arr = resp.data
									}
									if(arr&&arr.length){
										const listJson = JSON.stringify(arr)
										uni.navigateTo({
											url: "/pages/questionBank/questionBank?navTitle=" + title + "&subject=" + this.subject +
												"&needVip=" + !result + "&questionIdList=" + listJson
										})
									}else{
										uni.showToast({
											title: '暂无题目',
											icon: 'none'
										})
									}
								}
							} else {
								uni.redirectTo({
									url: '/pages/login/login'
								});
							}
						} else if (resp.code === '4001') {
							uni.showToast({
								title: '当前题库非最新版，请更新~',
								icon: 'none'
							})
							this.getAllQuestion()
						}
					})
				} else {
					uni.navigateTo({
						url: "/pages/questionBank/questionBank?navTitle=" + title + "&subject=" + this.subject + "&needVip=" +
							val
					})
				}
			},
			toExams(title) {
				if (storage.get('token')) {
					if(title=='模拟考试'){
						getTestQuestionId({
								versionId: this.version,
								carTypeId: storage.get('carType') || '1001',
								subject: this.subject,
							}).then(async (resp) => {
								if (resp.code === '0000') {
									const arr = resp.data
									const listJson = JSON.stringify(arr)
									uni.navigateTo({
										url: "/pages/index/testTip?subject=" + this.subject + "&questionIdList=" + listJson
									})
								} else if (resp.code === '4001') {
									uni.showToast({
										title: '当前题库非最新版，请更新~',
										icon: 'none'
									})
									this.getAllQuestion()
								}
							})
					}else if(title=='考前秘卷'){
						const param=this.subject=='1'?{isExam1: '1'}:{isExam2: '1'}
						queryQuestionId({
							versionId: this.version,
							carTypeId: storage.get('carType') || '1001',
							subject: this.subject,
							...param
						}).then(async (resp) => {
							if (resp.code === '0000') {
								let arr = []
								if (this.token) {
									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 {
										if (resp.data && resp.data.length > 3) {
										 arr = resp.data.slice(0, 3)
										} else {
										 arr = resp.data
										}
										const listJson = JSON.stringify(arr)
										uni.navigateTo({
											url: "/pages/index/videoVip?subject=" + this.subject
										})
									}
								} else {
									uni.redirectTo({
										url: '/pages/login/login'
									});
								}
							} else if (resp.code === '4001') {
								uni.showToast({
									title: '当前题库非最新版，请更新~',
									icon: 'none'
								})
								this.getAllQuestion()
							}
						})
					}
					} else {
				uni.navigateTo({
					url: '/pages/login/login'
				})
			}
		},
		toExclusive() {
			uni.navigateTo({
				url: "/pages/questionBank/exclusiveExercise?subject=" + this.subject
			})
		},
		toWrongList() {
			uni.navigateTo({
				url: "/pages/questionBank/wrongQuestion?subject=" + this.subject
			})
		}
	}
	}
</script>

<style scoped>
	.box-nav {
		width: 100%;
		position: relative;
		height: 500rpx;
	}

	.center-box {
		position: absolute;
		width: 100%;
		top: 170rpx;
		padding: 0 28rpx;
	}

	.box-item {
		width: 336rpx;
		height: 336rpx;
		background: #FFFFFF;
		border-radius: 16rpx;
		z-index: 999;
	}

	.btn-item {
		width: 193rpx;
		height: 193rpx;
		background: linear-gradient(0deg, #11DF20 0%, #00B74F 100%);
		border-radius: 50%;
	}

	.btn2-item {
		width: 193rpx;
		height: 193rpx;
		background: linear-gradient(0deg, #E95A0E 0%, #FF9600 100%);
		border-radius: 50%;
	}

	::v-deep .u-tabs__wrapper__nav__line {
		background: linear-gradient(90deg, #11DF20 0%, #00B74F 100%) !important;
		bottom: 14rpx !important;
	}

	.tabs-box {
		width: 694rpx;
		height: 366rpx;
		background: #FFFFFF;
		border-radius: 16rpx;
		display: flex;
		align-items: center;
		justify-content: flex-start;
		flex-wrap: wrap;
	}

	.video-box {
		padding: 20rpx;
		width: 694rpx;
		height: 369rpx;
		background: #DEEFE5;
		border: 2px solid #47DB87;
		border-radius: 16rpx;
	}

	.contain-box {
		width: 406rpx;
		height: 228rpx;
		background: #00B74F;
		border-radius: 16rpx;
	}

	.play_btn_2 {
		width: 65rpx;
		height: 65rpx;
		position: absolute;
		left: 165.5rpx;
		top: 78rpx
	}
</style>