<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 };
        if (data.class && !data.clbum) return; // 选了年级没有选班级
        this.queryParams.pageNum = 1;
        this.getList();
      },
      detail(user) {
        this.$store.dispatch('settings/setStudent', user)
        this.$router.push({ name: "UserStatisticsInfo"});
      },
      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>
