<template>
  <z-paging ref="paging" v-model="list" @query="handleQuery">
    <view v-for="item in list" :key="item.id" class="mx-30 my-28">
      <ie-news-item :data="item" @click="handleClick(item)" />
    </view>
  </z-paging>
</template>
<script lang="ts" setup>
import { getNewsListNoToken } from '@/api/modules/news';
import { News } from '@/types';
import { useTransferPage } from '@/hooks/useTransferPage';
const { transferTo, routes } = useTransferPage();

const props = defineProps<{
  params: News.NewsQueryDTO;
}>();
const list = ref<News.NewsItem[]>([]);
const paging = ref<ZPagingInstance>();

const handleQuery = (page: number, size: number) => {
  getNewsListNoToken({ ...props.params, pageNum: page, pageSize: size }).then(res => {
    paging.value?.completeByTotal(res.rows, res.total)
      .catch(() => paging.value?.complete(false));
  });
}
const handleClick = (item: News.NewsItem) => {
  transferTo(routes.newsDetail, {
    data: {
      id: item.id,
    }
  });
}
</script>
<style lang="scss" scoped></style>