<template>
  <CommonListPage
    :title="'可移动文物'"
    :dropDownNames="dropdownNames"
    :pageSize="8"
    :load="loadData"
    :loadDetail="loadDetail"
    :tagsData="tagsData"
    :defaultSelectTag="tagsData[0].id"
    detailsPage="/details/artifact"
  />
</template>

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

async function loadDetail(id: number, item: any) {
  const res = await MoveableContent.getContentDetail(id);
  res.addItems = [
    { name: '保护级别', text: item.crTypeText || '未定级', span: 12 },
  ];
  return res;
}
async function loadData(
  page: number, 
  pageSize: number,
  selectedTag: number,
  searchText: string,
  dropDownValues: number[]
) {

  const res = await MoveableContent.getContentList(new GetContentListParams().setSelfValues({
    crType: 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 {
        ...item,
        addItems: [
          { name: '保护级别', text: item.crTypeText || '未定级', span: 12 },
        ],
      };
    }),
  }
}

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


onMounted(async () => {
  tagsData.value = tagsData.value.concat((await MoveableContent.getCategoryList(310)).map((item) => ({
    id: item.id,
    name: item.title,
  })));
  dropdownNames.value.push({ 
    options: [{
      id: 0, 
      name: '全部'
    }].concat((await MoveableContent.getCategoryList(2)).map((item) => ({
      id: item.id,
      name: item.title,
    }))),
    label: '文物级别',
    defaultSelectedValue: 0,
  });
  dropdownNames.value.push({ 
    options: [{
      id: 0, 
      name: '全部'
    }].concat((await MoveableContent.getCategoryList(1)).map((item) => ({
      id: item.id,
      name: item.title,
    }))),
    label: '区域',
    defaultSelectedValue: 0,
  });
})
</script>

<style>
</style>


