<template>
    <view class="page-content pb-40">
        <mx-nav-bar :title="detail.name"/>
        <uv-cell-group title="1">
            <template #title>
                <view class="text-xs text-tips">
                    包含
                    <text class="text-error mx-5">{{ detail.childCount }}</text>
                    个专业
                </view>
            </template>
            <uv-cell v-for="item in detail.children" :key="item.code" :title="item.name" isLink border
                     class="f-333 bg-white" @click="goDetail(item)">
            </uv-cell>
        </uv-cell-group>
    </view>
</template>

<script setup>
import {ref, computed, onMounted} from 'vue'
import {useTransfer} from "@/hooks/useTransfer";
import {findTreeNode} from "@/utils/tree-helper";
import {useCacheStore} from "@/hooks/useCacheStore";
import {cacheActions} from "@/hooks/defineCacheActions";

const {prevData, transferTo} = useTransfer()
const {dispatchCache} = useCacheStore()
const majorTree = ref([])
const detail = computed(() => findTreeNode(majorTree.value, m => m.code == prevData.value.code) || {})

const goDetail = (item) => {
    transferTo('/pages/major-library/detail/detail', ['code'], item)
}

onMounted(async () => {
    majorTree.value = await dispatchCache(cacheActions.getMajorTree)
})
</script>

<style lang="scss">

</style>
