<template>
  <!-- 文化传承 - 非遗产品 -->
  <CommonListPage
    :title="'非遗产品(作品)'"
    :prevPage="{ title: '保护传承' }"
    :dropDownNames="dropdownNames"
    :pageSize="8"
    :load="loadData"
    :loadDetail="loadDetail"
    :tagsData="tagsData"
    :defaultSelectTag="tagsData[0].id"
    detailsPage="/inheritor/intangible-detail"
  />
</template>

<script setup lang="ts">
import CommonContent, { GetContentListParams } from '@/api/CommonContent';
import ProductsContent from '@/api/inheritor/ProductsContent';
import type { DropDownNames } from '@/components/content/CommonListPage.vue';
import { onMounted, ref } from 'vue';

async function loadDetail(id: number, item: any) {
  const res = await ProductsContent.getContentDetail(id);
  res.addItems = [
    { name: '产地', text: res.regionText, span: 12 },
    { name: '特点', text: res.keywords, span: 12 },
    { name: '艺术分类', text: res.ichTypeText, span: 12 },
  ];
  return res;
}
async function loadData(
  page: number, 
  pageSize: number,
  selectedTag: number,
  searchText: string,
  dropDownValues: number[]
) {

  const res = await ProductsContent.getContentList(new GetContentListParams().setSelfValues({
    ichType: selectedTag == 0 ? undefined: selectedTag,
    level: dropDownValues[0] == 0 ? undefined: dropDownValues[0],
    region: dropDownValues[1] == 0 ? undefined: dropDownValues[1],
    keywords: searchText,
  }), page, pageSize);

  return { 
    page: page,
    total: res.total,
    data: res.list.map((item, index) => {
      return {
        id: item.id,
        title: item.title ?? '!!title!!',
        desc: item.desc,
        image: item.image,
        addItems: [
          { name: '产地', text: item.regionText, span: 12 },
          { name: '特点', text: item.keywords?.join(' '), span: 12 },
          { name: '艺术分类', text: item.ichTypeText, span: 12 },
        ],
      };
    }),
  }
}

const dropdownNames = ref<DropDownNames[]>([]);
//子分类
const tagsData = ref([
  { id: 0, name: '全部' },
]);

onMounted(async () => {
  // tagsData.value = tagsData.value.concat((await CommonContent.getCategoryList(4)).map((item) => ({
  //   id: item.id,
  //   name: item.title,
  // })));
  dropdownNames.value.push({ 
    options: [{
      id: 0, 
      name: '全部'
    }].concat((await CommonContent.getCategoryList(2)).map((item) => ({
      id: item.id,
      name: item.title,
    }))),
    defaultSelectedValue: 0,
  });
  dropdownNames.value.push({ 
    options: [{
      id: 0, 
      name: '全部'
    }].concat((await CommonContent.getCategoryList(1)).map((item) => ({
      id: item.id,
      name: item.title,
    }))),
    defaultSelectedValue: 0,
  });
})
</script>

<style>
</style>

