<template>
   <CommonListPage
    :title="'非遗活动'"
    :dropDownNames="[]"
    :showSearch="true"
    :pageSize="8"
    :load="loadData"
    :loadDetail="loadDetail"
    :tagsData="tagsData"
    :defaultSelectTag="tagsData[0].id"
  />
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { GetContentListParams } from '@/api/CommonContent';
import CustomContent from '@/api/introduction/CustomContent';

let _selectedTag = 0;

async function loadDetail(id: number, item: any) {
  return await CustomContent.getContentDetail(
    id,
    tagsData.value.find((item) => item.id == _selectedTag)?.modelId || 0
  );
}
async function loadData(
  page: number, 
  pageSize: number,
  selectedTag: number,
  searchText: string,
  dropDownValues: number[],
) {
  _selectedTag = selectedTag;
  const res = await CustomContent.getContentList(new GetContentListParams()
    .setModelId(tagsData.value.find((item) => item.id == selectedTag)?.modelId || 0)
    .setMainBodyColumnId(selectedTag > 0 ? selectedTag : 0)
    .setKeywords(searchText)
  , page, pageSize);

  return { 
    page: page,
    total: res.total,
    data: res.list.map((item, index) => {
      return {
        id: item.id,
        title: item.title,
        desc: item.desc,
        image: item.thumbnail || item.image,
        addItems: [],
      };
    }),
  }
}

//子分类
const tagsData = ref([
  { modelId: 18, id: 290, name: '全部' },
  { modelId: 16, id: 187, name: '讲古' },
  { modelId: 5, id: -1, name: '方言' },
  { modelId: 4, id: -2, name: '民俗习俗' },
]);
</script>

<style>
</style>

