<template>
  <el-container>
    <el-main>
      <commonFormVue :form="form" :getExamCondition="getExamCondition">
        <el-row v-show="showAllCondition">
          <el-col :span="6">
            <el-form-item label="考试ID">
              <el-input
                class="form_search_width"
                size="small"
                v-model="form.examRecordDataId"
                placeholder="考试ID"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="审核结果">
              <el-select
                class="form_search_width"
                size="small"
                v-if="currentPagePrivileges.INVIGILATE_AUDIT_STATUS"
                v-model="form.status"
                clearable
                placeholder="全部"
              >
                <el-option value="PASS" label="通过"></el-option>
                <el-option value="UN_PASS" label="不通过"></el-option>
              </el-select>
              <el-input
                v-if="!currentPagePrivileges.INVIGILATE_AUDIT_STATUS"
                placeholder="不通过"
                :disabled="true"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="审核说明">
              <el-select
                class="form_search_width"
                size="small"
                v-model="form.disciplineType"
                clearable
                placeholder="全部"
              >
                <el-option
                  v-for="item in auditExplainList"
                  :key="item.name"
                  :label="item.desc"
                  :value="item.name"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="审核人">
              <el-input
                class="form_search_width"
                size="small"
                v-model="form.auditUserName"
                placeholder="审核人"
              >
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </commonFormVue>
      <el-col :span="24">
        <el-button
          @click="search"
          size="small"
          type="primary"
          icon="el-icon-search"
          >查询
        </el-button>
        <el-button
          size="small"
          type="primary"
          icon="el-icon-more"
          v-if="!showAllCondition"
          @click="showMoreCondition"
        >
          高级查询
        </el-button>
        <el-button
          size="small"
          type="primary"
          v-if="showAllCondition"
          @click="showSimpleCondition"
        >
          简单查询
        </el-button>
        <el-button
          size="small"
          icon="el-icon-refresh"
          @click="resetForm"
          class="margin-bottom-10"
        >
          重置
        </el-button>
      </el-col>
      <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 label="考试ID">
              <template slot-scope="scope">
                <el-button
                  v-show="currentPagePrivileges.SNAPSHOT_DETAILS"
                  @click="gotoCaptureDetail(scope.row.examRecordDataId)"
                  type="text"
                  >{{ scope.row.examRecordDataId }}
                </el-button>
                <span v-show="!currentPagePrivileges.SNAPSHOT_DETAILS">
                  {{ scope.row.examRecordDataId }}
                </span>
              </template>
            </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 sortable label="校验次数" prop="faceTotalCount">
            </el-table-column>
            <el-table-column sortable label="成功次数" prop="faceSuccessCount">
            </el-table-column>
            <el-table-column
              sortable
              label="陌生人记录"
              prop="faceStrangerCount"
            >
            </el-table-column>
            <el-table-column
              sortable
              label="人脸识别成功率(%)"
              prop="faceSuccessPercent"
            >
            </el-table-column>
            <el-table-column sortable label="考试次数" prop="examOrder">
            </el-table-column>
            <el-table-column sortable label="审核说明" prop="disciplineType">
            </el-table-column>
            <el-table-column sortable label="审核结果" prop="status">
            </el-table-column>
            <el-table-column sortable label="审核人" prop="auditUserName">
            </el-table-column>
          </el-table>
          <div class="block pull-right">
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page.sync="form.pageNo"
              :page-sizes="[10, 20, 50, 100]"
              :page-size="form.pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total"
            >
            </el-pagination></div></el-col
      ></el-row>
    </el-main>
  </el-container>
