<template>
  <div class="app-container">
    <el-card class="box-card" style="margin-bottom: 30px">
      <el-row :gutter="24">
        <el-col :span="16">
          <div
            style="
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
              padding-right: 20px;
            "
          >
            {{ user.name }}{{ currentSubjectName }}累计错题排名统计表
          </div>
        </el-col>
        <el-col :span="8" style="text-align: right">
          <el-button @click="$router.go(-1)" size="small" round>返回</el-button>
        </el-col>
      </el-row>
    </el-card>
    <form-search
      :searchformShow="searchFormShow"
      :validateRules="rules"
      ref="searchForm"
      @handleQuery="handleQuery"
    ></form-search>

    <el-table v-loading="loading" :data="dataList" style="width: 100%">
      <el-table-column label="序号" type="index" align="center" width="100" />
      <el-table-column label="知识点" prop="knowledgeName" align="center" />
      <el-table-column label="次数" prop="wrongCount" align="center" />
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button
            type="text"
            icon="el-icon-view"
            @click="detail(scope.$index)"
            >查看详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      :page-size="20"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getStudentKnownledgeStats } from "@/api/webApi/front";
import { getDefaultDateRange } from "@/utils/index";

export default {
  data() {
    return {
      total: 0,
      queryParams: { pageNum: 1, pageSize: 20 },
      loading: false,
      dataList: [],
      searchFormShow: {},
      rules: {
        userSubject: [{ required: true, message: "请选择科目", trigger: "blur" }],
        time: [{ required: true, message: " ", trigger: "blur" }],
      },
      user: {},
      routeParams: {},
      currentSubjectName: ''
    };
  },
  created() {
    this.routeParams = this.$route.query;
    this.user.id = this.routeParams.userId;
    this.user.name = this.routeParams.name;
    this.user.img = this.routeParams.avatar;

    this.searchFormShow = { userSubject: "", time: getDefaultDateRange() };
  },
  computed: {

  },
  methods: {
    detail(idx) {
      //const knownledgeId = this.dataList[idx].knownledgeId;
      const knownledgeName = this.dataList[idx].knowledgeName || '';
      const className = this.routeParams.className;
      const nextParams = {
        ...this.queryParams,
        //knownledgeId: knownledgeId,
        knownledgeName: knownledgeName,
        className: className,
        studentName: this.user.name,
      };
      const nextPath = "/idc/mistakes/detail";
      this.$router.push({ path: nextPath, query: nextParams });
    },
    handleQuery(ctrlParams = {}) {
      this.currentSubjectName = this.$refs.searchForm.getSubjectName(ctrlParams.subjectid);

      this.queryParams.beginTime = (ctrlParams.time && ctrlParams.time[0]) || this.searchFormShow.time[0];
      this.queryParams.endTime = (ctrlParams.time && ctrlParams.time[1]) || this.searchFormShow.time[1];
      this.queryParams.subjectId = ctrlParams.userSubject || this.searchFormShow.userSubject;
      this.queryParams.classId = this.routeParams.classId;
      this.queryParams.customerCode = this.routeParams.customerCode;
      console.log("valid parmas", this.queryParams);
      this.getList();
    },
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    getList() {
      this.loading = true;
      getStudentKnownledgeStats(this.queryParams).then((rep) => {
        if (rep.code == 200 || rep.code == 0) {
          this.dataList = rep.rows || rep.data;
          this.total = rep.total || 0;
        } else {
          this.msgError(rep.msg || "getStudentKnownledgeStats请求异常");
        }
        this.loading = false;
      });
    },
  },
};
</script>

<style>
</style>
