<template>
  <el-container>
    <el-main>
      <commonFormVue :form="form" :getExamCondition="getExamCondition">
      </commonFormVue>
      <el-row>
        <el-col :span="24">
          <el-button @click="search" size="medium" type="primary"
            >查询</el-button
          >
        </el-col>
      </el-row>
      <el-row class="margin-top-10"
        ><el-col :span="24">
          <el-table
            v-loading="tableLoading"
            element-loading-text="数据加载中"
            ref="multipleTable"
            @selection-change="handleSelectionChange"
            :data="tableData"
            border
          >
            <el-table-column sortable label="学习中心" prop="orgName">
            </el-table-column>
            <el-table-column sortable label="姓名" prop="studentName">
            </el-table-column>
            <el-table-column sortable label="身份证号" prop="identityNumber">
            </el-table-column>
            <el-table-column sortable label="学号" prop="studentCode">
            </el-table-column>
            <el-table-column sortable label="课程" prop="courseName">
            </el-table-column>
            <el-table-column sortable label="课程层次" prop="courseLevel">
            </el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="info"
                  @click="openReexamineDialog(scope.row.examStudentId);"
                  icon="el-icon-info"
                  >设置重考</el-button
                >
              </template>
            </el-table-column>
          </el-table>
          <div class="block">
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page.sync="form.pageNo"
              :page-sizes="[10, 30, 50, 100]"
              :page-size="form.pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total"
            >
            </el-pagination></div></el-col
      ></el-row>
      <el-dialog title="设置重考" :visible.sync="dialogFormVisible">
        <el-form :model="reexamineForm">
          <el-form-item label="重考理由">
            <el-select
              v-model="reexamineForm.reexamineType"
              placeholder="请选择"
            >
              <el-option
                v-for="item in reexamineTypeList"
                :key="item.name"
                :label="item.desc"
                :value="item.name"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="详情描述">
            <el-input
              v-model="reexamineForm.reexamineDetail"
              type="textarea"
              :autosize="{ minRows: 6, maxRows: 10 }"
              placeholder="请输入内容"
            >
            </el-input>
          </el-form-item>
          <div class="dialog-footer">
            <el-button @click="dialogFormVisible = false;">取 消</el-button>
            <el-button type="primary" @click="doSetReexamine">确 定</el-button>
          </div>
        </el-form>
      </el-dialog>
    </el-main>
  </el-container>
</template>
<script>
import { mapState } from "vuex";
import commonFormVue from "../component/commonForm.vue";
export default {
  components: { commonFormVue },
  data() {
    return {
      dialogFormVisible: false,
      total: 0,
      tableLoading: false,
      form: {
        examRecordDataId: null,
        hasStranger: null,
        courseId: null,
        courseLevel: null,
        examId: null,
        examRecordId: null,
        faceSuccessPercentLower: null,
        faceSuccessPercentUpper: null,
        livenessSuccessPercentLower: null,
        livenessSuccessPercentUpper: null,
        identityNumber: null,
        orgId: null,
        studentCode: null,
        studentName: null,
        isWarn: null,
        pageNo: 1,
        pageSize: 10
      },
      reexamineForm: {
        examStudentId: "",
        reexamineType: "",
        reexamineDetail: ""
      },
      getExamCondition: {
        params: {
          name: "",
          examTypes: "ONLINE"
        },
        filterCondition: ""
      },
      tableData: [],
      reexamineTypeList: [
        { desc: "断电", name: "POWER_FAILURE" },
        { desc: "机器故障", name: "MACHINE_STOPPAGE" },
        { desc: "其他", name: "OTHER" }
      ]
    };
  },
  computed: {
    ...mapState({ user: state => state.user })
  },
  methods: {
    search() {
      if (!this.form.examId) {
        this.$notify({
          title: "警告",
          message: "请选择考试批次",
          type: "warning",
          duration: 1000
        });
        return false;
      }
      this.tableLoading = true;
      this.$http
        .post("/api/ecs_oe_admin/exam/student/reexamine/list", this.form)
        .then(response => {
          if (response.data) {
            this.tableData = response.data.content;
            this.total = response.data.totalElements;
          } else {
            this.tableData = [];
          }
          this.tableLoading = false;
        });
    },
    selectable(row) {
      return row.isWarn;
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    /**
     * pagesize改变时触发
     */
    handleSizeChange(val) {
      this.form.pageSize = val;
      this.search();
    },
    /**
     * 当前页改变时触发
     */
    handleCurrentChange() {
      this.search();
    },
    openReexamineDialog(examStudentId) {
      this.dialogFormVisible = true;
      this.reexamineForm = {
        examStudentId: examStudentId,
        reexamineType: "",
        reexamineDetail: ""
      };
    },
    doSetReexamine() {
      var param = new URLSearchParams({
        examStudentId: this.reexamineForm.examStudentId
      });
      this.$http
        .post("/api/ecs_oe_admin/exam/student/reexamine", param)
        .then(() => {
          this.$notify({
            title: "成功",
            message: "操作成功",
            type: "success"
          });
          this.dialogFormVisible = false;
          this.search();
        });
    }
  },
  created() {}
};
</script>
<style scoped>
.el-row {
  position: static !important;
}
.margin-top-10 {
  margin-top: 10px;
}
</style>
