<template>
  <div class="mark-detail-quality">
    <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-width="0px">
          <el-button type="primary" @click="search">查询</el-button>
        </el-form-item>
      </el-form>
      <div class="part-box-action">
        <el-button type="primary" icon="el-icon-refresh-left" @click="toReset">
          重新计算
        </el-button>
        <el-button type="primary" icon="el-icon-data-line" @click="toViewLine">
          给分曲线
        </el-button>
      </div>
    </div>

    <div class="part-box part-box-pad">
      <el-table
        ref="TableList"
        :data="dataList"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          type="selection"
          fixed="left"
          width="55"
          align="center"
        ></el-table-column>
        <el-table-column prop="courseName" label="评卷员" min-width="100">
          <template slot-scope="scope">
            <el-tag size="medium" type="info">
              {{ scope.row.name }}（{{ scope.row.orgName }}）
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="groupQuestions"
          label="评阅题目"
          min-width="200"
        ></el-table-column>
        <el-table-column
          prop="finishCount"
          label="完成任务数"
          width="100"
        ></el-table-column>
        <el-table-column prop="adoptionRate" label="评卷采用率" width="100">
          <span slot-scope="scope">{{ scope.row.adoptionRate || 0 }}%</span>
        </el-table-column>
        <el-table-column
          prop="avgSpeed"
          label="评卷速度(秒)"
          width="100"
        ></el-table-column>
        <el-table-column
          prop="avgScore"
          label="平均分"
          width="100"
        ></el-table-column>
        <el-table-column
          prop="maxScore"
          label="最高分"
          width="100"
        ></el-table-column>
        <el-table-column
          prop="minScore"
          label="最低分"
          width="100"
        ></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>
    <!-- QualityChartDialog -->
    <quality-chart-dialog
      ref="QualityChartDialog"
      :data="chartData"
    ></quality-chart-dialog>
  </div>
</template>

<script>
import {
  markQualityListPage,
  markQualityUpdate,
  markGroupQuestions,
} from "../../api";
import QualityChartDialog from "./QualityChartDialog.vue";

export default {
  name: "mark-detail-quality",
  props: {
    baseInfo: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  components: { QualityChartDialog },
  data() {
    return {
      filter: {
        groupNumber: "",
        loginName: "",
      },
      current: 1,
      size: this.GLOBAL.pageSize,
      total: 0,
      dataList: [],
      multipleSelection: [],
      chartData: {},
      questions: [],
    };
  },
  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 markQualityListPage(datas);
      this.dataList = data.records;
      this.total = data.total;
    },
    toPage(page) {
      this.current = page;
      this.getList();
    },
    search() {
      this.toPage(1);
    },
    handleSelectionChange(val) {
      this.multipleSelection = val.map((item) => item.markUserGroupId);
    },
    async toReset(row) {
      const confirm = await this.$confirm("确定要重新计算吗？", "提示", {
        type: "warning",
      }).catch(() => {});
      if (confirm !== "confirm") return;

      await markQualityUpdate({
        examId: this.baseInfo.examId,
        paperNumber: this.baseInfo.paperNumber,
        groupNumber: this.filter.groupNumber || undefined,
      });
      this.$message.success("操作成功！");
      this.getList();
    },
    toViewLine() {
      if (!this.filter.groupNumber) {
        this.$message.error("请先选择评阅题目");
        return;
      }
      this.chartData = {
        examId: this.baseInfo.examId,
        paperNumber: this.baseInfo.paperNumber,
        groupNumber: this.filter.groupNumber,
      };
      this.$refs.QualityChartDialog.open();
    },
  },
};
</script>
