<template>
  <el-container>
    <el-main class="el-main-padding">
      <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
                size="small"
                class="form_search_width"
                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('clickSelectBtn')"
          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"
              width="120"
            >
            </el-table-column>
            <el-table-column
              sortable
              label="学号"
              prop="studentCode"
              width="120"
            >
            </el-table-column>
            <el-table-column
              sortable
              label="课程"
              prop="courseName"
              width="120"
            >
            </el-table-column>
            <el-table-column
              sortable
              label="课程层次"
              prop="courseLevel"
              width="120"
            >
            </el-table-column>
            <el-table-column
              sortable
              label="校验次数"
              prop="faceTotalCount"
              width="120"
            >
            </el-table-column>
            <el-table-column
              sortable
              label="成功次数"
              prop="faceSuccessCount"
              width="120"
            >
            </el-table-column>
            <el-table-column
              sortable
              label="陌生人记录"
              prop="faceStrangerCount"
              width="120"
            >
            </el-table-column>
            <el-table-column
              sortable
              label="人脸识别成功率(%)"
              prop="faceSuccessPercent"
              width="180"
            >
            </el-table-column>
            <el-table-column
              sortable
              label="考试次数"
              prop="examOrder"
              width="120"
            >
            </el-table-column>
            <el-table-column
              sortable
              label="审核说明"
              prop="disciplineType"
              width="120"
            >
            </el-table-column>
            <el-table-column
              sortable
              label="审核结果"
              prop="status"
              width="120"
            >
            </el-table-column>
            <el-table-column
              sortable
              label="审核人"
              prop="auditUserName"
              width="180"
            >
            </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, 200, 300]"
              :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";
import _ from "lodash";
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 //详情查看
      },
      getPermissionStatus: 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(type) {
      if (!this.form.examId) {
        this.$notify({
          title: "警告",
          message: "请选择考试批次",
          type: "warning",
          duration: 2000
        });
        return false;
      }
      if (type && type == "clickSelectBtn") {
        this.form.pageNo = 1;
      }
      this.tableLoading = true;
      var params = JSON.parse(JSON.stringify(this.form));
      if (!this.currentPagePrivileges.INVIGILATE_AUDIT_STATUS) {
        params.status = "UN_PASS";
      }
      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") {
            //是数字 且 长度小于15
            if (!isNaN(value) && value.toString().length < 15) {
              value = _.toNumber(value);
            }
            this.form[attr] = value;
          }
        }
        this.search();
      }
    }
  },
  watch: {
    //监控权限是否获取完成
    getPermissionStatus: function(val) {
      if (val) {
        if (!this.currentPagePrivileges.INVIGILATE_AUDIT_STATUS) {
          this.form.status = "UN_PASS";
        }
        this.backFill();
      }
    }
  },
  created() {}
};
</script>
<style scoped src="../style/common.css"></style>
