<template>
	<view>
		<view @click="goBack">{{gradeTerm.text}}</view>

		<view>缓存数据1:{{routeParams}}</view>
		<view>
			<view v-for="item in data.list" :key="item.index" @click="listClick"> {{item.index}} {{item.label}} </view>
		</view>
		<view>
			<uni-button @click="handleCheckCatalogue">go catalogue</uni-button>
			<uni-button @click="goKaoshi">goKaoshi</uni-button>
			<navigator :url="`/pages/study/catalogue?gradeId=1&termId=1&text=一年级上册`" hover-class="navigator-hover">
				<button type="default">学习计划</button>
			</navigator>
			<navigator url="/pages/unitTest/index" hover-class="navigator-hover">
				<button type="default">成长</button>
			</navigator>
			<navigator url="navigate/navigate?title=navigate" hover-class="navigator-hover">
				<button type="default">伙伴</button>
			</navigator>
			<navigator url="navigate/navigate?title=navigate" hover-class="navigator-hover">
				<button type="default">我的</button>
			</navigator>
		</view>

		<!-- 蛋 -->
		<view class="ezy-popup">蛋</view>


		<catalogue ref="catalogueRef" @change-zhang="handleChangeZhang"></catalogue>
	</view>
</template>

<script setup>
	import {
		reactive,
		ref,
		onMounted
	} from "vue";
	import {
		onLoad,
		onReady
	} from '@dcloudio/uni-app';
	import catalogue from "@/components/catalogue/catalogue.vue";
	import {
		useStudyRouteParams
	} from "@/utils/emitEvents.js"
	
	// 缓存操作
	const {getStudyStorage,removeStudyStorage} = useStudyRouteParams();
	const catalogueRef = ref(null);
	const gradeTerm = ref('');
	const selectZhang = ref(null);
	// 来自单元测试的路由参数缓存
	const routeParams = ref(null);

	onLoad((options) => {
		gradeTerm.value = options;
		// 获取路由参数
		routeParams.value = getStudyStorage();
		// 移除缓存
		removeStudyStorage();
	})

	const data = reactive({
		list: [{
				label: '长度中的隐含条件问题',
				id: 1,
			},
			{
				label: '解决重叠问题',
				id: 2,
			},
			{
				label: '列表法解决方案问题',
				id: 3,
			},
			{
				label: '真题测试',
				id: 4,
			},
		]
	})

	function handleChangeZhang(data) {
		console.log("章", data);
		selectZhang.value = data;
	}

	function goKaoshi() {
		uni.navigateTo({
			url: `/pages/unitTest/index?jieId=1&nextZhangId=${selectZhang.value.nextZhang.zhangId}&zhangId=${selectZhang.value.zhangId}`
		})
	}

	function listClick(data) {
		uni.navigateTo({
			url: '/pages/study/lookShipin'
		})
	}

	function handleCheckCatalogue() {
		catalogueRef.value.showPopup();
	}

	function goBack() {
		uni.navigateBack()
	}
</script>

<style>

</style>