<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">
      <span>直播课程</span>
      -
      <span>{{ course_title }}</span>
    </h3>
    <div class="btnDiv">
      <el-button
        size="large"
        @click="linkTo('jsd_personal_wdkc_zbkc')"
        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"
  >
    <h3 class="nav-title"><span>课程章节</span></h3>
    <div class="mt-25px search-box">
      <input type="text" placeholder="搜索关键字" v-model="keyword" />
      <button type="button" class="search-btn" @click="filterData"></button>
    </div>
    <div v-if="listData.length > 0">
      <ul class="mt-25px course-list">
        <li v-for="item in listData" @click="toDetail(item)">
          <div class="course-img relative">
            <img :src="item.tzk_img" alt="" />
            <div class="course-fire-tag" v-if="item.hot == '1'"></div>
            <h3 class="live-state not-start" v-if="item.status == 1">
              {{ item.status_msg }}
            </h3>
            <h3 class="live-state on" v-if="item.status == 2">
              {{ item.status_msg }}
            </h3>
            <h3 class="live-state playback" v-if="item.status == 3">
              {{ item.status_msg }}
            </h3>
            <div class="info-bottom pl-7px items-center flex justify-between">
              <div>
                <span class="icon-view inline-block align-middle"></span>
                <span
                  class="ml-5px text-14px inline-block text-white align-middle"
                  >{{ item.tzk_lll }}</span
                >
              </div>
              <div class="mr-10px">
                <span
                  class="ml-15px icon-thumb inline-block align-middle"
                ></span>
                <span
                  class="ml-5px text-14px text-white inline-block align-middle"
                  >{{ item.tzk_dzl }}</span
                >
              </div>
            </div>
          </div>
          <div class="pt-10px pb-15px px-15px border-bottom-1">
            <div
              class="text-16px text-dark-400 h-40px leading-20px overflow-hidden"
            >
              {{ item.tzk_ksmc }}
            </div>
            <h4 class="mt-10px text-14px color-grey">
              开启时间：{{ item.tzk_zbkqsj }}
            </h4>
          </div>
          <div class="flex justify-between p-15px text-13px">
            <span class="text-dark-400">责任老师：{{ item.tzk_xm }}</span>
            <span class="ml-10px flex-1 color-grey text-right text-overflow">{{
              item.tzk_ssdw
            }}</span>
          </div>
        </li>
      </ul>
      <div class="mt-20px flex justify-center">
        <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 { ElMessage } from "element-plus";
import { useRoute, useRouter } from "vue-router";
import { chapter_list } from "@/pages/jsd/wdkc/zbkc/api.js";
import { user } from '@/store/index'
const router = useRouter();
const route = useRoute();
let course_title = $ref("");
let keyword = $ref("");
let limit = $ref(8);
let total = $ref(0);
let cur_page = $ref(1);
let listData = $ref([]);
let tz_id = $ref("");
const linkTo = (name) => {
  router.push({ name });
};

function filterData() {
  cur_page = 1;
  getListData();
}

function getListData() {
  let data = {
    tz_id: tz_id,
    page: cur_page,
    limit: limit,
    keyword: keyword,
    tzk_zjr_user_id: user.value.user_id,
    M5jxrcL: ''
  };
  chapter_list(data).then((res) => {
    if (res.code === "1") {
      listData = res.data.page_data;
      course_title = res.data.kc_name;
      total = Number(res.data.total_rows);
      cur_page = Number(res.data.page_now);
    }
  });
}

if (route.params.tz_id) {
  tz_id = route.params.tz_id;
  getListData();
}

let handleSelectionChange = (val) => {
  cur_page = val;
  getListData();
};

function toDetail(item) {
  switch (item.status) {
    case 1:
      ElMessage.error("直播还未开始，请耐心等待！");
      break;
    case 2:
      router.push({name: 'jsd_personal_wdkc_zbkc_live', params: {tz_id: tz_id, tzk_id: item.tzk_id}});
      break;
    case 3:
      router.push({name: 'jsd_personal_wdkc_zbkc_detail', params: {tz_id: tz_id, tzk_id: item.tzk_id}});
      break;
  }
}
</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: 16px;
  color: #949494;

  span {
    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: 268px;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.11);
    margin-right: 19px;
    margin-bottom: 15px;
    cursor: pointer;

    &:nth-child(4n) {
      margin-right: 0;
    }

    .course-img {
      width: 100%;
      height: 151px;
      border-radius: 10px 10px 0 0;
      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;
        }
      }
    }
  }
}

.no-data {
  width: 100%;
}
.live-state {
  position: absolute;
  right: 0;
  top: 0;
  width: 80px;
  height: 27px;
  border-radius: 0 10px 0 10px;
  font-size: 14px;
  color: #fff;
  text-align: center;
  line-height: 27px;
  &.not-start {
    background: rgba(200, 200, 200, 0.7);
  }
  &.on {
    background: rgba(243, 8, 8, 0.7);
  }
  &.playback {
    background: rgba(0, 0, 0, 0.7);
  }
}
::v-deep .el-pagination.is-background .el-pager li.is-active {
  background: $color;
}
::v-deep .el-pager li:hover {
  color: $color;
}
</style>