<template>
  <!-- 在线学习 -->
  <div class="ssysContent">
    <el-card>
      <div style="padding: 0 75px">
        <span class="title">在线学习</span>
        <span class="subTitle">我的课程 - 我创建的 - <span style="color: #000">在线学习</span></span>
      </div>
    </el-card>

    <div class="searchDiv" style="display: flex; justify-content: flex-end">
      <el-button type="primary" @click="addData()">创建</el-button>
      <div class="searchValue">
        <input type="text" placeholder="搜索关键字" v-model="keyword" />
        <div class="searchBtn" @click="initData">
          <img src="/kczy/searchIcon.png" alt="" />
        </div>
      </div>
    </div>
    <div class="line"></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="list-right">
      <div v-for="(item, index) in listData" :key="index">
        <img class="img-show" :src="https + item.zz_img" alt="" />
        <div class="main">
          <p class="main-title">{{ item.zz_name }}</p>
          <img @click="editData(item.zz_id)" class="edit" src="@/assets/img/edit.png" alt="" />
          <img @click="deleteData(item.zz_id)" class="delete" src="@/assets/img/delete.png" alt="" />

          <p class="main-content">{{ item.zz_content }}</p>
          <div>
            <img src="@/assets/img/zhjy/img_3.png" alt="" />{{ item.zz_jsxx }}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { grade_list, zxxx_list, subject_list, zxxx_delete } from "./api";

export default {
  data() {
    return {
      activeName: "1",
      listData: [],

      keyword: "",
      https: window.GLOBAL_CONFIG.api,
      gradeList: [],
      subjectList: [],
      grade_id: "",
      subject_id: "",
      firstForm: {
        grade: "",
        subject: "",
      },
      isRead: false,
      gradeData: [],
      activeGrade: "",
      subjectData: [],
      activeSubject: "",
      typeData: [],
      activeType: "",
    };
  },
  methods: {
    //年级

    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.initData();
    },
    //科目
    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) {
      this.activeSubject = value.subject_id;
      this.initData();
    },
    // 分类
    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.initData();
    },
    initData() {
      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;
      });
    },

    addData() {
      this.$router.push({ name: "zxxx-create" });
    },
    editData(id) {
      this.$router.push({ name: "zxxx-create", query: { id: id } });
    },
    deleteData(id) {
      let data = {
        zz_id: id,
      };
      this.$confirm("确认删除该课程?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          zxxx_delete(data).then((res) => {
            if (res.code == 1) {
              this.$message({
                message: "课程删除成功！",
                type: "success",
              });
              this.initData();
            } else {
              this.$message({
                message: res.msg,
                type: "error",
              });
            }
          });
        })
        .catch(() => { });
    },
  },
  // async created() {
  //   await this.gradeListData();
  //   await this.subjectListData();
  // },
  mounted() {
    this.initData();

    this.initGradeData();
    this.initSubjectData();
    this.initTypeData();
    // const _this = this;
    // document.onkeydown = function (e) {
    //   e = window.event || e;
    //   if (
    //     _this.$route.name == "course-ssys" &&
    //     (e.code === "Enter" || e.code === "enter")
    //   ) {
    //     // 登录事件
    //     _this.initData();
    //   }
    // };
  },
};
</script>

<style lang="scss" scoped>
.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);
      }
    }
  }
}
.ssysContent {
  .el-card {
    margin-bottom: 15px;
    background: #fff;
  }
  .pointer {
    cursor: pointer;
  }
  .title {
    font-size: 18px;
    color: #050026;
  }
  .subTitle {
    font-size: 14px;
    color: #949494;
    margin-left: 45px;
  }
  .searchDiv {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 80px;
    .menuDiv {
      display: flex;
      margin-bottom: -10px;
      .list {
        margin: 0 20px;
        padding: 0 10px;
        color: #949494;
        position: relative;
        line-height: 40px;
        font-size: 14px;
        &::after {
          content: "";
          width: 0;
          height: 2px;
          background: rgba(0, 131, 197, 0.8);
          position: absolute;
          bottom: -10px;
          left: 50%;
          transform: translateX(-50%);
          transition: width linear 0.1s;
        }
        &:hover {
          color: rgba(0, 131, 197, 0.8);
        }
        &.active {
          color: rgba(0, 131, 197, 0.8);
          font-size: 16px;
          &::after {
            width: 100%;
          }
        }
      }
    }
    .el-button {
      width: 100px;
      height: 40px;
      margin-right: 40px;
    }
    .searchValue {
      width: 350px;
      height: 50px;

      background: #ffffff;
      border-radius: 8px;
      overflow: hidden;
      position: relative;
      input {
        width: 100%;
        height: 100%;
        outline: 0;
        box-sizing: border-box;
        padding-left: 10px;
        background: #f6f8fa;
      }
      .searchBtn {
        width: 26px;
        height: 26px;
        background: #00a3ff;
        border-radius: 6px;
        position: absolute;
        right: 5px;
        top: 50%;
        transform: translate(-50%, -50%);
        text-align: center;
        vertical-align: middle;
        cursor: pointer;
        img {
          display: block;
          text-align: center;
          margin: 6px auto 0;
        }
      }
    }
  }
  .line {
    height: 1px;
    background: #eaeaea;
    width: calc(100% + 40px);
    margin-left: -20px;
    margin-top: 10px;
  }
  .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;
      }
    }
  }

  .list-right {
    width: 1400px;
    display: flex;
    flex-wrap: wrap;
    margin: 0 auto;

    & > div {
      box-sizing: border-box;
      width: calc(50% - 40px);

      display: flex;
      margin-bottom: 20px;
      box-shadow: 0px 15px 24px 0px rgba(161, 153, 168, 0.18);
      &:nth-of-type(odd) {
        margin-right: 40px;
      }
      .img-show {
        width: 80%;
        height: 150px;
        margin-right: 12px;
      }
      .main {
        display: inline-block;
        display: flex;
        flex-direction: column;

        width: 100%;

        position: relative;
        .main-title {
          width: 60%;
          vertical-align: top;
          font-size: 16px;
          font-family: PingFangSC, PingFangSC-Medium;
          font-weight: 500;
          text-align: left;
          color: #050026;
          line-height: 22px;
          margin-bottom: 5px;
        }
        .edit,
        .delete {
          width: 18px;
          height: 17px;
          position: absolute;
          top: 10px;
          right: 10px;
        }
        .edit {
          position: absolute;
          top: 10px;
          right: 50px;
        }
        .main-content {
          display: inline-block;
          font-size: 14px;
          font-family: PingFangSC, PingFangSC-Regular;
          font-weight: 400;
          text-align: left;
          color: #949494;
          line-height: 20px;
        }
        div {
          width: 186px;

          display: inline-block;
          font-size: 14px;
          font-family: PingFangSC, PingFangSC-Medium;
          font-weight: 500;
          text-align: left;
          color: #050026;
          line-height: 20px;
          position: absolute;
          bottom: 10px;
          left: 0px;

          img {
            display: inline-block;
            width: 24px;
            height: 24px;
            border-radius: 50%;
            margin-right: 8px;
          }
        }
      }
    }
  }
}
</style>

<style lang="scss" >
.ssysContent {
  .resultCard .el-card__body {
    padding: 0 !important;
  }
}
</style>