<!-- 刷题练习 -->
<template>
  <div class="app-container practiceSolvingProblems">
    <div class="page-container practiceSolvingProblemsPage" v-if="pageType === 1">
      <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="knowledgePointId">
            <el-cascader
              v-model="queryParams.knowledgePointId"
              :options="optionListC"
              :props="{
                emitPath:false,
                checkStrictly: true,
                value: 'id',
                label: 'knowledgePointName',
                children: 'children',
              }"
              style="width: 180px"
              :show-all-levels="false"
              filterable
              placeholder="知识点"
            ></el-cascader>
          </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="knowledgePointName"  show-overflow-tooltip/>
          <el-table-column label="试题总数" prop="totalQuestionCount" width="200" show-overflow-tooltip/>
          <el-table-column label="练习人数" prop="practiceUserCount" width="200" show-overflow-tooltip/>
          <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="操作" width="200" show-overflow-tooltip v-if="tableButtonType">
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p"
                   @click="tableButton(2,scope.row)"
                   v-hasPermiRouter="['exam:elPracticeStat:detail']"
                >练习统计</p>
                <p class="table-button-null"></p>
              </div>
            </template>
          </el-table-column>
        </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>
    <practiceStatistics :propsData="propsData" v-if="pageType === 2"></practiceStatistics>
  </div>
</template>
<script>
  //import { getDicts } from "@/api/commonality/noPermission";
  //import { systemUserSelect } from "@/api/commonality/permission";
  //import { getInfo } from "@/api/basicsModules/index";
  import practiceStatistics from "./practiceStatistics.vue";
  import {
    examElPracticeStatPage,
    examElKnowledgePointTreeList,systemDeptCurrentDept,
  } from "@/api/safetyEducationExaminationNew/index";
  export default {
    name: 'index',
    components: {
      practiceStatistics
    },
    data () {
      return {
        tableButtonType:this.hasPermiDom(['exam:elPracticeStat:detail',]),
        //页面状态
        pageType:1,
        //下拉列表数据
        optionListB:[],
        optionListC:[],
        //查询条件
        queryParams:{
          page:1,
          pageSize:20,
          queryParamsData1:"",
          deptId :null,
        },
        //时间数据
        dateRange:[],
        //列表数据
        dataList:[],
        //数据数量
        total:0,
        //组件传参
        propsData:{},
      }
    },
    created () {

    },
    mounted () {
      this.systemDeptCurrentDept();
      this.examElKnowledgePointTreeList();
      this.getList();
    },
    methods: {
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'dateRange',[])
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          queryParamsData1:"",
          deptId :null,
        });
        this.getList();
      },
      //获取数据列表
      getList(){
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        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 = "";
        }
        examElPracticeStatPage(obj).then(response => {
          this.$set(this,'dataList',response.data.records);
          this.$set(this,'total',response.data.total);
        });
      },
      //操作按钮
      tableButton(type,row){
        let self = this;
        if(type == 2){
          //详情
          this.$set(this,'pageType',2);
          let obj = JSON.parse(JSON.stringify(row))
          this.$set(this,'propsData',obj);
        }else if(type == 6){
          //返回并刷新
          this.$set(this,'pageType',1);
          this.getList();
        }
      },
      //学院列表
      systemDeptCurrentDept(){
        systemDeptCurrentDept({}).then(response => {
          const list = response.data || [];
          this.formatTreeData(list);
          this.$set(this,'optionListB',list);
        });
      },
      //知识点
      examElKnowledgePointTreeList(){
        examElKnowledgePointTreeList({ dataScope:2 }).then(response => {
          const list = response.data || [];
          this.formatTreeData(list);
          this.$set(this, 'optionListC', list);
        });
      },
    },
  }
</script>
<style scoped lang="scss">
  .practiceSolvingProblems{
    .practiceSolvingProblemsPage{

    }
  }
</style>
