<template>
  <div class="upload-structure">
    <div class="part-box part-box-filter part-box-flex">
      <el-form ref="FilterForm" label-position="left" inline>
        <template v-if="checkPrivilege('condition', 'condition')">
          <el-form-item label="学期：">
            <semester-select
              v-model="filter.semesterId"
              default-select
              :clearable="false"
              @default-selected="getList"
            ></semester-select>
          </el-form-item>
          <el-form-item label="考试：">
            <exam-select
              v-model="filter.examId"
              :semester-id="filter.semesterId"
            ></exam-select>
          </el-form-item>
        </template>
        <el-form-item label-width="0px">
          <el-button
            v-if="checkPrivilege('button', 'select')"
            type="primary"
            @click="toPage(1)"
            >查询</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <div class="part-box part-box-pad">
      <el-table ref="TableList" :data="dataList">
        <el-table-column
          prop="thirdRelateId"
          label="云阅卷考试"
          min-width="160"
        >
          <span slot-scope="scope">
            {{ scope.row.thirdRelateId }}（{{
              scope.row.thirdRelateName | defaultFieldFilter
            }}）
          </span></el-table-column
        >
        <el-table-column prop="courseName" label="课程（代码）" min-width="200">
          <span slot-scope="scope">
            {{ scope.row.courseName }}（{{ scope.row.courseCode }}）
          </span>
        </el-table-column>
        <el-table-column
          prop="paperNumber"
          label="试卷编号"
          min-width="160"
        ></el-table-column>
        <el-table-column
          prop="paperType"
          label="试卷类型"
          width="100"
        ></el-table-column>
        <el-table-column prop="thirdRelateId" label="命题老师" min-width="160">
          <span slot-scope="scope">
            {{ scope.row.loginName }}（{{ scope.row.realName }}）
          </span></el-table-column
        >
        <el-table-column
          class-name="action-column"
          label="操作"
          width="160px"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button
              v-if="checkPrivilege('link', 'Submit')"
              class="btn-primary"
              type="text"
              :disabled="scope.row.taskStatus === 'RUNNING'"
              @click="toSetParams(scope.row)"
              >评卷参数设置</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="part-page">
        <el-pagination
          background
          layout="total, sizes, prev, pager, next, jumper"
          :pager-count="5"
          :current-page="current"
          :total="total"
          :page-size="size"
          @current-change="toPage"
          @size-change="pageSizeChange"
        >
        </el-pagination>
      </div>
    </div>

    <ModifyMarkParams
      ref="ModifyMarkParams"
      :instance="curTask"
      @modified="getList"
    />
  </div>
</template>

<script>
import { examStructureListPage } from "../api";
import ModifyMarkParams from "../components/markParam/ModifyMarkParams";

export default {
  name: "upload-structure",
  components: {
    ModifyMarkParams,
  },
  data() {
    return {
      filter: {
        semesterId: "",
        examId: "",
      },
      current: 1,
      size: this.GLOBAL.pageSize,
      total: 0,
      dataList: [],
      curTask: {},
      curMarkLeaders: [],
    };
  },
  methods: {
    delayUpdateList() {
      setTimeout(() => {
        this.getList();
      }, 1000);
    },
    async getList() {
      if (!this.checkPrivilege("list", "list")) return;
      const datas = {
        ...this.filter,
        pageNumber: this.current,
        pageSize: this.size,
      };
      const data = await examStructureListPage(datas);
      this.dataList = data.records;
      this.total = data.total;
    },
    toPage(page) {
      this.current = page;
      this.getList();
    },
    toSetParams(row) {
      this.curTask = row;
      this.$refs.ModifyMarkParams.open();
    },
  },
};
</script>
