<!-- 历史错题 -->
<template>
  <div class="page-container historyOfIncorrectQuestions-addPage">
    <div class="page-container-top-max-big-box">
      <p class="top-1-p">历史错题</p>
      <p class="top-2-p" @click="backPage()">返回</p>
    </div>
    <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="queryParamsData1">
          <el-cascader
            v-model="queryParams.queryParamsData1"
            :options="optionListA"
            :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="queryParamsData2">
          <el-select v-model="queryParams.queryParamsData2" placeholder="题型" style="width: 200px">
            <el-option
              v-for="dict in optionListB"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="" prop="queryParamsData3">
          <el-select v-model="queryParams.queryParamsData3" 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="queryParamsData4">
          <el-input
            maxLength="30"
            v-model="queryParams.queryParamsData4"
            placeholder="搜索名称"
            style="width: 200px"
          />
        </el-form-item>
        <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
        <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
        <p class="page-submit-common-style-button"
           style="float: right;"
           @click="tableButton(1)"
        >开始训练</p>
      </el-form>
    </div>
    <div class="page-content-box">
      <el-table class="table-box"  border :data="dataList">
        <el-table-column label="题干" prop="name"  show-overflow-tooltip/>
        <el-table-column label="题型" prop="content" width="200" show-overflow-tooltip/>
        <el-table-column label="难度" prop="content" width="200" show-overflow-tooltip/>
        <el-table-column label="做对次数" prop="content" width="200" show-overflow-tooltip/>
        <el-table-column label="做错次数" prop="content" width="200" show-overflow-tooltip/>
        <el-table-column label="操作" width="200" show-overflow-tooltip>
          <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)"
              >查看答案</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>
    <el-drawer
      size="40%"
      custom-class="examinationArrange-addPage-drawer"
      :append-to-body="true"
      :title="drawerTitle"
      ref="drawer"
      :visible.sync="drawer"
      direction="rtl">
      <answerKey v-if="drawer"></answerKey>
    </el-drawer>
  </div>
</template>

<script>
  //import { getDicts } from "@/api/commonality/noPermission";
  //import { systemUserSelect } from "@/api/commonality/permission";
  import { examElKnowledgePointTreeList, } from "@/api/safetyEducationExaminationNew/index";
  import answerKey from "@/views/safetyEducationExaminationNew/components/answerKey.vue";
  export default {
    name: 'addPage',
    components: {
      answerKey,
    },
    props: {
      propsData: {}
    },
    data() {
      return {
        //下拉列表数据
        optionListA: [],
        optionListB: [{value:'1',label:'单选'},{value:'2',label:'多选'},{value:'3',label:'判断'}],
        optionListC: [{value:"1",label:'简单'},{value:"2",label:'一般'},{value:"3",label:'较难'},{value:"4",label:'极难'}],
        queryParams: {
          page: 1,
          pageSize: 20,
          queryParamsData1: null,
          queryParamsData2: null,
          queryParamsData3: null,
          queryParamsData4: '',
        },
        //列表数据
        dataList:[{}],
        //数据数量
        total:0,
        //弹窗相关
        drawerTitle: '',
        drawerType: '',
        drawer: false,
      }
    },
    created() {

    },
    mounted() {
      this.initialize()
      this.examElKnowledgePointTreeList();
    },
    methods: {
      // 初始化
      initialize() {

      },
      // 返回按钮
      backPage() {
        this.$parent.tableButton(6)
      },
      // 提交按钮
      submitButton() {

      },
      tableButton(type){
        if(type == '1'){
          //开始训练
        }else if(type == 2){
          //查看答案
          this.$set(this, 'drawerTitle', '查看试题答案')
          this.$set(this, 'drawerType', 1)
          this.$set(this, 'drawer', true)
        }
      },
      //弹窗返回
      drawerReturnButton(){
        this.$refs.drawer.closeDrawer();
      },
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          queryParamsData1: null,
          queryParamsData2: null,
          queryParamsData3: null,
          queryParamsData4: '',
        });
        this.getList();
      },
      //获取数据列表
      getList(){

        let obj = JSON.parse(JSON.stringify(this.queryParams))
        getListFunction(obj).then(response => {

          this.$set(this,'dataList',response.data.records);
          this.$set(this,'total',response.data.total);
        });
      },
      examElKnowledgePointTreeList(){
        examElKnowledgePointTreeList({}).then(response => {
          const list = response.data || [];
          this.formatTreeData(list);
          this.$set(this, 'optionListA', list);
        });
      },
    }
  }
</script>

<style scoped lang="scss">
  .historyOfIncorrectQuestions-addPage {
    .content-box {
      flex: 1;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      padding: 20px;
    }
  }
</style>
