<template>
  <div class="training-plan-manage">
    <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')">
          <el-form-item label="专业：">
            <professional-select
              v-model="filter.professionalId"
              placeholder="专业"
            ></professional-select>
          </el-form-item>
          <el-form-item label="培养方案：">
            <training-plan-select
              v-model="filter.cultureProgramId"
              placeholder="培养方案"
              :professional-id="filter.professionalId"
              professional-required
            ></training-plan-select>
          </el-form-item>
          <el-form-item label="课程：">
            <training-plan-course-select
              v-model="filter.courseId"
              placeholder="课程"
              :professional-id="filter.professionalId"
              :culture-program-id="filter.cultureProgramId"
            ></training-plan-course-select>
          </el-form-item>
        </template>
        <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>

    <div class="part-box part-box-pad">
      <el-table ref="TableList" :data="dataList">
        <el-table-column
          type="index"
          label="序号"
          width="55"
          :index="indexMethod"
        ></el-table-column>
        <el-table-column prop="courseName" label="课程名称" min-width="200">
        </el-table-column>
        <el-table-column prop="courseCode" label="课程代码" width="120">
        </el-table-column>
        <el-table-column
          prop="outlineName"
          label="课程大纲名称"
          min-width="300"
        >
        </el-table-column>
        <el-table-column prop="evaluationMode" label="考核方式" width="100">
          <span slot-scope="scope">
            {{ scope.row.evaluationMode | evaluationModeFilter }}
          </span>
        </el-table-column>
        <el-table-column prop="userName" label="负责教师" min-width="120">
        </el-table-column>
        <el-table-column
          prop="targetCount"
          label="课程目标数量"
          width="110"
        ></el-table-column>
        <el-table-column prop="weightSetting" label="权重设置状态" width="110">
          <template slot-scope="scope">
            <span :class="scope.row.weightSetting ? '' : 'color-gray-2'">
              {{ scope.row.weightSetting ? "已完成" : "未完成" }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          class-name="action-column"
          label="操作"
          width="100"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button
              v-if="checkPrivilege('link', 'edit')"
              class="btn-primary"
              type="text"
              @click="toEdit(scope.row)"
              >编辑</el-button
            >
            <el-button
              v-if="checkPrivilege('link', 'delete')"
              class="btn-danger"
              type="text"
              @click="toDelete(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>
    <!-- DetailCourseExamine -->
    <detail-course-examine
      v-if="checkPrivilege('link', 'edit')"
      ref="DetailCourseExamine"
      :row-data="curRow"
      @modified="getList"
    ></detail-course-examine>
  </div>
</template>

<script>
import { courseExamineListPage, deleteCourseExamine } from "../api";
import DetailCourseExamine from "../components/course-examine/DetailCourseExamine.vue";

export default {
  name: "course-examine-manage",
  components: { DetailCourseExamine },
  data() {
    return {
      filter: {
        professionalId: "",
        cultureProgramId: "",
        courseId: "",
      },
      current: 1,
      size: this.GLOBAL.pageSize,
      total: 0,
      dataList: [],
      curRow: {},
    };
  },
  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 courseExamineListPage(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.DetailCourseExamine.open();
    },
    async toDelete(row) {
      const confirm = await this.$confirm(`确定要删除当前记录吗?`, "提示", {
        type: "warning",
      }).catch(() => {});
      if (confirm !== "confirm") return;

      await deleteCourseExamine(row.id);
      this.$message.success("删除成功！");
      this.deletePageLastItem();
    },
  },
};
</script>
