<template>
  <div class="course-link-manage">
    <div class="part-box part-box-filter part-box-flex">
      <el-form ref="FilterForm" label-position="left" label-width="85px" inline>
        <el-form-item prop="semesterId" label="学期：">
          <semester-select v-model="filter.semesterId"></semester-select>
        </el-form-item>
        <el-form-item prop="examTypeId" label="考试类型：">
          <exam-type-select v-model="filter.examTypeId"></exam-type-select>
        </el-form-item>
        <el-form-item label="云阅卷课程代码：">
          <el-input
            style="width: 200px"
            v-model.trim="filter.cloudMarkingCourseCode"
            placeholder="云阅卷课程代码模糊查询"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="考务数据课程代码：">
          <el-input
            style="width: 210px"
            v-model.trim="filter.syncCourseCode"
            placeholder="考务数据课程代码模糊查询"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="toPage(1)">查询</el-button>
        </el-form-item>
      </el-form>
      <div class="part-box-action">
        <el-button
          type="primary"
          :disabled="!filter.semesterId || !filter.examTypeId"
          @click="toImport"
          >导入</el-button
        >
      </div>
    </div>
    <div class="part-box part-box-pad">
      <el-table ref="TableList" :data="dataList">
        <el-table-column
          type="index"
          label="序号"
          width="70"
          :index="indexMethod"
        ></el-table-column>
        <el-table-column prop="semesterName" label="学期"></el-table-column>
        <el-table-column prop="examTypeName" label="考试类型"></el-table-column>
        <el-table-column
          prop="cloudMarkingCourseCode"
          label="云阅卷课程代码"
        ></el-table-column>
        <el-table-column
          prop="syncCourseCode"
          label="考务数据课程代码"
        ></el-table-column>
      </el-table>
      <div class="part-page">
        <el-pagination
          background
          layout="total,prev, pager, next"
          :current-page="current"
          :total="total"
          :page-size="size"
          :page-sizes="[20, 50, 100]"
          @current-change="toPage"
        >
        </el-pagination>
      </div>
    </div>

    <!-- CourseLinkUploadDialog -->
    <course-link-upload-dialog
      ref="CourseLinkUploadDialog"
      :upload-data="uploadData"
    ></course-link-upload-dialog>
  </div>
</template>

<script>
import { courseLinkList } from "../api";
import CourseLinkUploadDialog from "../components/CourseLinkUploadDialog.vue";

export default {
  name: "course-link-manage",
  components: { CourseLinkUploadDialog },
  data() {
    return {
      filter: {
        semesterId: "",
        examTypeId: "",
        syncCourseCode: "",
        cloudMarkingCourseCode: "",
      },
      current: 1,
      size: this.GLOBAL.pageSize,
      total: 0,
      dataList: [],
      uploadUrl: "/api/exam_course_mapping/import",
      uploadData: {},
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    async getList() {
      const datas = {
        ...this.filter,
        pageNumber: this.current,
        pageSize: this.size,
      };

      const data = await courseLinkList(datas);
      this.dataList = data.records;
      this.total = data.total;
    },
    toPage(page) {
      this.current = page;
      this.getList();
    },
    toImport() {
      this.uploadData = {
        semesterId: this.filter.semesterId,
        examTypeId: this.filter.examTypeId,
      };
      this.$refs.CourseLinkUploadDialog.open();
    },
    uploadSuccess() {
      this.search();
    },
  },
};
</script>
