<template>
  <div class="mark-detail-task">
    <div class="part-box part-box-filter part-box-flex">
      <el-form ref="FilterForm" label-position="left" label-width="85px" inline>
        <el-form-item label="评阅题目">
          <el-select
            v-model="filter.groupNumber"
            placeholder="评阅题目"
            clearable
          >
            <el-option
              v-for="group in questions"
              :key="group.groupNumber"
              :value="group.groupNumber"
              :label="group.groupQuestions"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="评卷员">
          <el-input
            v-model.trim="filter.loginName"
            placeholder="评卷员姓名"
            clearable
          >
          </el-input>
        </el-form-item>
        <el-form-item label="状态">
          <el-select v-model="filter.status" placeholder="状态" clearable>
            <el-option
              v-for="(val, key) in MARK_TASK_STATUS"
              :key="key"
              :value="key"
              :label="val"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学号">
          <el-input
            v-model.trim="filter.studentCode"
            placeholder="学号"
            clearable
          >
          </el-input>
        </el-form-item>
        <el-form-item label="密号">
          <el-input
            v-model.trim="filter.secretNumber"
            placeholder="密号"
            clearable
          >
          </el-input>
        </el-form-item>
        <el-form-item label="小题得分">
          <el-input-number
            v-model="filter.subScore"
            placeholder="小题得分"
            clearable
            :min="0"
            :max="999"
            :step="0.01"
            step-strictly
            :controls="false"
          >
          </el-input-number>
        </el-form-item>
        <el-form-item label-width="0px">
          <el-button type="primary" @click="search">查询</el-button>
        </el-form-item>
      </el-form>
    </div>

    <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="groupQuestions"
          label="评阅题目"
          min-width="200"
        ></el-table-column>
        <el-table-column
          prop="studentCode"
          label="学号"
          width="180"
        ></el-table-column>
        <el-table-column
          prop="studentName"
          label="姓名"
          width="120"
        ></el-table-column>
        <el-table-column
          prop="secretNumber"
          label="密号"
          width="100"
        ></el-table-column>
        <el-table-column
          prop="teachClassName"
          label="教学班"
          min-width="200"
        ></el-table-column>
        <el-table-column
          prop="statusDisplay"
          label="状态"
          width="80"
        ></el-table-column>
        <el-table-column prop="userName" label="评卷员" min-width="200">
          <template slot-scope="scope">
            <span v-if="scope.row.userName">
              {{ scope.row.userName }}（{{ scope.row.loginName }}）
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="markerScore"
          label="评卷总分"
          width="90"
        ></el-table-column>
        <el-table-column
          prop="markerScoreList"
          label="给分明细"
          width="90"
        ></el-table-column>
        <el-table-column prop="markerTime" label="评卷时间" width="170">
          <span slot-scope="scope">{{
            scope.row.markerTime | timestampFilter
          }}</span>
        </el-table-column>
        <el-table-column prop="rejectUserName" label="打回人" min-width="200">
          <template slot-scope="scope">
            <span
              v-if="scope.row.status === 'REJECTED' && scope.row.rejectUserName"
            >
              {{ scope.row.rejectUserName }}（{{ scope.row.rejectLoginName }}）
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="headerTime" label="打回时间" width="170">
          <template slot-scope="scope">
            <span v-if="scope.row.status === 'REJECTED'">{{
              scope.row.headerTime | timestampFilter
            }}</span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="rejectReason" label="打回原因" width="120">
          <template slot-scope="scope">
            <span v-if="scope.row.status === 'REJECTED'">{{
              scope.row.rejectReason
            }}</span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column
          class-name="action-column"
          label="操作"
          width="120"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button
              v-if="checkPrivilege('link', 'MarkTaskReject')"
              class="btn-primary"
              :disabled="scope.row.status !== 'MARKED'"
              type="text"
              @click="toReject(scope.row)"
              >打回</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="part-page">
        <el-pagination
          background
          layout="total, sizes, prev, pager, next, jumper"
          :pager-count="5"
          :current-page="current"
          :total="total"
          :page-size="size"
          @current-change="toPage"
          @size-change="pageSizeChange"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { markDetailTaskListPage, markGroupQuestions } from "../../api";
import { MARK_TASK_STATUS } from "@/constants/enumerate";
import markMinxin from "../../markMinxin";

export default {
  name: "mark-detail-task",
  mixins: [markMinxin],
  props: {
    baseInfo: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  data() {
    return {
      filter: {
        groupNumber: "",
        loginName: "",
        status: "",
        studentCode: "",
        secretNumber: "",
        subScore: undefined,
      },
      current: 1,
      size: this.GLOBAL.pageSize,
      total: 0,
      dataList: [],
      questions: [],
      MARK_TASK_STATUS,
    };
  },
  mounted() {
    this.getQuestions();
    this.search();
  },
  methods: {
    async getQuestions() {
      const res = await markGroupQuestions({
        examId: this.baseInfo.examId,
        paperNumber: this.baseInfo.paperNumber,
      });
      this.questions = res || [];
    },
    async getList() {
      const datas = {
        ...this.filter,
        examId: this.baseInfo.examId,
        paperNumber: this.baseInfo.paperNumber,
        pageNumber: this.current,
        pageSize: this.size,
      };
      const data = await markDetailTaskListPage(datas);
      this.dataList = data.records;
      this.total = data.total;
    },
    toPage(page) {
      this.current = page;
      this.getList();
    },
    search() {
      this.toPage(1);
    },
    toReject(row) {
      this.toMarkReject({
        taskId: row.id,
        groupNumber: row.groupNumber,
        paperNumber: row.paperNumber,
        studentCode: row.studentCode,
        studentName: row.studentName,
        courseCode: this.baseInfo.courseCode,
        courseName: this.baseInfo.courseName,
      });
    },
  },
};
</script>
