<template>
  <div
    class="mt-10px shadow-default bg-white pl-35px pr-30px pr-35px h-60px rounded-10px relative flex items-center justify-between"
  >
    <h3 class="nav-title">家庭教育</h3>
    <div class="btnDiv">
      <el-button
        size="large"
        @click="linkTo('jsd_personal_wdkc')"
        class="w-100px"
        >返回
      </el-button>
    </div>
  </div>
  <div
    class="mt-10px shadow-default bg-white-grey pt-25px pl-35px pr-35px pb-35px rounded-10px"
  >
    <div class="flex">
      <el-select
        v-model="subject_id"
        class="shadow-default"
        placeholder="全部学科"
        size="large"
        @change="filterData"
         clearable
        filterable
      >
        <el-option value="">全部学科</el-option>
        <el-option
          v-for="item in subjectList"
          :key="item.tjzx_id"
          :label="item.tjzx_xkmc"
          :value="item.tjzx_id"
        />
      </el-select>
      <el-select
        v-model="grade_id"
        class="shadow-default ml-40px"
        placeholder="全部年级"
        size="large"
        @change="filterData"
         clearable
        filterable
      >
        <el-option value="">全部年级</el-option>
        <el-option
          v-for="item in gradeList"
          :key="item.tjzn_id"
          :label="item.tjzn_njmc"
          :value="item.tjzn_id"
        />
      </el-select>
      <div class="search-box ml-40px">
        <input type="text" placeholder="搜索关键字" v-model="keyword" />
        <button type="button" class="search-btn" @click="filterData"></button>
      </div>
    </div>
    <div v-if="listData.length > 0">
      <ul class="mt-25px course-list">
        <li v-for="item in listData" @click="toChapter(item)">
          <div class="course-img relative">
            <img :src="item.tjk_img" alt="" />
            <div class="info-bottom pl-7px items-center flex justify-between">
              <div>
                <span class="inline-block align-middle icon-view"></span>
                <span
                  class="inline-block align-middle ml-5px text-14px text-white"
                  >{{ item.tjk_lll }}</span
                >
              </div>
              <div class="mr-10px">
                <span class="inline-block align-middle icon-thumb"></span>
                <span
                  class="inline-block align-middle ml-5px text-14px text-white"
                  >{{ item.tjk_dzl }}</span
                >
              </div>
            </div>
          </div>
          <div class="flex-1 mini-w-0">
            <div class="p-10px border-bottom-1">
              <div
                class="text-16px text-dark-400 h-44px leading-22px overflow-hidden"
              >
                {{ item.tjk_mc }}
              </div>
              <div class="mt-10px flex justify-between">
                <h4 class="text-14px color-grey">
                  {{ item.ex.create_dateline }}
                </h4>
                <h4 class="text-12px color-grey">
                  {{ item.tjzn_name }}&nbsp;&nbsp;|&nbsp;&nbsp;{{
                    item.tjzx_name
                  }}
                </h4>
              </div>

              <h5 class="mt-15px text-14px color-blue">
                {{ item.tjk_bml }}人报名
              </h5>
            </div>
            <div
              class="mt-2px flex justify-between px-10px text-13px leading-30px"
            >
              <span class="text-dark-400">责任老师：{{ item.tjk_zrjsmc }}</span>
              <span
                class="ml-10px color-grey flex-1 text-right text-overflow"
                >{{ item.tjk_zrjgmc }}</span
              >
            </div>
          </div>
        </li>
      </ul>
      <div class="mt-20px flex justify-center p-page">
        <el-pagination
          v-model:current-page="cur_page"
          v-model:page-size="limit"
          layout="total, prev, pager, next"
          :total="total"
          :background="true"
          @current-change="handleSelectionChange"
        ></el-pagination>
      </div>
    </div>
    <div v-else class="py-80px text-center">
      <div>
        <img
          src="/images/icon-no-data.png"
          width="138"
          class="block m-0-auto"
          alt=""
        />
        <h3 class="text-18px color-050026 mt-20px">暂无数据，敬请期待！</h3>
      </div>
    </div>
  </div>
</template>

