<template>
    <z-paging ref="paging" :fixed="false" v-model="list" @query="handleQuery">
        <question-preview-list :list="list" hidden-delete @change="handleChange"/>
    </z-paging>
</template>

<script setup>
import {ref} from 'vue'
import QuestionPreviewList from "@/pagesOther/pages/topic-center/topic-collection/components/question-preview-list.vue";
import {favQuestions} from "@/api/webApi/webQue";
import {createPropDefine} from "@/utils";
import {useQuestionTranslate} from "@/components/mx-question/useQuestionTranslate";

const props = defineProps({
    subjectId: createPropDefine(0, [Number, String])
})

const list = ref([])
const paging = ref(null)
const handleChange = (collect) => {
  paging.value.reload()
}
const handleQuery = function (pageNum, pageSize) {
    const params = {pageNum, pageSize, type: 'question', subjectId: props.subjectId}
    favQuestions(params)
        .then(res => {
            // 转成标准格式，以供mx-question-content/parse使用，以共享MathJax特性
            const rows = res.rows.map(useQuestionTranslate)
            paging.value.completeByTotal(rows, res.total)
        })
        .catch(e => paging.value.complete(false))
}
</script>

<style scoped>

</style>