<template>
  <common-header />
  <div class="content">
    <div class="title">
      在线学习 <span>智慧教研-</span><span>在线学习</span>
    </div>
    <div class="jy-header">
      <p>在线学习</p>
      <div class="search">
        <input v-model="keyword" type="text" placeholder="搜索关键字" />
        <span class="inp-sear" @click="getData"></span>
      </div>
    </div>

    <div class="nav">
      <div class="search-list">
        <div class="label">年级</div>
        <div class="valueDiv">
          <div class="item pointer" :class="activeGrade==item.grade_id?'active':''" @click="initGrade(item)" v-for="item in gradeData" :key="item.grade_id">{{item.grade_name}}</div>
        </div>
      </div>

      <div class="search-list">
        <div class="label">科目</div>
        <div class="valueDiv">
          <div class="item pointer" :class="activeSubject==item.subject_id?'active':''" @click="initSubject(item)" v-for="item in subjectData" :key="item.subject_id">{{item.subject_name}}</div>
        </div>
      </div>

      <div class="search-list">
        <div class="label">分类</div>
        <div class="valueDiv">
          <div class="item pointer" :class="activeType==item.v?'active':''" @click="initType(item)" v-for="item in typeData" :key="item.v">{{item.n}}</div>
        </div>
      </div>
    </div>

    <div class="ysgc-kind">
      <ul class="specail">
        <li class="kc" v-for="(item, index) in listData" :key="index">
          <div>
            <video v-if="item.zz_video" class="mask" @click="zxxxspDetail(item.zz_id)" style="width: 100%"></video>
          </div>

          <img @click="zxxxxqDetail(item.zz_id)" class="kc-back" :src="https + item.zz_img" alt="" />
          <div class="kc-des">
            <p class="kc-name">{{ item.zz_name }}</p>
            <div class="rate">
              <!-- <el-rate v-model="item.zz_star_num"></el-rate> -->
              <img v-for="star in Number(item.zz_star_num)" :key="star" src="@/assets/img/zhjyzxxx/star.png" alt="" />
            </div>
          </div>

          <div class="dataShow">

            <div class="baseInfoPart">
              <img src="/kczy/fingerIcon.png" alt="">
              <span>{{item.zz_like_num}}</span>
            </div>
            <div class="baseInfoPart">
              <img src="/kczy/cellectIcon.png" alt="">
              <span>{{item.zz_fav_num}}</span>
            </div>
          </div>
        </li>
      </ul>
    </div>

    <div class="footer">
      <div style="width: 1400px; height: 50px; position: relative; margin: 0 auto">
        <el-pagination background layout="total,prev, pager, next" :total="total" style="position: absolute; top: 0; right: 0" @current-change="handleCurrentChange" :page-size="limit">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { zxxx_list, grade_list, subject_list } from "./api";
import CommonHeader from "@/components/CommonHeader/index.vue";
export default {
  name: "index",
  components: {
    CommonHeader,
  },
  data() {
    return {
      listData: [],
      keyword: "",
      limit: 10,
      total: 0,
      cur_page: 1,
      https: window.GLOBAL_CONFIG.api,
      gradeList: [],
      subjectList: [],
      grade_id: "",
      subject_id: "",
      firstForm: {
        grade: "",
        subject: "",
      },
      gradeData: [],
      activeGrade: "",
      subjectData: [],
      activeSubject: "",
      typeData: [],
      activeType: "",

    };
  },
  methods: {
    //跳转
    zxxxxqDetail(id) {
      this.$router.push({ name: "zhjy_zhjyzxxx_zxxxxq", params: { id: id } });
    },
    zxxxspDetail(id) {
      this.$router.push({ name: "zhjy_zhjyzxxx_zxxxsp", params: { id: id } });
    },
    //数据获取
    getData() {
      let data = {
        page: this.cur_page,
        limit: this.limit,
        keyword: this.keyword,
        grade_id: this.activeGrade,
        subject_id: this.activeSubject,
        zz_type: this.activeType,
      };

      zxxx_list(data).then((res) => {
        this.listData = res.data.page_data;
        console.log(this.listData);
        this.cur_page = Number(res.data.page_now);
        this.total = Number(res.data.total_rows);
      });
    },
    handleCurrentChange(val) {
      this.cur_page = val;
      this.listData();
    },

    //年级
    initGradeData() {
      this.gradeData = [
        {
          grade_id: "",
          grade_name: "全部",
        }
      ];
      grade_list().then((res) => {
        if (res.code == 1) {
          this.gradeData = this.gradeData.concat(res.data.page_data);
        }
      });
    },
    initGrade(value) {
      this.activeGrade = value.grade_id;
      this.getData();
    },
    //科目
    initSubjectData() {
      this.subjectData = [
        {
          subject_id: "",
          subject_name: "全部",
        }
      ];
      subject_list().then((res) => {
        if (res.code == 1) {
          this.subjectData = this.subjectData.concat(res.data.page_data);
        }
      });
    },
    initSubject(value) {
      console.log(value, 123);
      this.activeSubject = value.subject_id;
      this.getData();
    },
    // 分类
    initTypeData() {
      this.typeData = [
        {
          v: "",
          n: "全部"
        }
      ];
      zxxx_list().then((res) => {
        if (res.code == 1) {
          this.typeData = this.typeData.concat(res.data.table_structure.field.zz_type.option);
        }
      });
    },
    initType(value) {
      this.activeType = value.v;

      this.getData();
    },
  },

  mounted() {
    this.getData();
    this.initGradeData();
    this.initSubjectData();
    this.initTypeData();
  },
};
</script>

