<!-- 练习统计 -->
<template>
  <div class="page-container practiceStatistics-addPage">
    <div class="page-container-top-max-big-box-shadow">
      <p class="top-1-p">练习统计</p>
      <p class="top-2-p" @click="backPage()">返回</p>
    </div>
    <div class="content-box">
      <div class="page-form-title-box">
        <el-form :model="queryParams" class="form-box" ref="queryForm"
                 :inline="true" style="width:100%;">
          <el-form-item label="" prop="deptId">
            <el-cascader
              style="width: 180px"
              v-model="queryParams.deptId"
              :options="optionListB"
              :props="{
                    emitPath:false,
                    checkStrictly: true,
                    value: 'deptId',
                    label: 'deptName',
                    children: 'child',
                  }"
              :show-all-levels="false"
              filterable
              placeholder="学院单位"
            ></el-cascader>
          </el-form-item>
          <el-form-item label="" prop="userType">
            <el-select v-model="queryParams.userType" placeholder="用户类别" style="width: 200px">
              <el-option
                v-for="dict in optionListC"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="keyword">
            <el-input
              maxLength="30"
              v-model="queryParams.keyword"
              placeholder="姓名/学工号"
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="" prop="state">
            <el-date-picker
              :clearable="false"
              v-model="dateRange"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box"  border :data="dataList">
          <el-table-column label="姓名" prop="userName"  show-overflow-tooltip/>
          <el-table-column label="学工号" prop="account" width="200" show-overflow-tooltip/>
          <el-table-column label="学院单位" prop="deptName" width="200" show-overflow-tooltip/>
          <el-table-column label="练习时间" prop="lastPracticeTime" width="200" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.lastPracticeTime,"{y}-{m}-{d} {h}:{i}") }}</span>
            </template>
          </el-table-column>
          <el-table-column label="刷题总数" prop="totalAnswerCount" width="200" show-overflow-tooltip/>
          <el-table-column label="答对题数" prop="correctAnswerCount" width="200" show-overflow-tooltip/>
          <el-table-column label="整体正确率%" prop="correctRate" width="200" show-overflow-tooltip/>
          <el-table-column label="积分" prop="points" width="200" show-overflow-tooltip/>
        </el-table>
        <pagination :page-sizes="[20, 30, 40, 50]"
                    v-show="total>0"
                    :total="total"
                    :page.sync="queryParams.page"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
    </div>
  </div>
</template>

<script>
  //import { getDicts } from "@/api/commonality/noPermission";
  //import { systemUserSelect } from "@/api/commonality/permission";
  import {
    examElPracticeStatDetail,
    systemUserGetCategories,systemDeptCurrentDept,
  } from "@/api/safetyEducationExaminationNew/index";
  export default {
    name: 'addPage',
    props: {
      propsData: {}
    },
    data() {
      return {
        //下拉列表数据
        optionListB:[],
        optionListC:[],
        //查询条件
        queryParams:{
          page:1,
          pageSize:20,
          deptId :null,
          userType:null,
          keyword:'',
        },
        //时间数据
        dateRange:[],
        //列表数据
        dataList:[],
        //数据数量
        total:0,
      }
    },
    created() {

    },
    mounted() {
      this.getList()
      this.systemDeptCurrentDept()
      this.systemUserGetCategories()
    },
    methods: {
      // 返回按钮
      backPage() {
        this.$parent.tableButton(6)
      },
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'dateRange',[])
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          deptId :null,
          userType:null,
          keyword:'',
        });
        this.getList();
      },
      //获取数据列表
      getList(){
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        obj.knowledgePointId = this.propsData.knowledgePointId
        if(this.dateRange[0]){
          obj.startTime = this.dateRange[0]+'T00:00:00'
          obj.endTime = this.dateRange[1]+'T23:59:59'
        }else{
          obj.startTime = "";
          obj.endTime = "";
        }
        examElPracticeStatDetail(obj).then(response => {
          this.$set(this,'dataList',response.data.records);
          this.$set(this,'total',response.data.total);
        });
      },
      //用户类别
      systemUserGetCategories(){
        systemUserGetCategories({}).then(response => {
          this.$set(this,'optionListC',response.data);
        });
      },
      //学院列表
      systemDeptCurrentDept(){
        systemDeptCurrentDept({}).then(response => {
          const list = response.data || [];
          this.formatTreeData(list);
          this.$set(this,'optionListB',list);
        });
      },
    }
  }
</script>

<style scoped lang="scss">
  .practiceStatistics-addPage {
    flex:1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    .page-container-top-max-big-box-shadow{
      margin:0;
      box-shadow:none;
      border-bottom:1px solid #dedede;
      border-radius:0;
    }
    .content-box {
      flex: 1;
      display: flex;
      flex-direction: column;
      overflow: hidden;
    }
  }
</style>
