<template>
    <z-paging ref="paging" v-model="list" @query="handleQuery">
        <view class="fx-col p-30 gap-30">
            <college-item v-for="i in list" :item="i" class="mx-card" @click="goCollege(i)"/>
        </view>
    </z-paging>
</template>

<script setup>
import {ref} from 'vue';
import {createPropDefine} from "@/utils";
import {useTransfer} from "@/hooks/useTransfer";
import CollegeItem from "@/pagesOther/pages/college-library/components/college-item.vue";
import {useCacheStore} from "@/hooks/useCacheStore";
import {getUniversityByCode} from "@/api/webApi/collegemajor";

const props = defineProps({
    major: createPropDefine({}, Object)
})

const {transferTo} = useTransfer()
const {dispatchCache} = useCacheStore()
const list = ref([])
const paging = ref(null)

const goCollege = (item) => {
    transferTo('/pagesOther/pages/college-library/detail/detail', ['code'], item)
}

const handleQuery = (pageNum, pageSize) => {
    const payload = {code: props.major.code, pageNum, pageSize}
    dispatchCache(getUniversityByCode, payload)
        .then(res => paging.value.completeByTotal(res.rows, res.total))
        .catch(e => paging.value.complete(false))
}
</script>

<style scoped>

</style>