<template>
  <div>
    <LinkTitlesCustom :currentPaths="['评卷总览', '评卷进度', '课程详情']" />
    <section class="content">
      <div class="box box-info">
        <div class="box-body">
          <el-form
            :inline="true"
            :model="formSearch"
            label-position="right"
            label-width="60px"
          >
            <el-form-item label="登录名" class="pull-left">
              <el-input
                placeholder="登录名"
                v-model="formSearch.userLoginName"
              ></el-input>
            </el-form-item>
            <el-form-item label="姓名" class="pull-left">
              <el-input
                placeholder="姓名"
                v-model="formSearch.userName"
              ></el-input>
            </el-form-item>
            <el-form-item>
              <el-button
                size="small"
                type="primary"
                icon="el-icon-search"
                @click="searchSetting"
                >查询</el-button
              >
              <!--
                <el-button size="small"  type="primary" icon="info" @click="exportMarker">导出</el-button>
              -->
              <el-button
                size="small"
                type="primary"
                icon="el-icon-arrow-left"
                @click="back"
                >返回</el-button
              >
            </el-form-item>
          </el-form>
          <div class="block-seperator"></div>
          <!-- 页面列表 -->
          <el-table
            stripe
            v-loading="loading"
            element-loading-text="拼命加载中"
            :data="tableData"
            border
            style="width: 100%"
          >
            <el-table-column label="姓名" width="200" prop="userName" />
            <el-table-column
              label="登录名"
              min-width="100"
              prop="userLoginName"
            />
            <el-table-column
              label="试卷类型"
              min-width="200"
              prop="markRangeName"
            />
            <el-table-column
              label="完成数量"
              min-width="100"
              prop="markedCount"
              sortable
            />
            <el-table-column
              label="最低分"
              min-width="100"
              prop="minScore"
              sortable
            />
            <el-table-column
              label="最高分"
              min-width="100"
              prop="maxScore"
              sortable
            />
            <el-table-column
              label="平均分"
              min-width="100"
              prop="avgScore"
              sortable
            />
            <el-table-column
              label="标准方差"
              min-width="100"
              prop="stdDev"
              sortable
            />
          </el-table>
          <div class="page pull-right">
            <el-pagination
              background
              @current-change="handleSettingCurrentChange"
              @size-change="handleSizeChange"
              :current-page="currentPage"
              :page-size="pageSize"
              :page-sizes="[10, 20, 50, 100]"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total"
            ></el-pagination>
          </div>
        </div>
      </div>
    </section>
  </div>
</template>

<script>
import { DATA_PROCESS_API } from "@/constants/constants";
import { mapState } from "vuex";
import LinkTitlesCustom from "@/components/LinkTitlesCustom.vue";
export default {
  data() {
    return {
      formSearch: {
        userLoginName: "",
        userName: ""
      },
      tableData: [],
      oldData: [],
      currentPage: 1,
      pageSize: 10,
      total: 10,
      loading: true,
      workId: "",
      examId: "",
      courseCode: ""
    };
  },
  components: {
    LinkTitlesCustom
  },
  methods: {
    handleSettingCurrentChange(val) {
      this.currentPage = val;
      this.searchSetting();
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.searchSetting();
    },
    pagingSetting() {
      var start = (this.currentPage - 1) * this.pageSize;
      var end =
        this.currentPage * this.pageSize < this.total
          ? this.currentPage * this.pageSize
          : this.total;
      var tempData = [];
      console.log(`当前页: ${this.currentPage},开始:${start},结束:${end}`);
      for (let i = start; i < end; i++) {
        tempData.push(this.tableData[i]);
      }
      this.tableData = tempData;
    },
    initSetting() {
      this.loading = true;
      this.$http
        .get(
          DATA_PROCESS_API +
            "/markTasks/all/0/" +
            this.pageSize +
            "?workId=" +
            this.workId +
            "&examId=" +
            this.examId +
            "&courseCode=" +
            this.courseCode
        )
        .then(response => {
          console.log(response);
          this.tableData = response.data.content;
          this.total = response.data.totalElements;
          this.loading = false;
        });
    },
    searchSetting() {
      this.loading = true;
      this.$http
        .get(
          DATA_PROCESS_API +
            "/markTasks/all/" +
            (this.currentPage - 1) +
            "/" +
            this.pageSize +
            "?workId=" +
            this.workId +
            "&examId=" +
            this.examId +
            "&courseCode=" +
            this.courseCode,
          { params: this.formSearch }
        )
        .then(response => {
          console.log(response);
          this.tableData = response.data.content;
          this.total = response.data.totalElements;
          this.loading = false;
        });
    },
    exportMarker() {
      window.location.href =
        "/api/ecs_data_process/markTasks/exportMarker?workId=" +
        this.workId +
        "&examId=" +
        this.examId +
        "&courseCode=" +
        this.courseCode;
    },
    back() {
      this.$router.back();
      // this.$router.push({
      //   path: "/marking/mark_work_overview"
      // });
    }
  },
  computed: {
    ...mapState({ user: state => state.user })
  },
  created() {
    this.workId = this.$route.params.workId;
    this.examId = this.$route.params.examId;
    this.courseCode = this.$route.params.courseCode;
    this.initSetting();
  }
};
</script>
<style lang="css" scoped>

li {
    list-style-type: none;
}

.searchFrame {
    margin-right: 10px;
    margin-bottom: 10px;
}

.page{
  margin-top: 10px;
}
.f_button{
    display:block;
    width:57px;
    height:20px;
    border:1px solid #CCC;
    background:#FFF;
    font-size: small;
}
</style>
