<template>
  <CommonListPage 
    title="非遗传习所"
    itemType="article-character"
    detailsPage="/pages/inhert/seminar/details"
    showTotal
    :dropDownNames="dropdownNames"
    :load="loadData" 
  />
</template>

<script setup lang="ts">
import CommonContent, { GetContentListParams } from '@/api/CommonContent';
import SeminarContent from '@/api/inheritor/SeminarContent';
import CommonListPage, { type DropDownNames } from '@/pages/article/common/CommonListPage.vue';
import { onLoad } from '@dcloudio/uni-app';
import { onMounted, ref } from 'vue';

const dropdownNames = ref<DropDownNames[]>([]);

async function loadData(
  page: number, 
  pageSize: number,
  searchText: string,
  dropDownValues: number[]
) {
  const res = (await SeminarContent.getContentList(new GetContentListParams().setSelfValues({
    ichType: dropDownValues[0] == 0 ? undefined: dropDownValues[0],
    level: dropDownValues[1] == 0 ? undefined: dropDownValues[1],
    region: dropDownValues[2] == 0 ? undefined: dropDownValues[2],
    keywords: searchText,
  }), page, pageSize));
  res.list.forEach((p) => {
    p.titleBox = Boolean(p.deathBirth);
    p.desc = p.ichName as string;
    p.bottomTags = [
      p.levelText, 
      p.nation,
    ];
  })
  return res;
}

onLoad(async (querys) => {
  dropdownNames.value.push({ 
    options: [{
      id: 0, 
      name: '全部类别'
    }].concat((await CommonContent.getCategoryList(4)).map((item) => ({
      id: item.id,
      name: item.title,
    }))),
    defaultSelectedValue: 0,
  });
  const levels = await CommonContent.getCategoryList(2);
  dropdownNames.value.push({ 
    options: [{
      id: 0, 
      name: '全部级别'
    }].concat(levels.map((item) => ({
      id: item.id,
      name: item.title,
    }))),
    defaultSelectedValue: querys?.level ?? 0,
  });
  dropdownNames.value.push({  
    options: [{
      id: 0, 
      name: '全部区域'
    }].concat((await CommonContent.getCategoryList(1)).map((item) => ({
      id: item.id,
      name: item.title,
    }))),
    defaultSelectedValue: querys?.region ?? 0,
  });
})
</script>
