<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>

    <div class="list-right">
      <div class="list" v-for="(item, index) in listData" :key="index">
        <div class="img-show"><img :src="item.zx_img" alt="" /></div>
        <div class="main">
          <p class="main-title">{{ item.zx_name }}</p>
          <p class="main-content">{{ item.zx_brief }}</p>
          <div>
            <img src="@/assets/img/zhjy/img.png" alt="" />
            <!-- <el-avatar style=" display: inline-block;width: 24px;   height: 24px;   border-radius: 50%;margin-right: 8px;" :size="16" :src="getAvatarUrl(userMsg.user_id)" /> -->

            {{item.zx_zrjs}}

            <span @click="xtbknrDetail(item.zx_id)">查看</span>
          </div>
        </div>
      </div>
    </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 { xtbk_list, grade_list, subject_list, user_avatar, user_info } from "./api";
import { getFullUrl, getAvatarUrl } from '@/utils/helper';

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: 10,
      currentPage: 1,
      total: 0,
      https: window.GLOBAL_CONFIG.api,
      gradeList: [],
      subjectList: [],
      grade_id: "",
      subject_id: "",
      gradeData: [],
      activeGrade: "",
      subjectData: [],
      activeSubject: "",
      userMsg: {},
    };
  },
  methods: {
    xtbknrDetail(id) {
      this.$router.push({ name: "zhjy_zhjyxtbk_nrxq", params: { id: id } });
    },
    // 获取用户信息
    getUser() {
      var locData = window.localStorage.getItem("userInfo");
      var user_id = JSON.parse(locData).user_id; //老师的role_id
      let data = {
        user_id: user_id,
      };
      user_info(data).then((res) => {
        this.userMsg = res.data;
      });
    },
    //数据获取
    getData() {
      let data = {
        page: this.currentPage,
        limit: this.pageSize,
        keyword: this.keyword,
        grade_id: this.activeGrade,
        subject_id: this.activeSubject,
      };
      console.log("data", data);
      xtbk_list(data).then((res) => {
        console.log("data1", data);
        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();
    },
    //头像数据
    AvatarData() {
      let data = { user_id: this.user_id };
      user_avatar(data).then((res) => {
        if (res.code == 1) {
          this.avatarList = res.data;
        }
      });
    },
  },
  mounted() {
    this.getData();
    this.initGradeData();
    this.initSubjectData();
    this.AvatarData();
    this.getUser();
  },
};
</script>

<style lang="scss" scoped>
.content {
  width: 100%;
  min-width: 1400px;
  margin: 0 auto;
}
.search-list {
  display: flex;
  align-items: baseline;
  font-size: 14px;
  margin: 10px 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);
      }
    }
  }
}
.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/xtbk_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;
  padding: 10px 0;
  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;

  .list {
    box-sizing: border-box;
    width: 630px;
    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: 50px;
    }

    .img-show {
      width: 283px;
      height: 150px;
      border-radius: 12px 0px 0px 12px;
      overflow: hidden;
      img {
        width: 100%;
        height: 100%;
      }
    }

    .main {
      display: flex;
      flex-direction: column;
      padding-left: 12px;
      position: relative;
      width: 380px;
      height: 150px;

      .main-title {
        display: inline-block;
        vertical-align: top;
        font-size: 16px;
        font-family: PingFangSC, PingFangSC-Medium;
        font-weight: 500;
        text-align: left;
        color: #050026;
        line-height: 22px;
        word-wrap: break-word;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 1;
        overflow: hidden;
      }

      .main-content {
        margin-top: 10px;
        font-size: 14px;
        height: 35px;
        word-wrap: break-word;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
        color: #949494;
        line-height: 17px;
      }

      div {
        width: 330px;
        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;
        right: 25px;

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

        span {
          display: inline-block;
          width: 71px;
          height: 26px;
          line-height: 26px;
          opacity: 0.8;
          background: linear-gradient(90deg, #00a3ff, #57c38f);
          border-radius: 13px;
          font-size: 14px;
          font-weight: 400;
          text-align: center;
          color: #ffffff;
          letter-spacing: 0.6px;
          float: right;
          cursor: pointer;
        }
      }
    }
  }
}

.z-footer {
  width: 100%;
  height: 50px;
  margin-top: 100px;

  display: inline-block;
}
</style>

