<template>
  <div class="app-warp">
    <div class="app-structure">
      <div class="app-search">
        <el-page-header content="添加试卷" @back="goback"/>
        <div class="app-search" style="margin-top: 20px">
          <div class="app-search-form">
            <div class="form-item">
              <label> 试卷名称：</label>
              <el-input v-model="KEYWORDS" placeholder="搜索" />
            </div>
            <div v-show="!searchFromCollapse" class="form-item">
              <label> 创建时间：</label>
              <el-date-picker v-model="dates" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" format="yyyy-MM-dd" class="filter-item" />
            </div>

            <div v-show="!searchFromCollapse" class="form-item">
              <label> 课件状态：</label>
              <el-select v-model="vidSate" placeholder="请选择">
                <el-option v-for="item in vidStateList" :key="item.value" :label="item.label" :value="item.value"/>
              </el-select>
            </div>
            <div v-show="!searchFromCollapse" class="form-item">
              <label> 满分：</label>
              <el-input v-model="EXAMSCORE" placeholder="满分" />
            </div>
            <div class="form-item text-right">
              <el-button v-waves type="primary" icon="el-icon-search" @click="getQuery">
                搜索
              </el-button>
              <el-button v-waves icon="el-icon-refresh" @click="goKeyReset">
                重置
              </el-button>
              <el-button v-if="searchFromCollapse==true" type="text" @click="searchFromCollapse = false">展开 <i class="el-icon-arrow-down"/></el-button>
              <el-button v-else type="text" @click="searchFromCollapse = true">合并 <i class="el-icon-arrow-up"/></el-button>
            </div>
          </div>
        </div>
      </div>
      <div class="app-tools">
        <div class="app-function">
          <el-button type="primary" icon="el-icon-plus" @click="handleAdd">保存试卷</el-button>
        </div>
        <div class="app-minbtn">
          <span class="screening">
            <el-dropdown trigger="click">
              <el-button type="text" icon="el-icon-finished"/>
              <el-dropdown-menu slot="dropdown" style="margin-top:3px;">
                <div class="app-checkbox-group">
                  <el-checkbox-group v-model="checkList">
                    <el-checkbox v-for="item in checkboxList" :key="item" :label="item" style="display: block"/>
                  </el-checkbox-group>
                </div>
              </el-dropdown-menu>
            </el-dropdown>
          </span>
          <el-button type="text" icon="el-icon-refresh-left"/>
          <el-button type="text" icon="el-icon-full-screen"/>
        </div>
      </div>
      <div class="app-container">
        <el-table
          v-loading="listLoading"
          ref="multipleTable"
          :data="varList"
          :row-key="getRowKey"
          :header-cell-style="{background:'#f5f7fa',color:'#606266'}"
          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 v-if="checkList.includes('上传时间')" prop="CREATTIME" label="上传时间" align="center" />
          <el-table-column v-if="checkList.includes('满分')" prop="EXAMSCORE" label="满分" align="center">
            <template slot-scope="{row}">
              <template v-if="row.EXAMSCORE.substring(row.EXAMSCORE.lastIndexOf('.')+1,row.EXAMSCORE.length)==='0'">
                {{ row.EXAMSCORE.substring(0,row.EXAMSCORE.lastIndexOf('.')) }}
              </template>
              <template v-else>
                {{ row.EXAMSCORE }}
              </template>
            </template>
          </el-table-column>
          <el-table-column v-if="checkList.includes('试卷属性')" prop="STATE" label="试卷属性" align="center" width="100">
            <template slot-scope="{row}">
              <template v-if="row.COLLECTIVE =='0'">
                <div>平台通用</div>
              </template>
              <template v-if="row.COLLECTIVE =='1'">
                <div>指定机构专用</div>
              </template>
            </template>
          </el-table-column>
          <el-table-column v-if="checkList.includes('试卷状态')" prop="STATE" label="试卷状态" align="center" width="100">
            <template slot-scope="{row}">
              <template v-if="row.ISSELL =='0'">
                <div><span class="status-dot status-red"/>下架</div>
              </template>
              <template v-if="row.ISSELL =='1'">
                <div><span class="status-dot status-green"/>上架</div>
              </template>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="280">
            <template slot-scope="{row}">
              <el-button type="text" @click="handleShowExam(row.STAGEEXAMPAPERINPUT_ID)">查看试卷</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="page-btn-group">
          <div/>
          <pagination :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
        </div>
      </div>
    </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="请选择" />
        </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" oninput="if(value<0)value=0" 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" oninput="if(value<0)value=0" 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" oninput="if(value<0)value=0" 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>
  </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'
