<template>
  <el-container>
    <el-main>
      <commonFormVue :form="form" :getExamCondition="getExamCondition">
        <el-row v-show="showAllCondition">
          <el-col :span="6">
            <el-form-item label="采集人">
              <el-input
                class="form_search_width"
                size="small"
                v-model="form.infoCollector"
                placeholder="采集人"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="开始时间">
              <el-date-picker
                size="small"
                v-model="form.startTime"
                type="datetime"
                placeholder="选择日期时间"
                value-format="yyyy/MM/dd HH:mm:ss"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="结束时间">
              <el-date-picker
                size="small"
                v-model="form.endTime"
                type="datetime"
                placeholder="选择日期时间"
                value-format="yyyy/MM/dd HH:mm:ss"
              >
              </el-date-picker>
            </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>
        <el-col v-show="currentPagePrivileges.EXAM_DETAIL_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 label="考试ID" width="120">
              <template slot-scope="scope">
                <el-button
                  v-show="currentPagePrivileges.SNAPSHOT_DETAILS"
                  @click="gotoCaptureDetail(scope.row.dataId)"
                  type="text"
                  >{{ scope.row.dataId }}
                </el-button>
                <span v-show="!currentPagePrivileges.SNAPSHOT_DETAILS">
                  {{ scope.row.dataId }}
                </span>
              </template>
            </el-table-column>
            <el-table-column
              sortable
              label="学习中心"
              prop="orgName"
              width="120"
            >
            </el-table-column>
            <el-table-column
              sortable
              label="姓名"
              prop="studentName"
              width="120"
            >
            </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="courseNameAndCode"
              width="120"
            >
            </el-table-column>
            <el-table-column
              sortable
              label="课程层次"
              prop="courseLevel"
              width="120"
            >
            </el-table-column>
            <el-table-column sortable label="年级" prop="grade" width="120">
            </el-table-column>
            <el-table-column sortable label="学生电话" prop="phone" width="120">
            </el-table-column>
            <el-table-column
              sortable
              label="采集人"
              prop="infoCollector"
              width="120"
            >
            </el-table-column>
            <el-table-column
              sortable
              label="考试次数"
              prop="examOrder"
              width="120"
            >
            </el-table-column>
            <el-table-column
              sortable
              label="开考时间"
              prop="paperStartTime"
              width="120"
            >
            </el-table-column>
            <el-table-column
              sortable
              label="交卷时间"
              prop="paperSubmitTime"
              width="120"
            >
            </el-table-column>
            <el-table-column
              sortable
              label="持续时间"
              prop="examTime"
              width="120"
            >
            </el-table-column>
            <el-table-column
              sortable
              label="校验成功率(%)"
              prop="faceSuccessPercent"
              width="150"
            >
            </el-table-column>
            <el-table-column
              sortable
              label="续考次数"
              prop="continuedCount"
              width="120"
            >
            </el-table-column>
            <el-table-column
              sortable
              label="卷面总分"
              prop="paperTotalScore"
              width="120"
            >
            </el-table-column>
            <el-table-column
              sortable
              label="是否违纪"
              prop="isIllegality"
              width="120"
            >
            </el-table-column>
            <el-table-column
              sortable
              label="是否提交"
              prop="isSubmit"
              width="120"
            >
            </el-table-column>
            <el-table-column
              fixed="right"
              label="详情"
              v-if="currentPagePrivileges.EXAM_QUERY_GETPAPER"
              width="90"
            >
              <template slot-scope="scope">
                <el-button
                  v-if="scope.row.examType == 'ONLINE'"
                  size="mini"
                  type="primary"
                  icon="el-icon-view"
                  @click="examPaperDetail(scope.row.courseId, scope.row.dataId)"
                  >调卷
                </el-button>
                <el-button
                  v-if="
                    scope.row.examType == 'OFFLINE' && scope.row.offlineFileUrl
                  "
                  size="mini"
                  type="primary"
                  icon="el-icon-view"
                  @click="downloadOfflineFile(scope.row.offlineFileUrl)"
                  >调卷</el-button
                >
              </template>
            </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 commonExportVue from "../component/commonExport.vue";
import { DISCIPLINE_TYPE_LIST } from "../constants/constants";
import pagePrivilege from "../mixin/pagePrivilege.js";
export default {
  components: { commonFormVue, commonExportVue },
  mixins: [pagePrivilege],
  data() {
    return {
      disciplineTypeList: DISCIPLINE_TYPE_LIST,
      total: 0,
      tableLoading: false,
      showAllCondition: false,
      form: {
        examRecordDataId: null,
        hasStranger: null,
        courseId: null,
        courseLevel: null,
        examId: null,
        examRecordId: null,
        faceSuccessPercentLower: null,
        faceSuccessPercentUpper: null,
        identityNumber: null,
        orgId: null,
        studentCode: null,
        studentName: null,
        isWarn: null,
        pageNo: 1,
        pageSize: 10,
        rootOrgId: null,
        startTime: null,
        endTime: null,
        infoCollector: null
      },

      getExamCondition: {
        params: {
          name: "",
          examTypes: "ONLINE#OFFLINE"
        },
        filterCondition: ""
      },
      tableData: [],
      exportUrl: "/api/ecs_oe_admin/exam/record/detail/list/export",
      exportFileName: "考试明细",
      currentPagePrivileges: {
        EXAM_DETAIL_EXPORT: false, //导出
        SNAPSHOT_DETAILS: false, //详情查看
        EXAM_QUERY_GETPAPER: 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,
        identityNumber: null,
        orgId: null,
        studentCode: null,
        studentName: null,
        isWarn: null,
        pageNo: 1,
        pageSize: 10,
        rootOrgId: null,
        startTime: null,
        endTime: null,
        infoCollector: null
      };
    },
    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));
      this.$http
        .post("/api/ecs_oe_admin/exam/record/detail/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/examDetail?" + new URLSearchParams(params)
          });
        });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    /**
     * pagesize改变时触发
     */
    handleSizeChange(val) {
      this.form.pageSize = val;
      this.search();
    },
    /**
     * 当前页改变时触发
     */
    handleCurrentChange() {
      this.search();
    },
    examPaperDetail(courseId, examRecordDataId) {
      window.open(
        "/admin/oe/examPaperDetail/" + courseId + "/" + examRecordDataId
      );
    },
    gotoCaptureDetail(examRecordDataId) {
      this.$router.push({
        path: "/oe/captureDetail/" + examRecordDataId + "/examDetail"
      });
    },
    downloadOfflineFile(url) {
      window.open(url);
    },
    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();
      }
    }
  },
  created() {
    this.form.rootOrgId = this.user.rootOrgId;
    this.backFill();
  }
};
</script>
<style scope>
.el-row {
  position: static !important;
}
.el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: auto !important;
}
.select-type {
  font-size: 8px;
  cursor: pointer;
  color: #409eff;
}
</style>
<style scoped src="../style/common.css"></style>
