<template>
  <div class="data-init-manage">
    <div class="part-box part-box-filter part-box-flex">
      <el-form ref="FilterForm" label-position="left" label-width="55px" inline>
        <template v-if="checkPrivilege('condition', 'condition')">
          <el-form-item label="学期：">
            <semester-select
              v-model="filter.semesterId"
              placeholder="学期"
            ></semester-select>
          </el-form-item>
          <el-form-item label="考试：">
            <exam-select
              v-model="filter.examId"
              :semester-id="filter.semesterId"
              placeholder="考试"
            ></exam-select>
          </el-form-item>
          <el-form-item label="课程：">
            <course-select
              v-model="filter.courseCode"
              placeholder="课程"
              :semester-id="filter.semesterId"
              :exam-id="filter.examId"
            ></course-select>
          </el-form-item>
        </template>
        <el-form-item>
          <el-button
            v-if="checkPrivilege('button', 'select')"
            type="primary"
            @click="toPage(1)"
            >查询</el-button
          >
        </el-form-item>
      </el-form>
      <div class="part-box-action"></div>
    </div>
    <div class="part-box part-box-pad">
      <el-table ref="TableList" :data="dataList">
        <el-table-column
          type="index"
          label="序号"
          width="50"
          :index="indexMethod"
        ></el-table-column>
        <el-table-column
          prop="semesterName"
          label="学期"
          min-width="160"
        ></el-table-column>
        <el-table-column prop="examName" label="考试" min-width="160">
        </el-table-column>
        <el-table-column prop="courseCode" 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="status" label="状态" width="100">
        </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', 'window') && !scope.row.publishStatus
              "
              class="btn-primary"
              type="text"
              @click="toConfig(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>
    <!-- ModifyBaseConfig -->
    <modify-base-config
      ref="ModifyBaseConfig"
      :instance="curRow"
    ></modify-base-config>
  </div>
</template>

<script>
import { dataInitList } from "../api";
import ModifyBaseConfig from "../components/ModifyBaseConfig.vue";

export default {
  name: "data-init-manage",
  components: { ModifyBaseConfig },
  data() {
    return {
      filter: {
        semesterId: "",
        examId: "",
        courseCode: ""
      },
      current: 1,
      size: this.GLOBAL.pageSize,
      total: 0,
      dataList: [],
      curRow: {},
      loading: false
    };
  },
  mounted() {
    this.toPage(1);
  },
  methods: {
    async getList() {
      if (!this.checkPrivilege("list", "list")) return;

      const datas = {
        ...this.filter,
        pageNumber: this.current,
        pageSize: this.size
      };
      const data = await dataInitList(datas);
      this.dataList = data.records;
      this.total = data.total;
    },
    toPage(page) {
      this.current = page;
      this.getList();
    },
    toConfig(row) {
      console.log(row);
      this.curRow = row;
      this.$refs.ModifyBaseConfig.open();
    }
  }
};
</script>
