<template>
  <div class="app-container">
    <form-search
      :searchformShow="{ clbum: '', class: '' }"
      :withoutSearchButton="true"
      ref="formSearch"
      @change="classGradeChange"
      @handleQuery="classGradeChange"
    ></form-search>
    <el-card
      v-if="dataList && dataList.length"
      class="box-card"
      style="margin-bottom: 30px"
    >
      <el-row>
        <el-col
          :span="99"
          v-for="(item, idx) in dataList"
          :key="idx"
          class="mb20 mt20 text-center"
        >
          <student-card
            @click.native="detail(item)"
            :name="item.customer && item.customer.name"
            :avatar="item.customer && item.customer.photo"
          ></student-card>
        </el-col>
      </el-row>
    </el-card>
    <evaluation-empty v-else />
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      :page-size="50"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getStudents } from "@/api/webApi/back";

export default {
  data() {
    return {
      total: 0,
      dataList: [],
      queryParams: { pageNum: 1, pageSize: 50 },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    classGradeChange(data) {
      this.queryParams = { ...this.queryParams, ...data };
      console.log(this.queryParams);
      if (data.class && !data.clbum) return; // 选了年级没有选班级
      this.queryParams.pageNum = 1;
      this.getList();
    },
    detail(user) {
      var className = this.$refs.formSearch.getClassName(user.classId);
      const params = {
        gradeId: user.customer.gradeId || this.queryParams.class,
        classId: user.classId,
        className: className,
        userId: user.id,
        customerCode: user.customerCode,
        name: user.customer.name,
        avatar: user.customer.photo,
      };
      if (this.$route.name == "Index") {
        //学生单次测评数据
        this.$router.push({ path: "/idc/student/index", query: params });
      } else if (this.$route.name == "Ranking") {
        this.$router.push({ path: "/idc/student/ranking", query: params });
      } else if (this.$route.name == "History") {
        this.$router.push({ path: "/idc/student/history", query: params });
      }
    },
    getList() {
      //if (!classId) return;
      getStudents({
        classId: this.queryParams.clbum,
        pageNum: this.queryParams.pageNum,
        pageSize: this.queryParams.pageSize,
      }).then((rep) => {
        console.log(
          "getStudents by classId[" + this.queryParams.clbum + "] rep=",
          rep
        );
        if (rep.code == 200 || rep.code == 0) {
          this.dataList = rep.rows || rep.data;
          this.total = rep.total || 0;
        } else {
          this.msgError(rep.msg || "getStudents请求异常");
        }
        this.loading = false;
      });
    },
  },
};
</script>

<style scoped>
.el-col-99 {
  width: 10%;
}
</style>
