<template>
	<view class="kecheng-mulu">
		<myCollapseCardVue v-for="zhang in chapterArr" :title="zhang.name" @click.stop="handleZhangClick(zhang)"
			:open="zhang.open">
			<myCollapseCardVue v-for="jie in zhang.jieList" :title="jie.name" @click.stop="handleJieClick(jie, zhang)"
				:open="jie.open">
				<view class="kejian-item" v-for="item in jie.kejianList" @click.stop="handleKejianClick(item)">
					<text>{{item.name}}</text>
					<text v-if="isHasProgress">进度{{item.curProcess}}</text>
				</view>
			</myCollapseCardVue>
		</myCollapseCardVue>
	</view>
</template>

<script setup>
	import myCollapseCardVue from '../myCollapseCard/myCollapseCard.vue';
	import {
		ref
	} from 'vue';
	const props = defineProps({
		chapterArr: {
			type: Array
		},
		isHasProgress: {
			type: Boolean
		}
	})

	const emits = defineEmits(['play'])

	function handleZhangClick(item) {

		if (item.open) {
			// 展开 -》 关闭
			props.chapterArr.forEach(zhang => {
				zhang.open = false;
				zhang.jieList.forEach(jie => {
					jie.open = false;
				})
			})
		} else {
			// 关闭 -》 展开
			props.chapterArr.forEach(zhang => {
				zhang.open = false;
				zhang.jieList.forEach(jie => {
					jie.open = false;
				})
			})
			item.open = true;
		}
	}

	function handleJieClick(item, zhang) {
		if (item.open) {
			// 展开 -》 关闭
			zhang.jieList.forEach(jie => {
				jie.open = false;
			})
		} else {
			// 关闭 -》 展开
			zhang.jieList.forEach(jie => {
				jie.open = false;
			})
			item.open = true;
		}
	}

	function handleKejianClick(item) {
		emits('play', item)
	}
</script>




<style>
	.kejian-item {
		line-height: 50px;
	}
</style>