<template>
  <div class="app-container">
    <form-search
      :searchformShow="searchformShow"
      @handleQuery="handleQuery"
    ></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"
          :proportion="`${exam.valid}/${exam.total}`"
        ></evaluation-card>
      </el-col>
    </el-row>
    <evaluation-empty v-if="total==0" />
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      :page-size="20"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getEvaluationForStat } from "@/api/webApi/front";
import { mapGetters } from "vuex";
export default {
  data() {
    return {
      total: 0,
      searchData: [],
      loading: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        //
        catalogId: "", // 分类 编码
        classId: "", // 班级
        customerCode: "", // 学生编号
        gradeId: "", // 年级
        subjectId: "", // 科目
        termId: "", // 学期
        typeId: "", // 类型 编码
      },
      searchformShow: {},
    };
  },
  created() {
    this.searchformShow = {
      class: "",
      clbum: "",
      userSubject: "",
      gradeid: "",
      semester: "",
      exam: "",
    };
    this.handleQuery();
  },
  computed: {
    ...mapGetters(["isFrontStudent"]),
  },
  methods: {
    detail(item) {
      const nextParams = {
        evaluationId: item.evaluationId,
        evaluationClassId: item.evaluationClassId,
        evaluationName: item.name,
      };
      this.$router.push({
        path: "/idc/reviewHistory/userList",
        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) {
          if (this.queryParams.pageNum == 1)
            this.searchData = rep.rows || rep.data || [];
          else this.searchData.concat(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.queryParams.subjectId = ctrlParams.userSubject || "";
      this.queryParams.gradeId = ctrlParams.gradeid || "";
      this.queryParams.termId = ctrlParams.semester || "";
      this.queryParams.typeId = ctrlParams.exam || "";
      this.getList();
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
