<template>
  <div class="studentWork" v-loading="loading">
    <div class="searchBtn">
      <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>
    <el-empty v-if="resultData.length==0" image-size="100" description="无数据" style="padding: 10px 0;" />
    <div class="resultDiv">
      <el-row :gutter="20">
        <el-col :span="12" v-for="item in resultData" :key="item.name" @click="lookDetail(item.id)">
          <el-card class="resultCard pointer">
            <div style="display: flex;">
              <img class="leftImg" :src="getFullUrl(item.img)" alt="" />
              <div style="flex: 1;padding: 8px 10px;position: relative;font-size: 14px">
                <div class="production">
                  <div style="display: flex;justify-content: space-between;">
                    <div style="font-size: 16px;color: #050026;">{{item.name}}</div>
                  </div>
                  <div style="color: #949494;">{{item.kcjj}}</div>
                  <!-- <div style="color: #000;">{{item.grade_name}} <span v-if="item.grade_name && item.subject_name">|</span> {{item.subject_name}}</div> -->
                </div>
                <div class="user">
                  <div style="display: flex;align-items: center;">
                    <el-avatar style="width: 24px;height: 24px;" :size="16" :src="getAvatarUrl(item.master_user_id)" />
                    <span style="margin-left: 8px;color: #050026;">{{ item.master_teacher }}</span>
                  </div>
                </div>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>

    <div class="paginationDiv">
      <el-pagination background layout="total, prev, pager, next" :total="total" @current-change="handleCurrentChange" :page-size="pageSize" :currentPage="currentPage"></el-pagination>
    </div>
  </div>
</template>

<script>
import { grade_list, subject_list } from "../../../MyCourse/api";
import { getFullUrl, getAvatarUrl } from '@/utils/helper';
export default {
  data() {
    return {
      loading: false,
      gradeData: ["幼儿园", "一年级", "二年级", "三年级", "四年级", "五年级", "六年级", "初一", "初二", "初三", "高一", "高二", "高三", "其他"],
      subjectData: ["美术", "音乐", "舞蹈"],
      activeGrade: "",
      activeSubject: "",
      resultData: [],
      pageSize: 4,
      currentPage: 1,
      total: 0,
    }
  },
  props: ["workType"],
  methods: {
    //年级
    initGradeData() {
      this.gradeData = [
        {
          grade_id: "",
          grade_name: "全部",
        }
      ];
      grade_list({ limit: 50 }).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({ limit: 50 }).then((res) => {
        if (res.code == 1) {
          this.subjectData = this.subjectData.concat(res.data.page_data);
        }
      });
    },
    initSubject(value) {
      this.activeSubject = value.subject_id;

      this.initData();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.initData();
    },
    initData(keyword) {
      this.loading = true;
      request({
        url: '/kzkt/zbkc/index',
        data: {
          keyword: keyword,
          grade_id: this.activeGrade,
          subject_id: this.activeSubject,
          limit: this.pageSize,
          page: this.currentPage,
          yys_id: 0
        }
      }).then(res => {
        if (res.code == 1) {
          this.resultData = res.data.page_data;
          this.total = Number(res.data.total_rows);
          this.loading = false;
        }
      })
    },
    lookDetail(id) {
      this.$router.push({ name: "personal_homework_wlzb_worklist", params: { workType: this.workType, id } });
    }
  },
  created() {
    this.initGradeData();
    this.initSubjectData();
    this.initData();
  }
}
</script>

<style lang="scss" scoped>
.studentWork::v-deep {
  padding: 0 20px;
  .el-card {
    margin-bottom: 15px;
    background: #fff;
    .el-card__body {
      padding: 0;
    }
  }
  .pointer {
    cursor: pointer;
  }
  .searchBtn {
    padding-top: 10px;
    .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;
        .item + .item {
          margin-left: 20px;
        }
        .item {
          padding: 3px 5px;
          &.active {
            color: #00a3ff;
            border-radius: 6px;
            background: rgba($color: #00a3ff, $alpha: 0.1);
          }
        }
      }
    }
  }
  .resultDiv {
    margin-bottom: 50px;
    .resultCard {
      padding: 0 !important;
      .leftImg {
        width: 264px;
        height: 155px;
      }
      .user {
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 14px;
        position: absolute;
        bottom: 8px;
        width: calc(100% - 20px);
      }
    }
  }
  .paginationDiv {
    position: absolute;
    right: 30px;
    bottom: 15px;
    padding: 3px;
  }
}
</style>