<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.courseCode"
              ></el-input>
            </el-form-item>
            <el-form-item label="课程名称" class="pull-left">
              <el-input
                placeholder="课程名称"
                v-model="formSearch.courseName"
              ></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>

          <!-- 页面列表 -->
          <el-table
            stripe
            v-loading="loading"
            element-loading-text="拼命加载中"
            :data="tableData"
            border
            style="width: 100%"
          >
            <el-table-column label="课程名称" width="200" prop="name" />
            <el-table-column label="课程代码" min-width="100" prop="code" />
            <el-table-column
              label="已评数量"
              min-width="200"
              prop="markedCount"
            />
            <el-table-column
              label="打回数量"
              min-width="100"
              prop="rejectCount"
            />
            <el-table-column label="完成状态" min-width="100">
              <template slot-scope="scope">
                <div>
                  <span v-if="scope.row.leftCount == 0">完成</span>
                  <span v-if="scope.row.leftCount != 0">未完成</span>
                </div>
              </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 { MARKING_API } from "@/constants/constants";
import { mapState } from "vuex";
import LinkTitlesCustom from "@/components/LinkTitlesCustom.vue";
export default {
  data() {
    return {
      formSearch: {
        courseCode: "",
        courseName: ""
      },
      tableData: [],
      oldData: [],
      currentPage: 1,
      pageSize: 10,
      total: 10,
      loading: true,
      workId: "",
      examId: "",
      courseCode: "",
      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(
          MARKING_API +
            "/markCourses/all/marker/0/" +
            this.pageSize +
            "?workId=" +
            this.workId +
            "&userId=" +
            this.userId
        )
        .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(
          MARKING_API +
            "/markCourses/all/marker/" +
            (this.currentPage - 1) +
            "/" +
            this.pageSize +
            "?workId=" +
            this.workId +
            "&userId=" +
            this.userId,
          { params: this.formSearch }
        )
        .then(response => {
          console.log(response);
          this.tableData = response.data.content;
          this.total = response.data.totalElements;
          this.loading = false;
        });
    },
    back() {
      this.$router.push({
        path:
          "/marking/marker/" +
          this.workId +
          "/" +
          this.examId +
          "/" +
          this.examName
      });
    }
  },
  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.userName = this.$route.params.userName;
    this.userId = this.$route.params.markerId;
    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>
