<template>
  <el-dialog
    class="scan-task-detail-dialog page-dialog"
    :visible.sync="modalIsShow"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    append-to-body
    fullscreen
    @open="visibleChange"
  >
    <template slot="title">
      <h3>
        详情
        <span class="color-gray ml-2"
          >{{ task.courseName }}（{{ task.courseCode }}）</span
        >
      </h3>
    </template>

    <div class="part-box part-box-pad">
      <el-table ref="TableList" :data="dataList">
        <el-table-column
          type="index"
          label="序号"
          width="70"
          :index="indexMethod"
        ></el-table-column>
        <el-table-column prop="studentName" label="姓名"></el-table-column>
        <el-table-column prop="studentCode" label="学号"></el-table-column>
        <el-table-column prop="courseCodeName" label="课程名称（代码）">
          <template slot-scope="scope">
            {{ scope.row.courseName }}（{{ scope.row.courseCode }}）
          </template>
        </el-table-column>
        <el-table-column prop="teacher" label="任课老师"></el-table-column>
        <el-table-column prop="teachClass" label="教学班"></el-table-column>
        <el-table-column
          prop="bindCount"
          label="绑定张数"
          width="120"
        ></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>
  </el-dialog>
</template>

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

export default {
  name: "scan-task-detail-dialog",
  props: {
    task: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  data() {
    return {
      modalIsShow: false,
      dataList: [],
      current: 1,
      size: this.GLOBAL.pageSize,
      total: 0,
    };
  },
  computed: {
    title() {
      return `${this.task.scanTaskName}-${this.task.courseName}-详情`;
    },
  },
  methods: {
    visibleChange() {
      this.dataList = [];
      this.toPage(1);
    },
    cancel() {
      this.modalIsShow = false;
    },
    open() {
      this.modalIsShow = true;
    },
    async getList() {
      const datas = {
        paperScanTaskId: this.task.paperScanTaskId,
        pageNumber: this.current,
        pageSize: this.size,
      };
      const data = await scanTaskDetailPage(datas);
      this.dataList = data.records;
      this.total = data.total;
    },
    toPage(page) {
      this.current = page;
      this.getList();
    },
  },
};
</script>
