<template>
  <el-dialog
    class="preview-more-teacher-list-dialog"
    :visible.sync="modalIsShow"
    title="教师各课堂成绩排名"
    top="10vh"
    width="840px"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    append-to-body
    @opened="dialogOpen"
  >
    <el-table ref="TableList" :data="dataList" border @sort-change="sortChange">
      <el-table-column
        prop="inspectCollegeName"
        label="考查学院"
        sortable="custom"
      ></el-table-column>
      <el-table-column
        prop="teacherName"
        label="任课老师"
        sortable="custom"
      ></el-table-column>
      <el-table-column label="应届平均分" align="center">
        <el-table-column
          prop="currentAvgScoreBefore"
          label="赋分前"
        ></el-table-column>
        <el-table-column
          prop="currentAvgScoreAfter"
          label="赋分后"
        ></el-table-column>
      </el-table-column>
      <el-table-column
        prop="teacherRank"
        label="考查学院院内排名"
        sortable="custom"
      ></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 slot="footer"></div>
  </el-dialog>
</template>

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

export default {
  name: "preview-more-teacher-list-dialog",
  props: {
    filter: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  data() {
    return {
      modalIsShow: false,
      setting: {
        column: null,
        order: null
      },
      current: 1,
      size: this.GLOBAL.pageSize,
      total: 0,
      dataList: []
    };
  },
  methods: {
    dialogOpen() {
      this.toPage(1);
    },
    async getList() {
      if (
        !this.filter.examId ||
        !this.filter.semesterId ||
        !this.filter.courseCode
      )
        return;

      const datas = {
        ...this.filter,
        ...this.setting,
        pageNumber: this.current,
        pageSize: this.size
      };
      const data = await courseSurveyTeacherTeacherView(datas);
      this.dataList = data.records;
      this.total = data.total;
    },
    toPage(page) {
      this.current = page;
      this.getList();
    },
    sortChange({ prop, order }) {
      if (order) {
        this.setting.column = prop;
        this.setting.order = order.replace("ending", "").toUpperCase();
      } else {
        this.setting.column = null;
        this.setting.order = null;
      }
      this.getList();
    },
    cancel() {
      this.modalIsShow = false;
    },
    open() {
      this.modalIsShow = true;
    }
  }
};
</script>
