<template>
  <el-container>
    <el-main class="el-main-padding">
      <commonFormVue :form="form" :getExamCondition="getExamCondition">
        <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 disciplineTypeList"
                :key="item.name"
                :label="item.desc"
                :value="item.name"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </commonFormVue>
      <el-row>
        <el-col :span="24">
          <el-button
            @click="search('clickSelectBtn')"
            size="small"
            icon="el-icon-search"
            type="primary"
            >查询</el-button
          >
          <el-button
            size="small"
            icon="el-icon-refresh"
            @click="resetForm"
            style="margin-right:10px;"
            >重置</el-button
          >
        </el-col>
      </el-row>
      <el-row>
        <el-col v-show="currentPagePrivileges.BREACH_THE_PRINCIPLE_EXPORT">
          <div class="block-seperator"></div>
          <span>操作：</span>
          <commonExportVue
            :form="form"
            :exportUrl="exportUrl"
            :exportFileName="exportFileName"
          ></commonExportVue>
        </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 width="80" 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="orgName"
              width="150"
            ></el-table-column>
            <el-table-column
              width="120"
              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="150"
            ></el-table-column>
            <el-table-column
              sortable
              label="成功率(%)"
              prop="faceSuccessPercent"
              width="150"
            ></el-table-column>
            <el-table-column
              sortable
              label="违纪类型"
              prop="disciplineType"
              width="120"
            ></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 commonExportVue from "../component/commonExport.vue";
import { DISCIPLINE_TYPE_LIST } from "../constants/constants";
import pagePrivilege from "../mixin/pagePrivilege.js";
import _ from "lodash";
export default {
  components: { commonFormVue, commonExportVue },
  mixins: [pagePrivilege],
  data() {
    return {
      disciplineTypeList: DISCIPLINE_TYPE_LIST,
      total: 0,
      tableLoading: false,
      exportLoading: 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,
        orgName: null,
        studentCode: null,
        studentName: null,
        isWarn: null,
        pageNo: 1,
        pageSize: 10
      },

      getExamCondition: {
        params: {
          name: "",
          examTypes: "ONLINE",
          propertyKeys: "IS_FACE_ENABLE"
        },
        filterCondition: "IS_FACE_ENABLE"
      },
      tableData: [],
      exportUrl: "/api/ecs_oe_admin/exam/audit/discipline/list/export",
      exportFileName: "违纪名单",
      currentPagePrivileges: {
        BREACH_THE_PRINCIPLE_EXPORT: false,
        SNAPSHOT_DETAILS: false //详情查看
      }
    };
  },
  computed: {
    ...mapState({ user: state => state.user })
  },
  methods: {
    resetForm() {
      this.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,
        orgName: null,
        studentCode: null,
        studentName: null,
        isWarn: null,
        pageNo: 1,
        pageSize: 10
      };
    },
    search(type) {
      if (!this.form.examId) {
        this.$notify({
          title: "警告",
          message: "请选择考试批次",
          type: "warning",
          duration: 1000
        });
        return false;
      }
      if (type && type == "clickSelectBtn") {
        this.form.pageNo = 1;
      }
      this.tableLoading = true;
      var params = JSON.parse(JSON.stringify(this.form));
      this.$http
        .post("/api/ecs_oe_admin/exam/audit/discipline/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/illegalityNameList?" + 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 + "/illegalityNameList"
      });
    },
    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();
      }
    }
  },
  created() {
    this.form.rootOrgId = this.user.rootOrgId;
    this.backFill();
  }
};
</script>
<style scoped src="../style/common.css"></style>