<style lang="scss" scoped>
.dataShow {
  position: absolute;
  right: 0;
  top: 0;
  z-index: 13;
  width: 160px;
  height: 32px;
  line-height: 32px;
  background: rgba(0, 0, 0, 0.5);
  border-bottom-left-radius: 12px;
  border-top-right-radius: 12px;
  display: flex;
  padding-left: 5px;
  .baseInfoPart {
    width: 50%;
    box-sizing: border-box;
    padding-left: 4px;
    img {
      display: inline-block;
      vertical-align: middle;
    }
    span {
      font-size: 14px;
      font-weight: 400;
      text-align: left;
      color: #ffffff;
      margin-left: 5px;
    }
  }
}
.search-list {
  display: flex;
  align-items: baseline;
  font-size: 14px;
  margin: 20px 0;
  .label {
    color: #000;
    margin-right: 25px;
  }
  .valueDiv {
    flex: 1;
    display: flex;
    color: #949494;
    border-bottom: 1px dashed #e4e6e8;
    padding-bottom: 15px;
    font-weight: 400;
    cursor: pointer;
    .item + .item {
      margin-left: 20px;
    }
    .item {
      padding: 3px 5px;
      &.active {
        color: #00a3ff;
        border-radius: 6px;
        background: rgba($color: #00a3ff, $alpha: 0.1);
      }
    }
  }
}
.content {
  width: 100%;
  min-width: 1400px;
  margin: 0 auto;
}
.title {
  width: 1400px;

  height: 55px;
  line-height: 55px;
  font-size: 18px;
  font-family: PingFangSC, PingFangSC-Regular;
  font-weight: 400;
  color: #050026;
  margin: 0 auto;
  span:first-of-type {
    width: 56px;
    height: 20px;
    font-size: 14px;
    font-family: PingFangSC, PingFangSC-Regular;
    font-weight: 400;
    text-align: left;
    color: #949494;
    line-height: 20px;
    margin-left: 30px;
  }
  span:last-of-type {
    width: 56px;
    height: 20px;
    font-size: 14px;
    font-family: PingFangSC, PingFangSC-Regular;
    font-weight: 400;
    text-align: left;
    color: #000000;
    line-height: 20px;
  }
}
.jy-header {
  width: 100%;
  height: 200px;
  background: url("@/assets/img/zhjyzxxx/zxxx_bg.png");
  background-size: 100% 200px;
  background-repeat: no-repeat;
  padding-top: 40px;
  p {
    width: 192px;
    height: 67px;
    font-size: 48px;
    font-family: PingFangSC, PingFangSC-Semibold;
    font-weight: 600;
    text-align: left;
    color: #ffffff;
    line-height: 67px;
    margin: 0 auto;
    margin-bottom: 15px;
  }
  .search {
    position: relative;
    height: 50px;
    width: 497px;
    margin: 0 auto;
    input {
      background: #ffffff;
      border-radius: 8px;
      border: 1px solid #00a3ff;
      height: 50px;
      padding: 20px;
      width: 100%;
      outline: none;
    }
    .inp-sear {
      display: block;
      width: 26px;
      height: 26px;
      background-color: #00a3ff;
      border-radius: 6px;
      position: absolute;
      top: 11px;
      right: 10px;
      background-image: url("@/assets/img/zhjyzxxx/search.png");
      background-size: 60%;
      background-position: center;
      background-repeat: no-repeat;
    }
  }
}
.nav {
  width: 1400px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  margin-bottom: 20px;
  div {
    display: flex;

    span {
      padding-top: 10px;
      display: inline-block;
      width: 50px;
      height: 50px;
      font-size: 16px;
      font-family: PingFangSC, PingFangSC-Semibold;
      font-weight: 600;
      text-align: center;
      color: #000000;
      line-height: 21px;
    }
  }
}
.ysgc-kind {
  // width: 1650px;
  width: 1400px;
  margin: 0 auto;

  .specail {
    width: 100%;

    display: flex;
    flex-wrap: wrap;

    li {
      height: 278px;
      display: inline-block;
      margin: 0 13px 17px 0;
      overflow: hidden;
      box-shadow: 0px 10px 24px 0px rgba(161, 153, 168, 0.18);
    }

    .kc {
      width: 330px;
      background: #ffffff;
      border-radius: 12px;
      box-shadow: 0px 10px 24px 0px rgba(161, 153, 168, 0.18);
      position: relative;
      .kc-back {
        width: 100%;
        height: 196px;
        display: block;
      }
      .mask {
        z-index: 4;
        width: 100%;
        height: 196px;
        display: block;
        position: absolute;
        top: 0;
        left: 0;
        background: rgba(0, 0, 0, 0.4) url("@/assets/img/zhjy/start.png")
          no-repeat center;
      }
      .kc-des {
        padding: 11px 6px;
        box-sizing: border-box;

        .kc-name {
          height: 22px;
          font-size: 16px;
          font-family: PingFangSC, PingFangSC-Regular;
          font-weight: 400;
          color: #000000;
          line-height: 22px;
        }
        .rate {
          display: flex;
          margin: 11px 0;
          img {
            margin-right: 6px;
          }
        }
      }
    }
  }
}
.footer {
  width: 100%;
  height: 50px;
  margin-top: 100px;

  display: inline-block;
}
</style>

