<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>
        <span>年级</span>
        <el-tabs v-model="firstForm.grade" @click="initData">
          <el-tab-pane
            v-for="(item, index) in gradeList"
            :key="index"
            :label="item.grade_name"
            :name="item.grade_id"
          ></el-tab-pane>
        </el-tabs>
      </div>

      <div>
        <span>科目</span>
        <el-tabs v-model="firstForm.subject" @click="initData">
          <el-tab-pane
            v-for="(item, index) in subjectList"
            :key="index"
            :label="item.subject_name"
            :name="item.subject_id"
          ></el-tab-pane>
        </el-tabs>
      </div>
    </div>

    <div class="list-right">
      <div v-for="(item, index) in wholeData" :key="index">
        <img class="img-show" :src="https + item.zt_img" alt="" />
        <div class="main">
          <p class="main-title">{{ item.zt_name }}</p>
          <img
            @click="editData(item.zt_id)"
            class="edit"
            src="@/assets/img/edit.png"
            alt=""
          />
          <img
            @click="deleteData(item.zt_id)"
            class="delete"
            src="@/assets/img/delete.png"
            alt=""
          />

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

<script>
import { grade_list, tbjy_list, subject_list, tbjy_delete } from "./api";

export default {
  data() {
    return {
      activeName: "1",
      wholeData: [],
      resultData: [],
      keyword: "",
      https: window.GLOBAL_CONFIG.api,
      gradeList: [],
      subjectList: [],
      grade_id: "",
      subject_id: "",
      firstForm: {
        grade: "",
        subject: "",
      },
      isRead: false,
    };
  },
  methods: {
    //年级
    gradeListData() {
      let data = {
        page: 1,
        limit: 9999,
      };
      grade_list(data).then((res) => {
        if (res.code == 1) {
          this.gradeList = res.data.page_data;
          let obj = {
            grade_id: "",
            grade_name: "全部",
          };
          this.gradeList.unshift(obj);
        }
      });
    },
    //科目列表
    subjectListData() {
      let data = {
        page: 1,
        limit: 9999,
      };
      subject_list(data).then((res) => {
        if (res.code == 1) {
          this.subjectList = res.data.page_data;
          let obj = {
            subject_id: "",
            subject_name: "全部",
          };
          this.subjectList.unshift(obj);
        }
      });
    },
    initData() {
      let data = {
        page: this.page,
        limit: this.limit,
        keyword: this.keyword,
        grade_id: this.firstForm.grade,
        subject_id: this.firstForm.subject,
      };

      tbjy_list(data).then((res) => {
        if (res.code == 1) {
          this.wholeData = res.data.page_data;
        }
      });
    },

    addData() {
      this.$router.push({ name: "tbjy-create" });
    },
    editData(id) {
      this.$router.push({ name: "tbjy-create", query: { id: id } });
    },
    deleteData(id) {
      let data = {
        zt_id: id,
      };
      this.$confirm("确认删除该课程?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          tbjy_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.gradeListData();
    this.subjectListData();
    // 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>
.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);
      height: 150px;
      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;
          height: 20px;
          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>