<template>
  <div class="my-class-score">
    <div class="page-head page-head-flex">
      <h2>
        <span>我的课堂</span>
        <el-popover
          popper-class="el-popper-dark"
          placement="right-start"
          width="300"
          trigger="hover"
        >
          <i class="el-icon-question" slot="reference"></i>
          <div>
            <p>我在各考查学院授课课堂的平均分查询，以及课堂考试情况分析。</p>
          </div>
        </el-popover>
      </h2>
      <div v-if="orgName">
        <i class="icon icon-sign"></i>开课学院：{{ orgName }}
      </div>
    </div>
    <div class="part-box part-box-filter">
      <el-form ref="FilterForm" label-position="left" label-width="60px" inline>
        <el-form-item label="学期：">
          <semester-select
            v-model="filter.semesterId"
            select-default
            :clearable="false"
            @change="semesterChange"
          ></semester-select>
        </el-form-item>
        <el-form-item label="考试：">
          <exam-select
            v-model="filter.examId"
            :semester-id="filter.semesterId"
            select-default
            :clearable="false"
            @change="examChange"
          ></exam-select>
        </el-form-item>
        <el-form-item label="课程：">
          <course-select
            v-model="filter.courseCode"
            :exam-id="filter.examId"
            is-teach
          ></course-select>
        </el-form-item>
        <el-form-item label="考查学院：">
          <inspect-college-select
            v-model="filter.inspectCollegeId"
            :filter="filter"
          ></inspect-college-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" round @click="search">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="part-box part-box-pad">
      <el-table
        ref="TableList"
        :data="dataList"
        border
        @sort-change="sortChange"
      >
        <el-table-column
          prop="teacherName"
          label="任课老师"
          sortable="custom"
        ></el-table-column>
        <el-table-column
          prop="inspectCollegeName"
          label="考查学院"
          sortable="custom"
        ></el-table-column>
        <el-table-column
          prop="courseCode"
          label="课程(代码)"
          sortable="custom"
          min-width="100"
        >
          <span
            class="text-link"
            slot-scope="scope"
            @click="toDetail(scope.row)"
          >
            {{ scope.row.courseName }}（{{ scope.row.courseCode }}）
          </span>
        </el-table-column>
        <el-table-column
          prop="teachCollegeName"
          label="开课学院"
          sortable="custom"
        ></el-table-column>
        <el-table-column prop="avgScore" label="应届平均分" min-width="100">
        </el-table-column>
        <!-- <el-table-column
          prop="teacherCount"
          label="教师人数"
          min-width="80"
        ></el-table-column>
        <el-table-column
          prop="rank"
          label="考查学院院内排名"
          sortable="custom"
          width="160"
        ></el-table-column> -->
      </el-table>
      <div class="part-page">
        <el-pagination
          background
          layout="total,prev, pager, next"
          :current-page="current"
          :total="total"
          :page-size="size"
          @current-change="toPage"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { schoolTeacherMyClassRank } from "../api";

export default {
  name: "my-class-score",
  data() {
    return {
      isInit: false,
      filter: {
        semesterId: "",
        examId: "",
        courseCode: "",
        inspectCollegeId: "",
        column: null,
        order: null
      },
      orgName: "",
      current: 1,
      size: this.GLOBAL.pageSize,
      total: 0,
      dataList: []
    };
  },
  created() {
    const orgInfo = this.$ls.get("user", { orgInfo: { name: "" } }).orgInfo;
    if (orgInfo) this.orgName = orgInfo.name;
  },
  methods: {
    search() {
      this.toPage(1);
    },
    async getList() {
      const datas = {
        ...this.filter,
        pageNumber: this.current,
        pageSize: this.size
      };
      const data = await schoolTeacherMyClassRank(datas);
      this.dataList = data.records;
      this.total = data.total;
    },
    toPage(page) {
      this.current = page;
      this.getList();
    },
    semesterChange() {
      this.filter.examId = null;
      this.examChange();
    },
    examChange() {
      this.filter.inspectCollegeId = null;
      this.filter.courseCode = null;

      // 初次载入页面加载默认数据
      if (!this.isInit && this.filter.examId && this.filter.semesterId) {
        this.isInit = true;
        this.search();
      }
    },
    sortChange({ prop, order }) {
      if (order) {
        this.filter.column = prop;
        this.filter.order = order.replace("ending", "").toUpperCase();
      } else {
        this.filter.column = null;
        this.filter.order = null;
      }
      this.getList();
    },
    toDetail(row) {
      this.$ls.set("myClassCourseSet", {
        semesterId: this.filter.semesterId,
        examId: this.filter.examId,
        courseCode: row.courseCode,
        inspectCollegeId: row.inspectCollegeId
      });
      this.$router.push({ name: "MyClassExamView" });
    }
  }
};
</script>
