<template>
  <div class="plan-link-paper">
    <div class="part-box part-box-filter part-box-flex">
      <el-form ref="FilterForm" label-position="left" label-width="85px" inline>
        <el-form-item label="关联状态：">
          <el-select
            v-model="filter.relateType"
            style="width: 100px;"
            placeholder="请选择"
          >
            <el-option
              v-for="(val, key) in RELATE_TYPE"
              :key="key"
              :value="key"
              :label="val"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="印刷计划：">
          <print-plan-select
            v-model.trim="filter.printPlanId"
            placeholder="请选择"
            clearable
          ></print-plan-select>
        </el-form-item>
        <el-form-item label="课程（代码）：" label-width="110px">
          <course-select
            v-model.trim="filter.courseCode"
            placeholder="请选择"
            clearable
          ></course-select>
        </el-form-item>
        <el-form-item label="试卷编号：">
          <paper-number-select
            ref="PaperNumberSelect"
            v-model="filter.paperNumber"
            placeholder="请选择"
            clearable
          ></paper-number-select>
        </el-form-item>
        <el-form-item label-width="0px">
          <el-button type="primary" icon="el-icon-search" @click="search"
            >查询</el-button
          >
        </el-form-item>
      </el-form>
    </div>

    <div class="part-box">
      <el-table ref="TableList" :data="dataList" border stripe>
        <el-table-column
          type="index"
          label="序号"
          width="70"
          align="center"
          :index="indexMethod"
        ></el-table-column>
        <el-table-column
          prop="printPlanName"
          label="印刷计划"
        ></el-table-column>
        <el-table-column prop="paperNumber" label="试卷编号"></el-table-column>
        <el-table-column prop="courseName" label="课程（代码）">
          <span slot-scope="scope"
            >{{ scope.row.courseName }}（{{ scope.row.courseCode }}）</span
          >
        </el-table-column>
        <el-table-column prop="specialty" label="适用专业（方向）">
        </el-table-column>
        <el-table-column prop="cardRuleName" label="题卡规则">
        </el-table-column>
        <el-table-column prop="userName" label="命题老师" width="100">
        </el-table-column>
        <el-table-column prop="exposedPaperType" label="已曝光类型" width="100">
        </el-table-column>
        <el-table-column
          prop="unexposedPaperType"
          label="未曝光类型"
          width="100"
        >
        </el-table-column>
        <el-table-column prop="relatePaperType" label="关联卷型" width="100">
        </el-table-column>
        <el-table-column label="关联状态" width="80">
          <span slot-scope="scope">
            {{ scope.row.relatePaperType ? "已关联" : "未关联" }}
          </span>
        </el-table-column>
        <el-table-column prop="totalSubjects" label="总科次" width="80">
        </el-table-column>
        <el-table-column
          class-name="action-column"
          label="操作"
          align="center"
          width="80px"
        >
          <template slot-scope="scope">
            <el-button
              class="btn-table-icon"
              type="text"
              icon="icon icon-edit"
              @click="toEdit(scope.row)"
              title="关联试卷"
            ></el-button>
          </template>
        </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"
          @current-change="toPage"
        >
        </el-pagination>
      </div>
    </div>

    <!-- ModifyPlanPaper -->
    <modify-plan-paper
      :instance="curRow"
      @modified="getList"
      ref="ModifyPlanPaper"
    ></modify-plan-paper>
  </div>
</template>

<script>
import { planLinkPaperListPage } from "../api";
import ModifyPlanPaper from "../components/ModifyPlanPaper";

export const RELATE_TYPE = {
  RELATE: "已关联",
  NOT_RELATE: "未关联"
};

export default {
  name: "plan-link-paper",
  components: { ModifyPlanPaper },
  data() {
    return {
      filter: {
        printPlanId: "",
        courseCode: "",
        paperNumber: "",
        relateType: ""
      },
      current: 1,
      size: this.GLOBAL.pageSize,
      total: 0,
      dataList: [],
      curRow: {},
      RELATE_TYPE
    };
  },
  created() {
    this.search();
  },
  methods: {
    async getList() {
      const datas = {
        ...this.filter,
        pageNumber: this.current,
        pageSize: this.size
      };
      const data = await planLinkPaperListPage(datas);
      this.dataList = data.records;
      this.total = data.total;
    },
    toPage(page) {
      this.current = page;
      this.getList();
    },
    search() {
      this.toPage(1);
    },
    toEdit(row) {
      this.curRow = row;
      this.$refs.ModifyPlanPaper.open();
    }
  }
};
</script>
