<template>
  <div>
    <el-dialog
      class="print-plan-detail page-dialog"
      :visible.sync="modalIsShow"
      :title="title"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      append-to-body
      fullscreen
      @open="visibleChange"
    >
      <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="课程（代码）：" label-width="110px">
            <course-select
              v-model.trim="filter.courseId"
              :semester-id="filter.semesterId"
              :exam-id="filter.examId"
              :print-plan-id="filter.printPlanIdList"
              placeholder="课程（代码）"
              clearable
            ></course-select>
          </el-form-item>
          <el-form-item label="试卷编号：">
            <paper-number-select
              ref="PaperNumberSelect"
              v-model="filter.paperNumber"
              :print-plan-id="filter.printPlanIdList"
              :exam-id="filter.examId"
              :course-id="filter.courseId"
              placeholder="试卷编号"
              clearable
            ></paper-number-select>
          </el-form-item>
          <el-form-item label="命题老师：">
            <el-input
              v-model.trim="filter.userName"
              placeholder="命题老师"
              clearable
            ></el-input>
          </el-form-item>
          <el-form-item label-width="0px">
            <el-button type="primary" @click="search">查询</el-button>
          </el-form-item>
        </el-form>
      </div>

      <div class="part-box part-box-pad box-justify">
        <p>
          <span class="mr-4">
            该印刷计划共计：
            <i class="color-primary">{{ totalInfo.courseTotal }}</i>
            门课程
          </span>
          <span class="mr-4">
            <i class="color-primary">{{ totalInfo.taskTotal }}</i> 个命题任务
          </span>
          <span class="mr-4">
            <i class="color-primary">{{ totalInfo.subjectTotal }}</i>
            科次（考生人数）
          </span>
        </p>
        <p>
          <el-button type="primary" @click="toBatchLink">批量关联</el-button>
        </p>
      </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="学期"
            min-width="210"
          ></el-table-column>
          <el-table-column
            prop="examName"
            label="考试"
            min-width="160"
          ></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="userName" label="命题老师" min-width="100">
          </el-table-column>
          <el-table-column
            prop="exposedPaperType"
            label="已曝光类型"
            width="100"
          >
            <template slot-scope="scope">
              <span v-if="scope.row.exposedPaperType"
                >卷{{ scope.row.exposedPaperType }}</span
              >
              <span v-else>--</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="unexposedPaperType"
            label="未曝光类型"
            width="100"
          >
            <template slot-scope="scope">
              <span v-if="scope.row.unexposedPaperType"
                >卷{{ scope.row.unexposedPaperType }}</span
              >
              <span v-else>--</span>
            </template>
          </el-table-column>
          <el-table-column prop="relatePaperType" label="关联卷型" width="100">
            <span slot-scope="scope">{{
              scope.row.relatePaperType | defaultFieldFilter
            }}</span>
          </el-table-column>
          <el-table-column prop="totalSubjects" label="科次" width="80">
          </el-table-column>
          <el-table-column
            class-name="action-column"
            label="操作"
            width="100"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-button
                class="btn-primary"
                type="text"
                @click="toEdit(scope.row)"
                >关联试卷</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="tips-info">
        <p>说明：批量关联操作，只能关联所有命题任务共有的卷型</p>
      </div>
    </el-dialog>

    <!-- ModifyPlanPaper -->
    <modify-plan-paper
      :instance="curRow"
      @modified="getList"
      ref="ModifyPlanPaper"
    ></modify-plan-paper>
    <!-- PrintPlanBatchLinkPaper -->
    <print-plan-batch-link-paper
      ref="PrintPlanBatchLinkPaper"
      :filter-data="filterData"
      @modified="getList"
    ></print-plan-batch-link-paper>
  </div>
</template>

<script>
import { planLinkPaperListPage, planLinkPaperTotal } from "../api";
import ModifyPlanPaper from "./ModifyPlanPaper";
import PrintPlanBatchLinkPaper from "./PrintPlanBatchLinkPaper.vue";

export default {
  name: "print-plan-detail",
  components: { ModifyPlanPaper, PrintPlanBatchLinkPaper },
  props: {
    plan: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  computed: {
    title() {
      return `印刷计划详情-${this.plan.name}`;
    },
  },
  data() {
    return {
      modalIsShow: false,
      filter: {
        semesterId: "",
        examId: "",
        printPlanIdList: [],
        courseId: "",
        paperNumber: "",
        userName: "",
      },
      filterData: {},
      dataList: [],
      curRow: {},
      totalInfo: {},
    };
  },
  methods: {
    visibleChange() {
      this.filter = {
        semesterId: this.plan.semesterId,
        examId: this.plan.examId,
        printPlanIdList: [this.plan.id],
        courseId: "",
        paperNumber: "",
        userName: "",
      };
      this.dataList = [];
      this.totalInfo = {};
      this.search();
    },
    cancel() {
      this.modalIsShow = false;
    },
    open() {
      this.modalIsShow = true;
    },
    async getTotal() {
      const data = await planLinkPaperTotal(this.filter);
      this.totalInfo = data || {};
    },
    async getList() {
      const datas = {
        ...this.filter,
      };
      const data = await planLinkPaperListPage(datas);
      this.dataList = data;

      this.filterData = { ...this.filter };
    },
    toPage(page) {
      this.current = page;
      this.getList();
    },
    search() {
      this.toPage(1);
      this.getTotal();
    },
    toEdit(row) {
      this.curRow = row;
      this.$refs.ModifyPlanPaper.open();
    },
    toBatchLink() {
      this.$refs.PrintPlanBatchLinkPaper.open();
    },
  },
};
</script>