</template>
<script>
import { mapState } from "vuex";
import commonFormVue from "../component/commonForm.vue";
import { AUDIT_EXPLAIN_LIST } from "../constants/constants";
import pagePrivilege from "../mixin/pagePrivilege.js";
export default {
  components: { commonFormVue },
  mixins: [pagePrivilege],
  data() {
    return {
      auditExplainList: AUDIT_EXPLAIN_LIST,
      total: 0,
      tableLoading: false,
      showAllCondition: false,
      form: {
        examRecordDataId: null,
        hasStranger: null,
        courseId: null,
        courseLevel: null,
        examId: null,
        faceSuccessPercentLower: null,
        faceSuccessPercentUpper: null,
        identityNumber: null,
        orgId: null,
        studentCode: null,
        studentName: null,
        isWarn: null,
        pageNo: 1,
        pageSize: 10,
        disciplineType: "",
        auditUserName: "",
        status: ""
      },

      getExamCondition: {
        params: {
          name: "",
          examTypes: "ONLINE",
          propertyKeys: "IS_FACE_ENABLE"
        },
        filterCondition: "IS_FACE_ENABLE"
      },
      tableData: [],
      currentPagePrivileges: {
        INVIGILATE_AUDIT_STATUS: false, //数据状态
        SNAPSHOT_DETAILS: false //详情查看
      }
    };
  },
  computed: {
    ...mapState({ user: state => state.user })
  },
  methods: {
    resetForm() {
      this.form = {
        examRecordDataId: null,
        hasStranger: null,
        courseId: null,
        courseLevel: null,
        examId: null,
        faceSuccessPercentLower: null,
        faceSuccessPercentUpper: null,
        identityNumber: null,
        orgId: null,
        studentCode: null,
        studentName: null,
        isWarn: null,
        pageNo: 1,
        pageSize: 10,
        disciplineType: "",
        auditUserName: "",
        status: ""
      };
    },
    showMoreCondition() {
      this.showAllCondition = true;
    },
    showSimpleCondition() {
      this.$notify({
        title: "提示",
        message: "高级查询条件值已重置",
        type: "info",
        duration: 2000
      });
      this.resetForm();
      this.showAllCondition = false;
    },
    search() {
      if (!this.form.examId) {
        this.$notify({
          title: "警告",
          message: "请选择考试批次",
          type: "warning",
          duration: 2000
        });
        return false;
      }
      this.tableLoading = true;
      var params = JSON.parse(JSON.stringify(this.form));
      this.$http
        .post("/api/ecs_oe_admin/exam/audit/list", params)
        .then(response => {
          if (response.data) {
            this.tableData = response.data.content;
            this.total = response.data.totalElements;
            this.form.pageNo = response.data.number + 1;
          } else {
            this.tableData = [];
          }
          this.tableLoading = false;
          this.$router.push({
            path: "/oe/alreadyAudited?" + new URLSearchParams(params)
          });
        });
    },
    selectable(row) {
      return row.isWarn;
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    /**
     * pagesize改变时触发
     */
    handleSizeChange(val) {
      this.form.pageSize = val;
      this.search();
    },
    /**
     * 当前页改变时触发
     */
    handleCurrentChange() {
      this.search();
    },
    gotoCaptureDetail(examRecordDataId) {
      this.$router.push({
        path: "/oe/captureDetail/" + examRecordDataId + "/alreadyAudited"
      });
    },
    backFill() {
      var formData = this.$route.query;
      if (formData && formData.examId) {
        for (var attr in formData) {
          var value = formData[attr];
          if (value && value != "null") {
            if (!isNaN(value)) {
              if (~~value == value) {
                value = parseInt(value);
              } else {
                value = parseFloat(value);
              }
            }
            this.form[attr] = value;
          }
        }
        this.search();
      }
    }
  },
  watch: {
    "currentPagePrivileges.INVIGILATE_AUDIT_STATUS": function(val) {
      this.form.status = val ? "" : "UN_PASS";
    }
  },
  created() {
    this.form.status = this.currentPagePrivileges.INVIGILATE_AUDIT_STATUS
      ? ""
      : "UN_PASS";
    this.backFill();
  }
};
</script>
<style scoped>
.el-row {
  position: static !important;
}
.margin-top-10 {
  margin-top: 10px;
}
.select-type {
  font-size: 8px;
  cursor: pointer;
  color: #409eff;
}
</style>
<style scoped src="../style/common.css"></style>