<script setup>
import { useRouter } from "vue-router";
import { jtjy_list, grade_list, subject_list } from "./api.js";
import { user } from '@/store/index'
const router = useRouter();
const linkTo = (name) => {
  router.push({ name });
};
let keyword = $ref("");
let subject_id = $ref("");
let grade_id = $ref("");
let subjectList = $ref([]);
let gradeList = $ref([]);
let limit = $ref(8);
let total = $ref(0);
let cur_page = $ref(1);
let listData = $ref([]);
function getGradeList() {
  let data = {
    page: "1",
    limit: "999",
  };
  grade_list(data).then((res) => {
    if (res.code === "1") {
      gradeList = res.data.page_data;
    }
  });
}
function getSubjectList() {
  let data = {
    page: "1",
    limit: "999",
  };
  subject_list(data).then((res) => {
    if (res.code === "1") {
      subjectList = res.data.page_data;
    }
  });
}
function getListData() {
  let data = {
    page: cur_page,
    limit: limit,
    keyword: keyword,
    tjzn_id: grade_id,
    tjzx_id: subject_id,
    tjk_zrjs_user_id: user.value.user_id,
    M5jxrcL: ''
  };
  jtjy_list(data).then((res) => {
    if (res.code === "1") {
      listData = res.data.page_data;
      total = Number(res.data.total_rows);
      cur_page = Number(res.data.page_now);
    }
  });
}
function toChapter(item) {
  router.push({
    name: "jsd_personal_wdkc_jtjy_chapter",
    params: { tjk_id: item.tjk_id },
  });
}
getGradeList();
getSubjectList();
getListData();
let handleSelectionChange = (val) => {
  cur_page = val;
  getListData();
};
function filterData() {
  cur_page = 1;
  getListData();
}
</script>
<style lang="scss" scoped>
$color: #1259a1;
.bg-white-grey {
  background: #fcfeff;
}
.shadow-default {
  box-shadow: 0 10px 24px rgba(161, 153, 168, 0.18);
}
.color-blue {
  color: $color;
}
.color-grey {
  color: #999;
}
.border-bottom-1 {
  border-bottom: 1px solid #eee;
}
.nav-title {
  font-size: 18px;
  color: #050026;
}
.btnDiv {
  .el-button {
    background: $color;
    border-color: $color;
    color: #fff;
  }
}
.search-box {
  width: 300px;
  height: 48px;
  background: #f6f8fa;
  border-radius: 8px;
  padding: 0 10px 0 14px;
  display: flex;
  align-items: center;
  input {
    flex: 1;
    height: 48px;
    border: 0;
    font-size: 16px;
    color: #333;
    outline: none;
    background: #f6f8fa;
  }
  .search-btn {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    background: $color url("/images/icon-search.png") center no-repeat;
    background-size: 13px 13px;
  }
}
.course-list {
  display: flex;
  flex-wrap: wrap;
  li {
    min-width: 0;
    width: 553px;
    height: 151px;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.11);
    margin-right: 19px;
    margin-bottom: 15px;
    cursor: pointer;
    display: flex;
    &:nth-child(even) {
      margin-right: 0;
    }
    .course-img {
      min-width: 0;
      width: 268px;
      height: 151px;
      border-radius: 10px 0 0 10px;
      overflow: hidden;
      img {
        width: 100%;
      }
      .info-bottom {
        position: absolute;
        left: 0;
        bottom: 0;
        z-index: 30;
        width: 152px;
        height: 27px;
        background: rgba(0, 0, 0, 0.5);
        border-radius: 0 10px 0 0;
        display: flex;
        .icon-view {
          width: 24px;
          height: 16px;
          background: url("/images/icon/view.png") center no-repeat;
          background-size: 24px 16px;
        }
        .icon-thumb {
          width: 17px;
          height: 16px;
          background: url("/images/icon/thumb.png") center no-repeat;
          background-size: 17px 16px;
        }
      }
    }
  }
}
::v-deep .el-pagination.is-background .el-pager li.is-active {
  background: $color;
}
::v-deep .el-pager li:hover {
  color: $color;
}
</style>