<template>
  <div class="container">
    <div class="bread-container">
      <el-breadcrumb separator=">">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>专题资源</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <el-card style="margin-top: 20px;">
      <div class="title">
        专题资源
      </div>
      <div class="more">
        {{ total }}个专题
      </div>

      <div class="subject-content">
        <div class="subject-card" v-for="item in resourceList" @click="goTo(item)">
          <el-card>
            <img :src="item.coverUrl" />
            <p class="subject-title">{{ item.catalogName }}</p>
          </el-card>
          <div class="subject-top">{{ item.resourceNum }}个资源</div>
        </div>
      </div>
      <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize" @pagination="getResourceListData" />
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { getResourceCatalogList } from '@/apis/catalogResource'
import pagination from '@/components/Pagination/index.vue';

const router = useRouter()

const queryParams = ref({
  pageNum: 1,
  pageSize: 12
})
const resourceList = ref([])
const total = ref(0)
const getResourceListData = async () => {
  const res = await getResourceCatalogList(queryParams.value)
  resourceList.value = res.rows
  total.value = res.total
}

const goTo = (item) => {
  router.push({ path: `subSubject`, query: { catalogId: item.catalogId, catalogName: item.catalogName, createTime: item.createTime, resourceNum: item.resourceNum } })
}

onMounted(() => {
  getResourceListData()
})
</script>

<style lang="scss" scoped>
.container {
  .title {
    font-size: 20px;
    font-weight: bold;
  }

  .more {
    margin-top: 10px;
    margin-bottom: 20px;
    font-size: 15px;
    color: #8A8178;
  }

  .bread-container {
    padding: 25px 0;

    :deep(.el-breadcrumb__inner) {
      color: #fff;
      font-size: 16px;
    }

    :deep(.el-breadcrumb__separator) {
      color: #fff;
    }
  }

  .subject-banner {
    margin-top: 20px;
    width: 1240px;
    height: 500px;

    img {
      width: 100%;
      height: 500px;
      border-radius: 5px;
    }
  }

  .subject-content {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 10px;

    .subject-card {
      position: relative;

      img {
        border-radius: 10px;
        width: 100%;
        height: 240px;
      }

      .subject-title {
        text-align: center;
        margin-top: 5px;
        font-size: 16px;
      }

      .subject-top {
        position: absolute;
        top: 0;
        left: 0;
        background-color: #FCB124;
        font-size: 14px;
        font-weight: bold;
        color: #fff;
        line-height: 28px;
        width: 100px;
        text-align: center;
      }
    }
  }

  .book-page {
    margin-top: 20px;
    display: flex;
    justify-content: end
  }
}
</style>