<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 ? 
      tagsData.value.find((item) => item.id == selectedTag)?.mainBodyColumnId || 0
      : selectedTag)
    .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: 16, id: 291, name: '闽南时尚' },
  { modelId: 16, id: 191, name: '闽南语经典歌曲' },
  { modelId: 16, id: 190, name: '南音' },
  { modelId: 16, id: 189, name: '闽南童谣' },
  { modelId: 5, mainBodyColumnId: [ 257,235,237,210 ], id: -100, name: '常用闽南语' },
  { modelId: 5, mainBodyColumnId: 313, id: -101, name: '闽南语原声' },
]);
</script>

<style>
</style>

