<template>
  <div class="mark-setting">
    <div class="part-box part-box-filter part-box-flex">
      <el-form ref="FilterForm" label-position="left" label-width="85px" inline>
        <template v-if="checkPrivilege('condition', 'condition')">
          <secp-select
            v-model="filter"
            defaultSelectExam
            @exam-default="search"
          ></secp-select>
        </template>
        <el-form-item label="状态">
          <el-select
            v-model="filter.groupStatus"
            style="width: 120px"
            placeholder="状态"
            clearable
          >
            <el-option :value="1" label="已提交"></el-option>
            <el-option :value="0" label="未提交"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label-width="0px">
          <el-button
            v-if="checkPrivilege('button', 'select')"
            type="primary"
            @click="search"
            >查询</el-button
          >
        </el-form-item>
      </el-form>
      <div class="part-box-action">
        <el-button
          v-if="checkPrivilege('button', 'add')"
          type="primary"
          :disabled="!multipleSelection.length"
          @click="toBatchModifySetting"
        >
          评卷设置
        </el-button>
      </div>
    </div>

    <div class="part-box part-box-pad">
      <el-table
        ref="TableList"
        :data="dataList"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          type="selection"
          width="55"
          align="center"
        ></el-table-column>
        <el-table-column prop="courseName" label="课程（代码）" min-width="200">
          <template slot-scope="scope">
            {{ scope.row.courseName }}（{{ scope.row.courseCode }}）
          </template>
        </el-table-column>
        <el-table-column
          prop="paperNumber"
          label="试卷编号"
          min-width="140"
        ></el-table-column>
        <el-table-column prop="groupStatus" label="状态" width="120">
          <span slot-scope="scope">{{
            scope.row.groupStatus ? "已提交" : "未提交"
          }}</span>
        </el-table-column>
        <el-table-column prop="markMode" label="评卷模式" width="120">
          <template slot-scope="scope">
            {{ scope.row.markMode | markModeTypeFilter }}
          </template>
        </el-table-column>
        <el-table-column
          class-name="action-column"
          label="操作"
          width="200"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button
              v-if="checkPrivilege('link', 'MarkParamSetting')"
              class="btn-primary"
              type="text"
              @click="toSetParams(scope.row)"
              >评卷参数设置</el-button
            >
            <el-button
              v-if="checkPrivilege('link', 'MarkConfig')"
              class="btn-primary"
              type="text"
              @click="toModifySetting(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>
    <!-- ModifyMarkSetting -->
    <modify-mark-setting
      ref="ModifyMarkSetting"
      :instance="curRow"
      @modified="getList"
    ></modify-mark-setting>
    <!-- ModifyMarkParams -->
    <modify-mark-params
      ref="ModifyMarkParams"
      :instance="curRow"
    ></modify-mark-params>
  </div>
</template>

<script>
import { markSettingListPage } from "../api";
import ModifyMarkSetting from "../components/ModifyMarkSetting.vue";
import ModifyMarkParams from "../components/markParam/ModifyMarkParams";

export default {
  name: "mark-setting",
  components: { ModifyMarkSetting, ModifyMarkParams },
  data() {
    return {
      filter: {
        semesterId: "",
        examId: "",
        courseCode: "",
        paperNumber: "",
        groupStatus: null,
      },
      current: 1,
      size: this.GLOBAL.pageSize,
      total: 0,
      dataList: [],
      curRow: {},
      multipleSelection: [],
    };
  },
  methods: {
    async getList() {
      if (!this.checkPrivilege("list", "list")) return;

      const datas = {
        ...this.filter,
        pageNumber: this.current,
        pageSize: this.size,
      };
      if (datas.groupStatus !== null && datas.groupStatus !== "")
        datas.groupStatus = !!datas.groupStatus;

      const data = await markSettingListPage(datas);
      this.dataList = data.records;
      this.total = data.total;
    },
    toPage(page) {
      this.current = page;
      this.getList();
    },
    search() {
      this.toPage(1);
    },
    handleSelectionChange(val) {
      this.multipleSelection = val.map((item) => item.id);
    },
    toSetParams(row) {
      this.curRow = row;
      this.$refs.ModifyMarkParams.open();
    },
    toModifySetting(row) {
      this.curRow = row;
      this.$refs.ModifyMarkSetting.open();
    },
    toBatchModifySetting() {
      if (!this.multipleSelection.length) {
        this.$message.error("请选择数据");
        return;
      }
    },
  },
};
</script>
