<template>
  <CommonListPage 
    :title="querys.title || undefined"
    :load="loadData"
    :itemType="querys.itemType as any || undefined"
    :detailsPage="querys.detailsPage || undefined"
    :detailsParams="{
      mainBodyColumnId: querys.mainBodyColumnId || undefined,
      modelId: querys.modelId || undefined,
    }"
    :intitalSearch="querys.search"
  />
</template>

<script setup lang="ts">
import { useLoadQuerys, stringDotNumbersToNumbers } from '@/common/composeabe/LoadQuerys';
import CommonListPage from './CommonListPage.vue';
import CommonContent, { GetContentListParams } from '@/api/CommonContent';

const { querys } = useLoadQuerys({
  mainBodyColumnId: '',
  modelId: 0,
  itemType: '',
  detailsPage: '',
  title: '',
  region: '',
  search: '',
});

async function loadData(
  page: number, 
  pageSize: number,
  searchText: string,
  dropDownValues: number[]
) {
  const mainBodyColumnId = stringDotNumbersToNumbers(querys.value.mainBodyColumnId);

  const res = await CommonContent.getContentList(new GetContentListParams().setSelfValues({
    mainBodyColumnId: mainBodyColumnId || undefined,
    modelId: querys.value.modelId || undefined,
    keywords: searchText,
    region: querys.value.region || undefined,
  }), page, pageSize);

  for (const element of res.list || []) {
    if (!element.desc && element.from)
      element.desc = `来源：${element.from}`;
  }

  return res;
}
</script>