<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="filter-group">
        <div class="filter-lable"> 试卷名称：</div>
        <el-input v-model="KEYWORDS" placeholder="搜索" style="width: 200px;"/>
      </div>
      <!--      <div class="filter-group">-->
      <!--        <div class="filter-lable"> 培训行业类型：</div>-->
      <!--        <SelectTree ref="keyHyRef" :options="dicListMap.trainDicList" :props="defaultProps" v-model="TRAINTYPE" placeholder="请选择培训行业类型" />-->
      <!--      </div>-->
      <div class="filter-group">
        <div class="filter-lable"> 岗位培训类型：</div>
        <SelectTree ref="keyGwRef" :options="dicListMap.postDicList" :props="defaultProps" v-model="POSTTYPE" placeholder="请选择岗位培训类型" />
      </div>
      <el-button v-waves class="ml-10" type="primary" icon="el-icon-search" @click="getQuery">
        搜索
      </el-button>
      <el-button v-waves type="success" icon="el-icon-refresh" @click="goKeyReset">
        重置
      </el-button>
    </div>
    <el-table
      v-loading="listLoading"
      ref="multipleTable"
      :data="varList"
      :row-key="getRowKey"
      :header-cell-style="{
        'font-weight': 'bold',
        'color': '#000'
      }"
      tooltip-effect="dark"
      border
      fit
      highlight-current-row
    >
      <el-table-column
        :reserve-selection="true"
        type="selection"
        width="55"
        align="center"/>
      <el-table-column type="index" label="序号" width="50" align="center" />
      <el-table-column prop="EXAMNAME" label="试卷名称" />
      <el-table-column prop="post_type_name" label="培训行业类型" />
      <el-table-column prop="train_type_name" label="岗位培训类型" align="center" />
      <el-table-column prop="ANSWERSHEETTIME" label="试题数" align="center" >
        <template slot-scope="{row}">
          <template>
            <div>{{ (Number(row.DUOXUANTICOUNT)) + (Number(row.DANYUANTICOUNT))+ (Number(row.PANDUITICOUNT)) }}</div>
          </template>
        </template>
      </el-table-column>
      <el-table-column prop="EXAMSCORE" label="总分数" align="center" />
      <el-table-column prop="PASSSCORE" label="及格分数" align="center" />
      <el-table-column prop="STATE" label="试卷状态" align="center" width="100">
        <template slot-scope="{row}">
          <template v-if="row.STATE =='0'">启用</template>
          <template v-if="row.STATE =='1'"><span class="color-red">禁用</span></template>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="300">
        <template slot-scope="{row}">
          <el-button class="light-blue-btn" icon="el-icon-view" size="mini" @click="handleShowExam(row.STAGEEXAMPAPERINPUT_ID)">查看试卷</el-button>
          <!--          <el-button v-if="row.EXAMSTATE == '0'" v-show="edit" type="primary" icon="el-icon-edit" size="mini" @click="handleEdit(row.STAGEEXAMPAPER_ID)">编辑</el-button>-->
          <el-button v-show="edit && row.STATE == 0" type="info" icon="el-icon-switch-button" size="mini" @click="handleEditState(row.STAGEEXAMPAPERINPUT_ID,'1')">禁用</el-button>
          <el-button v-show="edit && row.STATE == 1" class="green-btn" icon="el-icon-switch-button" size="mini" @click="handleEditState(row.STAGEEXAMPAPERINPUT_ID,'0')">启用</el-button>
          <el-button v-if="row.EXAMSTATE == '0'" v-show="del" type="danger" icon="el-icon-delete" size="mini" @click="handleDelete(row.STAGEEXAMPAPERINPUT_ID)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="page-btn-group">
      <div>
        <el-button v-show="add" type="primary" icon="el-icon-plus" @click="handleAdd">新建试卷</el-button>
      </div>
      <pagination :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    </div>

    <el-dialog :visible.sync="dialogFormEdit" :title="dialogType==='edit'?'修改':'新增'" width="600px">
      <el-form ref="form" :rules="rules" :model="form" label-width="110px" style="width: 500px;">
        <el-form-item label="试卷名称" prop="EXAMNAME">
          <el-input id="EXAMNAME" ref="EXAMNAME" v-model="form.EXAMNAME" maxlength="255" placeholder="这里输入试卷名称..." title="试卷名称"/>
        </el-form-item>
        <el-form-item label="培训行业类型" prop="TRAINTYPE">
          <SelectTree ref="pxTree" :options="dicListMap.trainDicList" :props="defaultProps" v-model="form.TRAINTYPE" placeholder="请选择" style="width:100%"/>
        </el-form-item>
        <el-form-item label="岗位培训类型" prop="POSTTYPE">
          <SelectTree ref="keyGwRef2" :options="dicListMap.postDicList" :props="defaultProps" v-model="form.POSTTYPE" placeholder="请选择" style="width: 100%;" />
        </el-form-item>
        <el-form-item label="总分数" prop="EXAMSCORE">
          <el-input id="EXAMSCORE" ref="EXAMSCORE" v-model="form.EXAMSCORE" type="number" maxlength="255" placeholder="这里输入总分数..." title="总分数"/>
        </el-form-item>
        <el-form-item label="合格分数" prop="PASSSCORE">
          <el-input id="PASSSCORE" ref="PASSSCORE" :min="0" v-model="form.PASSSCORE" oninput="if(value<0)value=0" type="number" maxlength="255" placeholder="这里输入合格分数..." title="合格分数"/>
        </el-form-item>
        <el-form-item label="单选题数" prop="DANYUANTICOUNT">
          <el-input id="DANYUANTICOUNT" ref="DANYUANTICOUNT" :min="0" :disabled="questionType.danxuanDis" v-model="form.DANYUANTICOUNT" oninput="if(value<0)value=0" type="number" maxlength="11" placeholder="这里输入单选题数..." title="单选题数">
            <template slot="append">可选题数：{{ questionType.danxuanCount }}</template>
          </el-input>
        </el-form-item>
        <el-form-item label="单选分数" prop="DANXUANTINUMBER">
          <el-input
            id="DANXUANTINUMBER"
            ref="DANXUANTINUMBER"
            :disabled="questionType.danxuanDis"
            :min="0"
            v-model="form.DANXUANTINUMBER"
            onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"
            onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'0')}else{this.value=this.value.replace(/\D/g,'')}"
            oninput="value=value.replace(/[^\d]/g,'')"
            type="number"
            maxlength="11"
            placeholder="这里输入单选分数..."
            title="单选分数"/>
        </el-form-item>
        <el-form-item label="多选题数" prop="DUOXUANTICOUNT">
          <div>
            <el-input id="DUOXUANTICOUNT" ref="DUOXUANTICOUNT" :disabled="questionType.duoxuanDis" v-model="form.DUOXUANTICOUNT" oninput="if(value<0)value=0" type="number" maxlength="11" placeholder="这里输入多选题数..." title="多选题数">
              <template slot="append">可选题数：{{ questionType.duoxuanCount }}</template>
            </el-input>
          </div>
        </el-form-item>
        <el-form-item label="多选分数" prop="DUOXUANTINUMBER">
          <el-input
            id="DUOXUANTINUMBER"
            ref="DUOXUANTINUMBER"
            :disabled="questionType.duoxuanDis"
            :min="0"
            v-model="form.DUOXUANTINUMBER"
            onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"
            onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'0')}else{this.value=this.value.replace(/\D/g,'')}"
            oninput="value=value.replace(/[^\d]/g,'')"
            type="number"
            maxlength="11"
            placeholder="这里输入多选分数..."
            title="多选分数"/>
        </el-form-item>
        <el-form-item label="判断题数" prop="PANDUITICOUNT">
          <el-input id="PANDUITICOUNT" ref="PANDUITICOUNT" :min="0" :disabled="questionType.panduanDis" v-model="form.PANDUITICOUNT" oninput="if(value<0)value=0" type="number" maxlength="11" placeholder="这里输入判断题数..." title="判断题数">
            <template slot="append">可选题数：{{ questionType.panduanCount }}</template>
          </el-input>
        </el-form-item>
        <el-form-item label="判断分数" prop="PANDUITINUMBER">
          <el-input
            id="PANDUITINUMBER"
            ref="PANDUITINUMBER"
            :min="0"
            :disabled="questionType.panduanDis"
            v-model="form.PANDUITINUMBER"
            onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"
            onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'0')}else{this.value=this.value.replace(/\D/g,'')}"
            oninput="value=value.replace(/[^\d]/g,'')"
            type="number"
            maxlength="11"
            placeholder="这里输入判断分数..."
            title="判断分数"/>
        </el-form-item>
        <el-form-item v-if="sumFraction != form.EXAMSCORE || sumFraction ==0" label="" prop="">
          <div style="margin-left:20px;line-height:1.6">
            <div style="color: red;font-size: 12px">* 习题分数不等于合格分数</div>
          </div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormEdit = false">取 消</el-button>
        <el-button :disabled ="sumFraction != form.EXAMSCORE || sumFraction ==0" type="primary" @click="confirm" >确 定</el-button>
      </div>
    </el-dialog>

    <!--<el-dialog v-if="dialogExamShow" :visible.sync="dialogExamShow" title="阶考试卷" width="90%">
      <PaperInfo :paperid="STAGEEXAMPAPER_ID" :cascaderdata = "cascaderData" :coursewarelist = "coursewareList" />
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogExamShow = false">取 消</el-button>
      </div>
    </el-dialog>-->
  </div>
