<template>
    <college-list :extra-filter="extraFilter" custom-item-click @item-click="handleItemClick">
        <template #top>
            <mx-nav-bar title="选择院校" style="z-index: 20000"/>
        </template>
        <template v-if="categoryNode" #prefix>
            <view class="h-[44px] px-30 fx-row items-center bg-white">
                <uv-icon name="bell" color="warning" label-color="var(--warning-color)" label-size="14"
                         :label="`仅显示包含[${categoryNode.name}]专业的院校`"/>
            </view>
        </template>
    </college-list>
</template>

<script setup>
import {ref, computed, onMounted} from 'vue';
import CollegeList from "@/pagesOther/pages/college-library/components/college-list.vue";
import {useCacheStore} from "@/hooks/useCacheStore";
import {useTransfer} from "@/hooks/useTransfer";
import {useTransferPage} from '@/hooks/useTransferPage';
import {cacheActions} from "@/hooks/defineCacheActions";
import {findTreeNode} from "@/utils/tree-helper";
import {toast} from "@/uni_modules/uv-ui-tools/libs/function";
import {array} from "@/uni_modules/uv-ui-tools/libs/function/test";

const {dispatchCache} = useCacheStore()
const {prevData, callbackEventData, transferBack} = useTransfer()
const { transferBack: transferBackPage } = useTransferPage();
const majorTree = ref([])
const categoryNode = computed(() => findTreeNode(majorTree.value, m => m.code == prevData.value.majorCategory))
const extraFilter = computed(() => {
    const {majorCategory} = prevData.value
    return {majorCategory}
})


const handleItemClick = (college) => {
    if (array(prevData.value.excepts)) {
        if (prevData.value.excepts.includes(college.code))
            return toast('您已经选择过该院校了')
    }
    callbackEventData.value = college
    if (prevData.value.transferType === 'v2') {
        transferBackPage(college)
    } else {
        transferBack()
    }
}

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

<style lang="scss">

</style>
