<template>
  <CommonListPage
    :title="querys.title || undefined"
    :load="loadData"
    itemType="article-common"
    detailsPage="custom"
    @goCustomDetails="goCustomDetails"
  />
</template>

<script setup lang="ts">
import CommonListPage from '../../article/common/CommonListPage.vue';
import VillageInfoApi from '@/api/inhert/VillageInfoApi';
import { useLoadQuerys } from '@/common/composeabe/LoadQuerys';
import { navTo } from '@/components/utils/PageAction';

const { querys } = useLoadQuerys({
  keywords: '',
  title: '',
}, (querys) => {
  uni.setNavigationBarTitle({
    title: querys.title || '发现',
  });
});

function goCustomDetails(item: any) {
  navTo('details', {
    id: item.id,
    keywords: querys.value.keywords,
  });
}

async function loadData(
  page: number, 
  pageSize: number,
  searchText: string,
  dropDownValues: number[]
) {
  if (page > 1)
    return { list: [], total: 0 };
  const res = (await VillageInfoApi.getListForDiscover(
    page, pageSize, 
    ((querys.value.keywords || '') + ' ' + (searchText || '')).trim(), 
  ));
   return { 
    list: res.list.map((item) => ({
      ...item,
      badge: item.villageName || '',
    })), 
    total: res.total 
  };
}
</script>
