<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="培养方案名称：">
            <el-input
              v-model.trim="filter.cultureProgramName"
              placeholder="培养方案名称"
              clearable
            ></el-input>
          </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="obeCultureProgramName" label="培养方案名称">
        </el-table-column>
        <el-table-column prop="professionalName" label="专业">
        </el-table-column>
        <el-table-column
          prop="requirementDegree"
          label="毕业要求达成值"
          width="120"
        >
        </el-table-column>
        <el-table-column
          class-name="action-column"
          label="操作"
          width="160"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button
              v-if="checkPrivilege('link', 'detail')"
              class="btn-primary"
              type="text"
              @click="toDetail(scope.row)"
              >查看详情</el-button
            >
            <el-button
              v-if="checkPrivilege('link', 'Calculate')"
              class="btn-primary"
              type="text"
              @click="toCalculate(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>
    <!-- DetailRequirementStatistics -->
    <detail-requirement-statistics
      v-if="checkPrivilege('link', 'detail')"
      ref="DetailRequirementStatistics"
      :row-data="curRow"
    ></detail-requirement-statistics>
  </div>
</template>

<script>
import {
  requirementStatisticsListPage,
  requirementStatisticsCalculate,
} from "../api";
import DetailRequirementStatistics from "../components/requirement-statistics/DetailRequirementStatistics.vue";

export default {
  name: "requirement-statistics",
  components: { DetailRequirementStatistics },
  data() {
    return {
      filter: {
        professionalId: "",
        cultureProgramName: "",
      },
      current: 1,
      size: this.GLOBAL.pageSize,
      total: 0,
      dataList: [],
      curRow: {},
    };
  },
  mounted() {
    this.search();
  },
  methods: {
    async getList() {
      if (!this.checkPrivilege("list", "list")) return;

      const datas = {
        ...this.filter,
        pageNumber: this.current,
        pageSize: this.size,
      };
      const data = await requirementStatisticsListPage(datas);
      this.dataList = data.records;
      this.total = data.total;
    },
    toPage(page) {
      this.current = page;
      this.getList();
    },
    search() {
      this.toPage(1);
    },
    toDetail(row) {
      this.curRow = row;
      this.$refs.DetailRequirementStatistics.open();
    },
    async toCalculate(row) {
      const confirm = await this.$confirm(`确定要重新计算当前数据吗?`, "提示", {
        type: "warning",
      }).catch(() => {});
      if (confirm !== "confirm") return;

      await requirementStatisticsCalculate({
        cultureProgramId: row.cultureProgramId,
      });
      this.getList();
    },
  },
};
</script>
