<template>
    <view class="h-full">
        <z-paging ref="paging" v-model="list" @query="handleQuery">
            <view class="p-20 flex flex-col gap-20">
                <college-item v-for="i in list" :key="i.code" :item="i" class="mx-card" @click="handleDetail(i)"/>
            </view>
        </z-paging>
    </view>
</template>

<script setup lang="ts">
import {useTransferPage} from "@/hooks/useTransferPage";
import {universityList} from "@/api/modules/university";
import {University} from "@/types/university";
import {useUserStore} from "@/store/userStore";
import CollegeItem from "@/pagesOther/pages/university/index/components/plus/college-item.vue";
import {routes} from "@/common/routes";

const {transferTo} = useTransferPage()
const paging = ref<ZPagingInstance>()
const list = ref<University[]>([])
const {getLocation} = useUserStore()

const rankTips = computed(() => `${getLocation || '湖南'}省招生院校竞争力排名`)

const handleQuery = (pageNum: number, pageSize: number) => {
    const payload = {pageNum, pageSize, filterRank: true}
    universityList(payload)
        .then(res => paging.value?.completeByTotal(res.rows, res.total))
        .catch(e => paging.value?.complete(false))
}

const handleDetail = (college: University) => {
    const {id, code, name} = college
    transferTo(routes.universityDetail, {data: {id, code, name}})
}

</script>

<style scoped>

</style>