export default {
  components: { Pagination, SelectTree },
  inject: ['setActiveName', 'setCorpInfoId'],
  directives: { waves },
  data() {
    var totalQuesFraction = (rule, value, callback) => {
      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 {
      searchFromCollapse: true,
      listLoading: true,
      add: false,
      del: false,
      edit: false,
      listQuery: {
        page: 1,
        limit: 10
      },
      total: 0,
      config: config,
      KEYWORDS: '',
      TRAINTYPE: '',
      POSTTYPE: '',
      INDUSTRY: '',
      TRAINLEVEL: '',
      EXAMSCORE: '',
      vidSate: '',

      dates: [], // 时间
      vidStateList: [
        { value: '0', label: '下架' },
        { value: '1', label: '上架' }
      ],
      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' }]
      },
      industryProps: {
        value: 'INDUSTRYTYPE_ID',
        multiple: true,
        checkStrictly: true,
        children: 'nodes',
        label: 'NAME'
      },
      dicListMap: {
        trainDicList: [],
        postDicList: [],
        industryTreeData: [],
        trainLevelDicList: []
      },
      questionType: {
        danxuanCount: 0,
        duoxuanCount: 0,
        panduanCount: 0,
        duoxuanDis: false,
        danxuanDis: false,
        panduanDis: false
      },
      sumFraction: 0, // 习题总分数
      checkList: ['上传时间', '满分', '试卷属性', '试卷状态'],
      checkboxList: ['上传时间', '满分', '试卷属性', '试卷状态']
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getRowKey(row) {
      return row.STAGEEXAMPAPERINPUT_ID
    },
    // 搜索
    getQuery() {
      this.$refs.multipleTable.clearSelection()
      this.getList()
    },
    goKeyReset() {
      this.KEYWORDS = ''
      this.TRAINTYPE = ''
      this.EXAMSCORE = ''
      this.POSTTYPE = ''
      this.vidSate = ''
      this.dates = []
      this.TRAINLEVEL = ''
      this.dicListMap['postDicList'] = []
      this.dicListMap['industryTreeData'] = []
      this.dicListMap['trainLevelDicList'] = []
      this.getQuery()
    },
    // 获取列表
    getList() {
      console.info(this.TRAINLEVEL)
      this.listLoading = true
      requestFN(
        '/stageexampaperPrivatization/listprivate?showCount=' + this.listQuery.limit + '&currentPage=' + this.listQuery.page,
        {
          KEYWORDS: this.KEYWORDS,
          STARTTIME: this.dates[0],
          ENDTIME: this.dates[1],
          ISSELL: this.vidSate,
          CORPINFO_ID: this.$parent.parentObj.CORPINFO_ID,
          EXAMSCORE: this.EXAMSCORE
        }
      ).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() {
      const _selectData = this.$refs.multipleTable.selection
      if (_selectData == null || _selectData.length == 0) {
        this.$message({
          message: '请选中要保存的项...',
          type: 'error'
        })
        return false
      }
      this.stageexamIdList = []
      const stageexamList = this.$refs.multipleTable.selection// 选择的视频课件内容
      stageexamList.forEach(item => {
        this.stageexamIdList.push(item.STAGEEXAMPAPERINPUT_ID)
      })
      requestFN(
        '/stageexampaperPrivatization/add',
        {
          stageexamIdList: JSON.stringify(this.stageexamIdList),
          CORPINFO_ID: this.$parent.parentObj.CORPINFO_ID
        }
      ).then((data) => {
        this.$message.success('保存成功')
        this.$refs.multipleTable.clearSelection()
        this.getList()
      }).catch((e) => {
        this.listLoading = false
      })
    },
    // 修改
    handleEdit(ID) {
      this.$parent.STAGEEXAMPAPERINPUT_ID = ID
      this.setActiveName('Edit')
    },
    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.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.$parent.STAGEEXAMPAPERINPUT_ID = ExamId
      this.$parent.goType = 'add'
      this.setActiveName('stageexaminfo')
    },
    // 判断按钮权限，用于是否显示按钮
    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
      })
    },
    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/editIssell',
        {
          STAGEEXAMPAPERINPUT_ID: ID,
          ISSELL: state
        }
      ).then((data) => {
        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
      })
    },
    goback() {
      this.setActiveName('stageexampaperList')
    }
  }
}

</script>
