<template>
  <common-header />
  <div class="content allPageWidthBg">
    <div class="wholeHeader">
      <div class="title">
        <div class="left">
          自主研学 <span class="one ml-30px">智慧教研-</span
          ><span class="one">自主研学</span
          ><span class="two">-{{ detailData.zzc_name }}</span>
        </div>
        <div class="right" @click="goBack()">返回</div>
      </div>
    </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>

          <div class="kc-back">
            <img @click="zxxxxqDetail(item.zz_id)" :src="item.zz_img" alt="" />
          </div>
          <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="z-footer">
      <div
        style="width: 1400px; height: 50px; position: relative; margin: 0 auto"
      >
        <el-pagination
          style="position: absolute; top: 0; right: 0"
          background
          layout="total, prev, pager, next"
          :total="total"
          @current-change="handleCurrentChange"
          :page-size="pageSize"
          :currentPage="currentPage"
        ></el-pagination>
      </div>
    </div>
  </div>
  <common-footer />
</template>

<script>
import {
  zxxx_list,
  grade_list,
  subject_list,
  zxxx_detail,
  zxxx_kc_detail,
} from "./api";
import CommonHeader from "@/components/CommonHeader/index.vue";
import CommonFooter from "@/components/CommonFooter/index.vue";
export default {
  name: "index",
  components: {
    CommonHeader,
    CommonFooter,
  },
  data() {
    return {
      listData: [],
      keyword: "",
      pageSize: 12,
      currentPage: 1,
      total: 0,
      https: window.GLOBAL_CONFIG.api,
      gradeList: [],
      subjectList: [],
      grade_id: "",
      subject_id: "",
      firstForm: {
        grade: "",
        subject: "",
      },
      gradeData: [],
      activeGrade: "",
      subjectData: [],
      activeSubject: "",
      typeData: [],
      activeType: "",
      detailData: {},
      zz_id: "",
      zzc_id: "",
      parentId: "",
    };
  },
  methods: {
    goBack() {
      this.$router.go(-1);
    },
    //跳转
    zxxxxqDetail(id) {
      this.$router.push({ name: "zhjy_zhjyzxxx_zxxxxq", params: { id: id } });
    },
    zxxxspDetail(id) {
      this.$router.push({ name: "zhjy_zhjyzxxx_zxxxsp", params: { id: id } });
    },
    getDetailData() {
      let data = {
        zzc_id: this.parentId,
      };
      zxxx_kc_detail(data).then((res) => {
        this.detailData = res.data.one_info;
      });
    },
    //数据获取
    getData() {
      let data = {
        page: this.currentPage,
        limit: this.pageSize,
        keyword: this.keyword,
        grade_id: this.activeGrade,
        subject_id: this.activeSubject,
        zz_type: this.activeType,
        zzc_id: this.parentId,
        //zz_home_display: 1
      };

      zxxx_list(data).then((res) => {
        this.listData = res.data.page_data;
        this.total = Number(res.data.total_rows);
      });
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getData();
    },

    //年级
    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() {
    if (this.$route.params.id != "") {
      this.parentId = this.$route.params.id;
      this.getDetailData();
    }
    this.getData();
    this.initGradeData();
    this.initSubjectData();
    this.initTypeData();
  },
};
</script>

<style lang="scss" scoped>
.allPageWidthBg {
  width: 100%;
  padding-bottom: 80px;
  // min-height: 1650px;
  background: url("@/assets/kczy/sourceBg.png") no-repeat;
  background-size: 100%;
}
.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;
}
.wholeHeader {
  width: 100%;
  height: 55px;
  line-height: 55px;
  box-shadow: 0px 0px 24px 0px rgba(161, 153, 168, 0.18);
}
.title {
  display: flex;
  justify-content: space-between;
  width: 1400px;
  height: 55px;
  line-height: 55px;
  font-size: 18px;
  font-family: PingFangSC, PingFangSC-Regular;
  font-weight: 400;
  color: #050026;
  margin: 0 auto;
  padding-right: 30px;

  .one {
    width: 56px;
    height: 20px;
    font-size: 14px;
    font-family: PingFangSC, PingFangSC-Regular;
    font-weight: 400;
    text-align: left;
    color: #949494;
    line-height: 20px;
  }
  .two {
    width: 56px;
    height: 20px;
    font-size: 14px;
    font-family: PingFangSC, PingFangSC-Regular;
    font-weight: 400;
    text-align: left;
    color: #000000;
    line-height: 20px;
  }
  .right {
    width: 100px;
    height: 40px;
    background: rgba(0, 163, 255, 0.8);
    border-radius: 6px;
    font-size: 14px;
    font-family: PingFang SC, PingFang SC-Regular;
    font-weight: 400;
    text-align: center;
    color: #ffffff;
    line-height: 40px;
    margin-top: 10px;
  }
}
.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;
}
.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;
        overflow: hidden;
        cursor: pointer;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .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;
        cursor: pointer;
      }
      .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;
          font-size: 14px;
          word-wrap: break-word;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 1;
          overflow: hidden;
        }
        .rate {
          display: flex;
          margin: 11px 0;
          img {
            margin-right: 6px;
            border: 1px solid red;
          }
        }
      }
    }
  }
}
.z-footer {
  width: 100%;
  height: 50px;
  margin-top: 100px;

  display: inline-block;
}
</style>

