<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="80px"
          >
            <el-form-item label="姓名" class="pull-left">
              <el-input
                placeholder="姓名"
                v-model="formSearch.userName"
              ></el-input>
            </el-form-item>
            <el-form-item label="登录名" class="pull-left">
              <el-input
                placeholder="登录名"
                v-model="formSearch.userLoginName"
              ></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="success"
                icon="el-icon-caret-left"
                @click="back"
                >返回</el-button
              >
            </el-form-item>
          </el-form>

          <!-- 页面列表 -->
          <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="courseCount"
            />
            <el-table-column
              label="完成课程"
              min-width="100"
              prop="finishedCount"
            />
            <el-table-column
              label="完成数量"
              min-width="100"
              prop="markedCount"
            />
            <el-table-column label="最低分" min-width="100" prop="minScore" />
            <el-table-column label="最高分" min-width="100" prop="maxScore" />
            <el-table-column label="平均分" min-width="100" prop="avgScore" />
            <el-table-column label="标准方差" min-width="100" prop="stdDev" />
            <el-table-column :context="_self" label="操作" fixed="right">
              <template slot-scope="scope">
                <el-button
                  @click="markerDetail(scope.row)"
                  type="primary"
                  size="mini"
                  plain
                  >详情</el-button
                >
              </template>
            </el-table-column>
          </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: "",
      examName: ""
    };
  },
  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 +
            "/markers/all/" +
            (this.currentPage - 1) +
            "/" +
            this.pageSize +
            "?workId=" +
            this.workId
        )
        .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 +
            "/markers/all/" +
            (this.currentPage - 1) +
            "/" +
            this.pageSize +
            "?workId=" +
            this.workId,
          { params: this.formSearch }
        )
        .then(response => {
          console.log(response);
          this.tableData = response.data.content;
          this.total = response.data.totalElements;
          this.loading = false;
        });
    },
    markerDetail(row) {
      var url =
        "/marking/marker_detail/" +
        this.$route.params.workId +
        "/" +
        this.$route.params.examId +
        "/" +
        this.$route.params.name +
        "/" +
        row.userId +
        "/" +
        row.userName;
      this.$router.push({
        path: url
      });
    },
    back() {
      this.$router.push({
        path: "/marking/mark_setting_work/marker"
      });
    }
  },
  computed: {
    ...mapState({ user: state => state.user })
  },
  created() {
    this.workId = this.$route.params.workId;
    this.examId = this.$route.params.examId;
    this.examName = this.$route.params.name;
    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>