</template>
<script>
import Pagination from '@/components/Pagination' // 通过 el-pagination二次打包
import { requestFN } from '@/utils/request'
import waves from '@/directive/waves' // waves directive
import SelectTree from '@/components/SelectTree'
import PaperInfo from './info'
export default {
  components: { Pagination, SelectTree, PaperInfo },
  directives: { waves },
  data() {
    var totalQuesFraction = (rule, value, callback) => {
      // rule : field: "PASSSCORE"  fullField: "PASSSCORE"   type: "string"
      // value : 内容
      if (value) {
        const valueId = rule.field //  input ID

        const EXAMSCORE = this.form.EXAMSCORE ? Number(this.form.EXAMSCORE) : 0 // 试卷分数

        const DANYUANTICOUNT = this.form.DANYUANTICOUNT ? Number(this.form.DANYUANTICOUNT) : 0
        const DANXUANTINUMBER = this.form.DANXUANTINUMBER ? Number(this.form.DANXUANTINUMBER) : 0

        const DUOXUANTICOUNT = this.form.DUOXUANTICOUNT ? Number(this.form.DUOXUANTICOUNT) : 0
        const DUOXUANTINUMBER = this.form.DUOXUANTINUMBER ? Number(this.form.DUOXUANTINUMBER) : 0

        const PANDUITICOUNT = this.form.PANDUITICOUNT ? Number(this.form.PANDUITICOUNT) : 0
        const PANDUITINUMBER = this.form.PANDUITINUMBER ? Number(this.form.PANDUITINUMBER) : 0
        /**
         *  判断是否超出可选题数
         * 1.判断 分数和 是否和总分数相等
         */
        if (valueId == 'DANYUANTICOUNT') {
          if (DANYUANTICOUNT > this.questionType.danxuanCount) {
            callback(new Error('习题数量大于可选题数'))
          }
        }
        if (valueId == 'DUOXUANTICOUNT') {
          if (DUOXUANTICOUNT > this.questionType.duoxuanCount) {
            callback(new Error('习题数量大于可选题数'))
          }
        }
        if (valueId == 'PANDUITICOUNT') {
          if (PANDUITICOUNT > this.questionType.panduanCount) {
            callback(new Error('习题数量大于可选题数'))
          }
        }
        const sumFraction = (DANYUANTICOUNT * DANXUANTINUMBER) + (DUOXUANTICOUNT * DUOXUANTINUMBER) + (PANDUITICOUNT * PANDUITINUMBER)
        this.sumFraction = sumFraction
        if (sumFraction > EXAMSCORE) {
          callback(new Error('习题分数总计大于试卷分数'))
        } else if (sumFraction == EXAMSCORE) {
          this.form.DANYUANTICOUNT = this.form.DANYUANTICOUNT ? Number(this.form.DANYUANTICOUNT) : 0
          this.form.DANXUANTINUMBER = this.form.DANXUANTINUMBER ? Number(this.form.DANXUANTINUMBER) : 0

          this.form.DUOXUANTICOUNT = this.form.DUOXUANTICOUNT ? Number(this.form.DUOXUANTICOUNT) : 0
          this.form.DUOXUANTINUMBER = this.form.DUOXUANTINUMBER ? Number(this.form.DUOXUANTINUMBER) : 0

          this.form.PANDUITICOUNT = this.form.PANDUITICOUNT ? Number(this.form.PANDUITICOUNT) : 0
          this.form.PANDUITINUMBER = this.form.PANDUITINUMBER ? Number(this.form.PANDUITINUMBER) : 0
        }
        callback()
      } else {
        callback()
      }
    }
    var judgeFraction = (rule, value, callback) => { // 判断合格分数是否大于试卷分数
      if (value) {
        // form.EXAMSCORE  form.PASSSCORE
        const EXAMSCORE = this.form.EXAMSCORE ? Number(this.form.EXAMSCORE) : 0 // 试卷分数
        const PASSSCORE = this.form.PASSSCORE ? Number(this.form.PASSSCORE) : 0 // 合格分数
        if (PASSSCORE > EXAMSCORE) {
          callback(new Error('合格分数大于试卷分数'))
        } else {
          callback()
        }
      } else {
        callback()
      }
    }
    return {
      listLoading: true,
      add: false,
      del: false,
      edit: false,
      listQuery: {
        page: 1,
        limit: 10
      },
      total: 0,
      config: config,
      KEYWORDS: '',
      TRAINTYPE: '',
      POSTTYPE: '',
      varList: [],
      pd: [],
      defaultProps: {
        value: 'id',
        children: 'nodes',
        label: 'name'
      },
      AnswerSheetTimeOptions: [{
        value: '30',
        label: '30分钟'
      }, {
        value: '60',
        label: '60分钟'
      }, {
        value: '90',
        label: '90分钟'
      }],
      QuestionNumOptions: [
        { value: '10', label: '10', disabled: true },
        { value: '20', label: '20', disabled: true },
        { value: '50', label: '50', disabled: true },
        { value: '100', label: '100', disabled: true }
      ],
      props: { multiple: true, emitPath: false },
      cascaderData: [],
      coursewareList: [],
      form: {
        CURRICULUMID: '', // 课程ID
        EXAMNAME: '', // 试卷名称
        EXAMTIME: '', // 考试时间（开始时间）
        ANSWERSHEETTIME: '', // 答卷时间（持续时间）
        EXAMSCORE: 100, // 试卷分数
        CURRICULUMUSERS: '', // 适用人员
        COURSEWARES: '', // 课件范围
        QUESTIONNUM: '', // 试题数量（10、20、50、100）
        PASSSCORE: '',
        DUOXUANTICOUNT: '',
        DUOXUANTINUMBER: '',
        DANYUANTICOUNT: '',
        DANXUANTINUMBER: '',
        PANDUITICOUNT: '',
        PANDUITINUMBER: '',
        TRAINTYPE: '',
        POSTTYPE: ''
        // EXAMSTATE: ''// 试卷状态
      },
      multipleSelectionAll: [], // 所有选中的数据包含跨页数据
      multipleSelection: [], // 当前页选中的数据
      dialogFormEdit: false,
      dialogExamShow: false,
      STAGEEXAMPAPER_ID: '',
      dialogType: 'add',
      LearnerCategoryList: [],
      rules: {
        EXAMNAME: [{ required: true, message: '试卷名称不能为空', trigger: 'blur' }],
        // TRAINTYPE: [{ required: true, message: '培训行业类型不能为空', trigger: 'blur' }],
        POSTTYPE: [{ required: true, message: '岗位培训类型不能为空', trigger: 'blur' }],
        EXAMSCORE: [{ required: true, message: '总分数不能为空', trigger: 'blur' }, { validator: judgeFraction, trigger: 'blur' }],
        PASSSCORE: [{ required: true, message: '合格分数不能为空', trigger: 'blur' }, { validator: judgeFraction, trigger: 'blur' }],
        DUOXUANTICOUNT: [{ required: true, message: '多选题数不能为空', trigger: 'blur' }, { validator: totalQuesFraction, trigger: 'blur' }],
        DUOXUANTINUMBER: [{ required: true, message: '多选分数不能为空', trigger: 'blur' }, { validator: totalQuesFraction, trigger: 'blur' }],
        DANYUANTICOUNT: [{ required: true, message: '单选题数不能为空', trigger: 'blur' }, { validator: totalQuesFraction, trigger: 'blur' }],
        DANXUANTINUMBER: [{ required: true, message: '单选分数不能为空', trigger: 'blur' }, { validator: totalQuesFraction, trigger: 'blur' }],
        PANDUITICOUNT: [{ required: true, message: '判断题数不能为空', trigger: 'blur' }, { validator: totalQuesFraction, trigger: 'blur' }],
        PANDUITINUMBER: [{ required: true, message: '判断分数不能为空', trigger: 'blur' }, { validator: totalQuesFraction, trigger: 'blur' }]
      },
      dicListMap: {
        outlineDicList: [],
        trainDicList: [],
        postDicList: []
      },
      questionType: {
        danxuanCount: 0,
        duoxuanCount: 0,
        panduanCount: 0,
        duoxuanDis: false,
        danxuanDis: false,
        panduanDis: false
      },
      sumFraction: 0 // 习题总分数
    }
  },
  watch: {
    'form.POSTTYPE': {
      handler() {
        this.getCountByQuestionType()
      }
    },
    'form.TRAINTYPE': {
      handler() {
        this.getCountByQuestionType()
      }
    }
  },
  created() {
    this.getDict()
    this.getTreeList()
    this.getList(this.ROLE_ID)
  },
  methods: {
    getRowKey(row) {
      return row.STAGEEXAMPAPER_ID
    },
    // 搜索
    getQuery() {
      this.$refs.multipleTable.clearSelection()
      this.getList()
    },
    goKeyReset() {
      this.KEYWORDS = ''
      this.TRAINTYPE = ''
      this.POSTTYPE = ''
      this.$refs.keyGwRef.clearHandle()
      this.getList()
    },
    // 获取列表
    getList() {
      this.listLoading = true
      requestFN(
        '/stageexampaperinput/list?showCount=' + this.listQuery.limit + '&currentPage=' + this.listQuery.page,
        {
          KEYWORDS: this.KEYWORDS,
          TRAINTYPE: this.TRAINTYPE,
          POSTTYPE: this.POSTTYPE
        }
      ).then((data) => {
        this.listLoading = false
        this.varList = data.varList
        this.total = data.page.totalResult
        this.hasButton()
        this.pd = data.pd
      }).catch((e) => {
        this.listLoading = false
      })
    },
    // 添加
    handleAdd() {
      this.$refs.form && this.$refs.form.clearValidate()
      this.dialogType = 'add'
      this.resetForm()
      this.dialogFormEdit = true
    },
    // 修改
    handleEdit(ID) {
      this.dialogType = 'edit'
      requestFN(
        '/stageexampaperinput/goEdit',
        {
          STAGEEXAMPAPER_ID: ID
        }
      ).then((data) => {
        this.form = Object.assign({}, data.pd) // copy obj
        this.form.CURRICULUMUSERS = this.form.CURRICULUMUSERS.split(',')
        this.form.COURSEWARES = this.form.COURSEWARES.split(',')
        this.getQuestionNumOptions()
        this.dialogFormEdit = true
      }).catch((e) => {
        this.listLoading = false
      })
    },
    getQuestionNumOptions() {
      if (this.form.COURSEWARES.length == 0) {
        return false
      }
      requestFN(
        '/question/countByStageExamCourseware',
        {
          COURSEWARES: this.form.COURSEWARES.join(',')
        }
      ).then((data) => {
        this.QuestionNumOptions = [
          { value: '10', label: '10' },
          { value: '20', label: '20' },
          { value: '50', label: '50' },
          { value: '100', label: '100' }
        ]
        if (data.pd.DATACOUNT < 10) {
          this.QuestionNumOptions = [
            { value: '10', label: '10', disabled: true },
            { value: '20', label: '20', disabled: true },
            { value: '50', label: '50', disabled: true },
            { value: '100', label: '100', disabled: true }
          ]
        } else if (data.pd.DATACOUNT < 20) {
          this.QuestionNumOptions = [
            { value: '10', label: '10' },
            { value: '20', label: '20', disabled: true },
            { value: '50', label: '50', disabled: true },
            { value: '100', label: '100', disabled: true }
          ]
        } else if (data.pd.DATACOUNT < 50) {
          this.QuestionNumOptions = [
            { value: '10', label: '10' },
            { value: '20', label: '20' },
            { value: '50', label: '50', disabled: true },
            { value: '100', label: '100', disabled: true }
          ]
        } else if (data.pd.DATACOUNT < 100) {
          this.QuestionNumOptions = [
            { value: '10', label: '10' },
            { value: '20', label: '20' },
            { value: '50', label: '50' },
            { value: '100', label: '100', disabled: true }
          ]
        }
      }).catch((e) => {
      })
    },
    // 保存
    confirm() {
      this.$refs.form.validate(valid => {
        if (valid) {
          // 计算分数
          const duoxuan = Number(this.form.DUOXUANTICOUNT) * Number(this.form.DUOXUANTINUMBER)
          const danxuan = Number(this.form.DANYUANTICOUNT) * Number(this.form.DANXUANTINUMBER)
          const pandun = Number(this.form.PANDUITICOUNT) * Number(this.form.PANDUITINUMBER)
          const hege = Number(this.form.EXAMSCORE)
          const jige = Number(this.form.PASSSCORE)
          if (hege != (duoxuan + danxuan + pandun)) {
            this.$message.warning('总分数与选择考试题目分数不相等，请重新选择分数')
            return false
          }
          if (hege < jige) {
            this.$message.warning('总分数小于合格分数，请重新填写')
            return false
          }
          // this.form.CURRICULUMUSERS = this.form.CURRICULUMUSERS.join(',')
          // this.form.COURSEWARES = this.form.COURSEWARES.join(',')
          this.listLoading = true
          requestFN(
            '/stageexampaperinput/' + this.dialogType,
            this.form
          ).then((data) => {
            this.listLoading = false
            this.dialogFormEdit = false
            this.getList()
          }).catch((e) => {
            this.listLoading = false
          })
        } else {
          return false
        }
      })
    },
    handleShowExam(ExamId) {
      // this.STAGEEXAMPAPER_ID = ExamId
      // this.dialogExamShow = true
      this.$parent.STAGEEXAMPAPERINPUT_ID = ExamId
      this.$parent.activeName = 'PaperInfo'
    },
    handleDelete(id) {
      this.$confirm('确定要删除该试卷吗?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.listLoading = true
        requestFN(
          '/stageexampaperinput/delete',
          {
            STAGEEXAMPAPERINPUT_ID: id
          }
        ).then(() => {
          this.$message({
            message: '删除成功',
            type: 'success'
          })
          this.listLoading = false
          this.dialogExamShow = false
          this.varList = []
          this.listQuery.page = 1
          this.getList()
        }).catch((e) => {
          this.listLoading = false
        })
      }).catch(() => {
      })
    },
    getTreeList() {
      requestFN(
        '/user/listCascader',
        {}
      ).then((data) => {
        this.cascaderData = JSON.parse(data.CascaderNodes)
      }).catch((e) => {
      })
    },
    // 判断按钮权限，用于是否显示按钮
    hasButton: function() {
      var keys = 'stageexampaper:add,stageexampaper:del,stageexampaper:edit,toExcel'
      requestFN(
        '/head/hasButton',
        {
          keys: keys
        }
      ).then((data) => {
        this.add = data.stageexampaperfhadminadd		// 新增权限
        this.del = data.stageexampaperfhadmindel		// 删除权限
        this.edit = data.stageexampaperfhadminedit	// 修改权限
      }).catch((e) => {
        this.listLoading = false
      })
    },
    // 获取数据字典数据
    getDict: function() {
      requestFN(
        '/dictionaries/getLevels',
        {
          DICTIONARIES_ID: '532282f9c48346b8b646531909c739df'
        }
      ).then((data) => {
        this.LearnerCategoryList = data.list
      }).catch((e) => {
      })
      requestFN(
        '/datacourseware/getAllCourseware',
        {}
      ).then((data) => {
        this.coursewareList = data.list
      }).catch((e) => {

      })
      requestFN(
        '/dictionaries/listAllDictToParId',
        {
          parentId: '052369aa22d242118236cde52d0c67ea'
        }
      ).then((data) => {
        // this.dicListMap.trainDicList = data.list
        this.dicListMap.trainDicList = JSON.parse(data.zTreeNodes)
      }).catch((e) => {
      })
      requestFN(
        '/dictionaries/listAllDictToParId',
        {
          parentId: 'f6a7c4f5602f46e291d06b1390a3f820'
        }
      ).then((data) => {
        this.dicListMap.postDicList = JSON.parse(data.zTreeNodes)
      }).catch((e) => {
      })
    },
    resetForm() {
      this.form = {
        CURRICULUMID: '', // 课程ID
        EXAMNAME: '', // 试卷名称
        EXAMTIME: '', // 考试时间（开始时间）
        ANSWERSHEETTIME: '', // 答卷时间（持续时间）
        EXAMSCORE: 100, // 试卷分数
        CURRICULUMUSERS: '', // 适用人员
        COURSEWARES: '', // 课件范围
        QUESTIONNUM: '', // 试题数量（10、20、50、100）
        PASSSCORE: '',
        DUOXUANTICOUNT: '',
        DUOXUANTINUMBER: '',
        DANYUANTICOUNT: '',
        DANXUANTINUMBER: '',
        PANDUITICOUNT: '',
        PANDUITINUMBER: '',
        TRAINTYPE: '',
        POSTTYPE: ''
      }

      if (this.$refs.pxTree) {
        this.$refs.pxTree.clearHandle()
      }
      if (this.$refs.keyGwRef2) {
        this.$refs.keyGwRef2.clearHandle()
      }
    },
    // 修改
    handleEditState(ID, state) {
      requestFN(
        '/stageexampaperinput/editState',
        {
          STAGEEXAMPAPERINPUT_ID: ID,
          STATE: state
        }
      ).then((data) => {
        this.$message({
          message: '设置成功',
          type: 'success'
        })
        this.getList()
      }).catch((e) => {
        this.listLoading = false
      })
    },
    // 获取列表
    getCountByQuestionType() {
      this.questionType.danxuanCount = 0
      this.questionType.duoxuanCount = 0
      this.questionType.panduanCount = 0
      requestFN(
        '/question/getCountByQuestionType',
        {
          POSTTYPE: this.form.POSTTYPE,
          TRAINTYPE: this.form.TRAINTYPE
        }
      ).then((data) => {
        data.varList.forEach(item => {
          if (item.QUESTIONTYPE == '1') {
            this.questionType.danxuanCount = item.count
          } else if (item.QUESTIONTYPE == '2') {
            this.questionType.duoxuanCount = item.count
          } else if (item.QUESTIONTYPE == '3') {
            this.questionType.panduanCount = item.count
          }
        })
      }).catch((e) => {
        this.listLoading = false
      })
    }
  }
}

</script>
