<template>
  <div class="app-container">
    <evaluation-title
      :title="routeParams.name + '/选择班级'"
      :navBackButton="true"
    ></evaluation-title>
    <form-search
      :withoutSearchButton="true"
      :searchformShow="{ class: '', clbum: '' }"
      @change="handleQuery"
      @handleQuery="handleQuery"
      @resetQuery="resetQuery"
    ></form-search>
    <el-row :gutter="10">
      <el-col
        class="evaluation-card-wrapper"
        v-for="(exam, idx) in searchData"
        :key="idx"
        :xs="12"
        :sm="8"
        :md="8"
        :lg="6"
        :xl="6"
      >
        <evaluation-card
          @click.native="detail(exam)"
          :title="exam.name"
          :subTitle="exam.subjectName"
          :thirdTitle="exam.className"
          :stateOptions="mxGlobal.MergeEvalInspectionStates(exam.stateStr)"
          :state="exam.stateStr"
          :pointerEnable="exam.total>0"
          :proportion="`${exam.valid}/${exam.total}`"
        ></evaluation-card>
      </el-col>
    </el-row>
    <evaluation-empty v-if="!searchData || !searchData.length" />
    <pagination
      v-show="total > queryParams.pageSize"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      :page-size="20"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getEvaluationForStat } from "@/api/webApi/front";

export default {
  data() {
    return {
      total: 0,
      searchData: [],
      loading: true,
      // 查询参数
      routeParams: {},
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        //
        catalogId: "", // 分类 编码
        classId: "", // 班级
        evaluationId: "",
      },
    };
  },
  created() {
    this.routeParams = this.$route.query;
    this.queryParams.catalogId = this.routeParams.catalogId;
    this.queryParams.evaluationId = this.routeParams.evaluationId;
    this.handleQuery();
  },
  computed: {},
  methods: {
    detail(item) {
      if (!item.total) {
        this.msgInfo('无数据')
        return
      }
      const nextParams = {
        name: item.name,
        evaluationId: item.evaluationId,
        evaluationClassId: item.evaluationClassId,
        className: item.className
      };
      this.$router.push({
        path: "/idc/EvaluationDatabase/detailList",
        query: nextParams,
      });
    },
    // 选择图标
    selected(name) {
      this.form.icon = name;
    },
    /** 查询菜单列表 */
    getList() {
      this.loading = true;
      getEvaluationForStat(this.queryParams).then((rep) => {
        console.log("getEvaluationForStat rep =", rep);
        if (rep.code == 200 || rep.code == 0) {
          this.searchData = rep.rows;
          this.total = rep.total;
        } else {
          this.msgError(rep.msg || "getEvaluationForStat请求异常");
        }
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery(ctrlParams = {}) {
      this.queryParams.pageNum = 1;
      this.queryParams.classId = ctrlParams.clbum || "";
      this.getList();
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
