<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="试题ID" prop="id">
        <el-input
          v-model="queryParams.id"
          type="number"
          min="1"
          placeholder="请输入试题ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标题" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入标题"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学科" prop="subjectName">
        <el-input
          v-model="queryParams.subjectName"
          placeholder="请输入学科"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="试题题型" prop="qtpye">
        <el-input
          v-model="queryParams.qtpye"
          placeholder="请输入试题题型"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="包含子题" prop="issub">
        <el-select v-model="queryParams.issub" placeholder="请输入是否包含子题" clearable size="small">
          <el-option
            v-for="dict in issubOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <!--<el-form-item label="难度" prop="diff">-->
      <!--<el-input-->
      <!--v-model="queryParams.diff"-->
      <!--placeholder="请输入难度"-->
      <!--clearable-->
      <!--size="small"-->
      <!--@keyup.enter.native="handleQuery"-->
      <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="如果是听力题，存储了对应听力文件位置" prop="md5">-->
      <!--<el-input-->
      <!--v-model="queryParams.md5"-->
      <!--placeholder="请输入如果是听力题，存储了对应听力文件位置"-->
      <!--clearable-->
      <!--size="small"-->
      <!--@keyup.enter.native="handleQuery"-->
      <!--/>-->
      <!--</el-form-item>-->

      <!--<el-form-item label="年级ID" prop="gradeid">-->
      <!--<el-input-->
      <!--v-model="queryParams.gradeid"-->
      <!--placeholder="请输入年级ID"-->
      <!--clearable-->
      <!--size="small"-->
      <!--@keyup.enter.native="handleQuery"-->
      <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="知识点" prop="knowledges">-->
      <!--<el-input-->
      <!--v-model="queryParams.knowledges"-->
      <!--placeholder="请输入知识点"-->
      <!--clearable-->
      <!--size="small"-->
      <!--@keyup.enter.native="handleQuery"-->
      <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="试题区域" prop="area">-->
      <!--<el-input-->
      <!--v-model="queryParams.area"-->
      <!--placeholder="请输入试题区域"-->
      <!--clearable-->
      <!--size="small"-->
      <!--@keyup.enter.native="handleQuery"-->
      <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="试题年份" prop="year">-->
      <!--<el-input-->
      <!--v-model="queryParams.year"-->
      <!--placeholder="请输入试题年份"-->
      <!--clearable-->
      <!--size="small"-->
      <!--@keyup.enter.native="handleQuery"-->
      <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="试题类型：35，期中；38，同步；38，单元检测；36，月考；32，模拟考试；31，中考；34，期末考试；33，高考；37，其他" prop="papertpye">-->
      <!--<el-input-->
      <!--v-model="queryParams.papertpye"-->
      <!--placeholder="请输入试题类型：35，期中；38，同步；38，单元检测；36，月考；32，模拟考试；31，中考；34，期末考试；33，高考；37，其他"-->
      <!--clearable-->
      <!--size="small"-->
      <!--@keyup.enter.native="handleQuery"-->
      <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="试题来源(试卷)" prop="source">-->
      <!--<el-input-->
      <!--v-model="queryParams.source"-->
      <!--placeholder="请输入试题来源(试卷)"-->
      <!--clearable-->
      <!--size="small"-->
      <!--@keyup.enter.native="handleQuery"-->
      <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="试题来源" prop="fromsite">-->
      <!--<el-input-->
      <!--v-model="queryParams.fromsite"-->
      <!--placeholder="请输入试题来源"-->
      <!--clearable-->
      <!--size="small"-->
      <!--@keyup.enter.native="handleQuery"-->
      <!--/>-->
      <!--</el-form-item>-->

      <!--<el-form-item label="是否支持自动阅卷 1：支持" prop="isnormal">-->
      <!--<el-input-->
      <!--v-model="queryParams.isnormal"-->
      <!--placeholder="请输入是否支持自动阅卷 1：支持"-->
      <!--clearable-->
      <!--size="small"-->
      <!--@keyup.enter.native="handleQuery"-->
      <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="是否匹配章节知识点，1匹配，0不匹配" prop="iskonw">-->
      <!--<el-input-->
      <!--v-model="queryParams.iskonw"-->
      <!--placeholder="请输入是否匹配章节知识点，1匹配，0不匹配"-->
      <!--clearable-->
      <!--size="small"-->
      <!--@keyup.enter.native="handleQuery"-->
      <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="试题tiid结合渠道商字段处理" prop="tiid">-->
      <!--<el-input-->
      <!--v-model="queryParams.tiid"-->
      <!--placeholder="请输入试题tiid结合渠道商字段处理"-->
      <!--clearable-->
      <!--size="small"-->
      <!--@keyup.enter.native="handleQuery"-->
      <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="试题更新日期" prop="similarity">-->
      <!--<el-input-->
      <!--v-model="queryParams.similarity"-->
      <!--placeholder="请输入试题更新日期"-->
      <!--clearable-->
      <!--size="small"-->
      <!--@keyup.enter.native="handleQuery"-->
      <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="是否支持选项分离：1支持" prop="isunique">-->
      <!--<el-input-->
      <!--v-model="queryParams.isunique"-->
      <!--placeholder="请输入是否支持选项分离：1支持"-->
      <!--clearable-->
      <!--size="small"-->
      <!--@keyup.enter.native="handleQuery"-->
      <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="试题md5编码" prop="md52">-->
      <!--<el-input-->
      <!--v-model="queryParams.md52"-->
      <!--placeholder="请输入试题md5编码"-->
      <!--clearable-->
      <!--size="small"-->
      <!--@keyup.enter.native="handleQuery"-->
      <!--/>-->
      <!--</el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          @click="handleUpdateBatchQtpyeByIds"
          v-hasPermi="['back:questions:edit']"
        >批量修改题型
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['back:questions:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAddText"
          v-hasPermi="['back:questions:add']"
        >新增文本
        </el-button>
      </el-col>
      <!--<el-col :span="1.5">-->
      <!--<el-button-->
      <!--type="success"-->
      <!--plain-->
      <!--icon="el-icon-edit"-->
      <!--size="mini"-->
      <!--:disabled="single"-->
      <!--@click="handleUpdate"-->
      <!--v-hasPermi="['back:questions:edit']"-->
      <!--&gt;修改</el-button>-->
      <!--</el-col>-->
      <!--<el-col :span="1.5">-->
      <!--<el-button-->
      <!--type="danger"-->
      <!--plain-->
      <!--icon="el-icon-delete"-->
      <!--size="mini"-->
      <!--:disabled="multiple"-->
      <!--@click="handleDelete"-->
      <!--v-hasPermi="['back:questions:remove']"-->
      <!--&gt;删除</el-button>-->
      <!--</el-col>-->
      <!--<el-col :span="1.5">-->
      <!--<el-button-->
      <!--type="warning"-->
      <!--plain-->
      <!--icon="el-icon-download"-->
      <!--size="mini"-->
      <!--:loading="exportLoading"-->
      <!--@click="handleExport"-->
      <!--v-hasPermi="['back:questions:export']"-->
      <!--&gt;导出</el-button>-->
      <!--</el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <div style="width: 100%; overflow-x: auto;">
      <el-table v-loading="loading" :data="questionsList" id="tb-question" style="min-width: 2200px"
                @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center"/>
        <el-table-column label="试题ID" align="center" prop="id" width="100"/>
        <!--<el-table-column label="学科Id" align="center" prop="subjectid" />-->
        <el-table-column label="学科" align="center" prop="subjectName" width="100"/>
        <el-table-column label="标题" align="left" prop="title">
          <template slot-scope="{row}">
            <div v-html="row.title"></div>
          </template>
        </el-table-column>
        <!--      <el-table-column label="图片" align="center" prop="title" >-->
        <!--        <template slot-scope="scope">-->
        <!--          <router-link :to="'/question/pic/' + scope.row.id" class="link-type">-->
        <!--            <el-button type="text">图片</el-button>-->
        <!--          </router-link>-->

        <!--        </template>-->
        <!--      </el-table-column>-->
        <el-table-column label="选项A" align="center" prop="optionA"/>
        <el-table-column label="选项B" align="center" prop="optionB"/>
        <el-table-column label="选项C" align="center" prop="optionC"/>
        <el-table-column label="选项D" align="center" prop="optionD"/>
        <el-table-column label="选项E" align="center" prop="optionE"/>
        <el-table-column label="answer1" align="center" prop="answer1" show-overflow-tooltip/>
        <el-table-column label="answer2" align="center" prop="answer2" show-overflow-tooltip/>
        <!--<el-table-column label="试题解析" align="center" prop="parse" />-->
        <el-table-column label="试题题型" align="center" prop="qtpye" width="80"/>
        <!--<el-table-column label="难度" align="center" prop="diff" />-->
        <!--<el-table-column label="如果是听力题，存储了对应听力文件位置" align="center" prop="md5" />-->
        <!--<el-table-column label="年级ID" align="center" prop="gradeid" />-->
        <!--<el-table-column label="知识点" align="center" prop="knowledges" />-->
        <!--<el-table-column label="试题区域" align="center" prop="area" />-->
        <!--<el-table-column label="试题年份" align="center" prop="year" />-->
        <!--<el-table-column label="试题类型：35，期中；38，同步；38，单元检测；36，月考；32，模拟考试；31，中考；34，期末考试；33，高考；37，其他" align="center" prop="papertpye" />-->
        <!--<el-table-column label="试题来源(试卷)" align="center" prop="source" />-->
        <!--<el-table-column label="试题来源" align="center" prop="fromsite" />-->
        <!--<el-table-column label="是否存在子题，1：存在 关联subquestions.pid" align="center" prop="issub" />-->
        <!--<el-table-column label="是否支持自动阅卷 1：支持" align="center" prop="isnormal" />-->
        <!--<el-table-column label="是否匹配章节知识点，1匹配，0不匹配" align="center" prop="iskonw" />-->
        <!--<el-table-column label="试题tiid结合渠道商字段处理" align="center" prop="tiid" />-->
        <!--<el-table-column label="试题更新日期" align="center" prop="similarity" />-->
        <!--<el-table-column label="是否支持选项分离：1支持" align="center" prop="isunique" />-->
        <!--<el-table-column label="试题md5编码" align="center" prop="md52" />-->
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100">
          <template slot-scope="scope">
            <!--<el-button-->
            <!--size="mini"-->
            <!--type="text"-->
            <!--icon="el-icon-edit"-->
            <!--@click="handleUpdate(scope.row)"-->
            <!--v-hasPermi="['back:questions:edit']"-->
            <!--&gt;修改题型</el-button>-->
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdateQuestion(scope.row, 1)"
              v-hasPermi="['back:questions:edit']"
            >文本修改题目
            </el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdateQuestion(scope.row, 2)"
              v-hasPermi="['back:questions:edit']"
            >修改题目
            </el-button>
            <!--          <el-button-->
            <!--            size="mini"-->
            <!--            type="text"-->
            <!--            icon="el-icon-edit"-->
            <!--            @click="handleUpdateSubquestion(scope.row)"-->
            <!--            v-hasPermi="['back:subquestions:edit']"-->
            <!--          >子题</el-button>-->
            <!--<el-button-->
            <!--size="mini"-->
            <!--type="text"-->
            <!--icon="el-icon-delete"-->
            <!--@click="handleDelete(scope.row)"-->
            <!--v-hasPermi="['back:questions:remove']"-->
            <!--&gt;删除</el-button>-->
          </template>
        </el-table-column>
      </el-table>
    </div>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改试题类型对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="试题题型" prop="qtpye">
          <el-input v-model="form.qtpye" placeholder="请输入试题题型"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改试题对话框 -->
    <!-- Use v-if destroy editor, or else el-input will be listened by editor component and modify input as unexpected HTML -->
    <el-dialog v-if="openQuestion" :title="title" :visible.sync="openQuestion" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <!--<el-form-item label="题目ID" prop="id">-->
        <!--<el-input v-model="form.id" type="text" placeholder="请输入内容" disabled="true"/>-->
        <!--</el-form-item>-->
        <el-form-item label="科目" prop="subjectid">
          <el-select v-model="form.subjectid" placeholder="请选择科目">
            <el-option v-for="item in subjectIdOptions" :key="item.subjectId" :label="item.subjectName"
                       :value="item.subjectId"/>
          </el-select>
        </el-form-item>
        <el-form-item label="标题" prop="title">
          <editor v-model="form.title" :min-height="122"/>
        </el-form-item>
        <el-form-item label="选项A" prop="optionA">
          <editor v-model="form.optionA" :min-height="122"/>
        </el-form-item>
        <el-form-item label="选项B" prop="optionB">
          <editor v-model="form.optionB" :min-height="122"/>
        </el-form-item>
        <el-form-item label="选项C" prop="optionC">
          <editor v-model="form.optionC" :min-height="122"/>
        </el-form-item>
        <el-form-item label="选项D" prop="optionD">
          <editor v-model="form.optionD" :min-height="122"/>
        </el-form-item>
        <el-form-item label="选项E" prop="optionE">
          <editor v-model="form.optionE" :min-height="122"/>
        </el-form-item>
        <el-form-item label="答案1" prop="answer1">
          <editor v-model="form.answer1" :min-height="122"/>
        </el-form-item>
        <el-form-item label="答案2" prop="answer2">
          <editor v-model="form.answer2" :min-height="122"/>
        </el-form-item>
        <el-form-item label="试题解析" prop="parse">
          <editor v-model="form.parse" :min-height="122"/>
        </el-form-item>
        <el-form-item label="试题题型" prop="qtpye">
          <el-input v-model="form.qtpye" placeholder="请输入试题题型" autosize/>
        </el-form-item>
        <el-form-item label="难易度" prop="diff">
          <el-input-number v-model="form.diff" placeholder="难易度（1-5）" :min="1" :max="5"/>
        </el-form-item>
        <el-form-item label="知识点" prop="knowledges">
          <el-input v-model="form.knowledges" placeholder="请输入知识点" autosize/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormQuestion">确 定</el-button>
        <el-button @click="cancelQuestion">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改试题类型对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="试题题型" prop="qtpye">
          <el-input v-model="form.qtpye" placeholder="请输入试题题型"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改试题对话框 -->
    <el-dialog v-if="openQuestionText" title="题目" :visible.sync="openQuestionText" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <!--<el-form-item label="题目ID" prop="id">-->
        <!--<el-input v-model="form.id" type="text" placeholder="请输入内容" disabled="true"/>-->
        <!--</el-form-item>-->
        <el-form-item label="科目" prop="subjectid">
          <el-select v-model="form.subjectid" placeholder="请选择科目">
            <el-option v-for="item in subjectIdOptions" :key="item.subjectId" :label="item.subjectName"
                       :value="item.subjectId"/>
          </el-select>
        </el-form-item>
        <el-form-item label="标题" prop="title">
          <el-input type="textarea" v-model="form.title" autosize :min-height="122"/>
        </el-form-item>
        <el-form-item label="选项A" prop="optionA">
          <el-input type="textarea" v-model="form.optionA" autosize :min-height="122"/>
        </el-form-item>
        <el-form-item label="选项B" prop="optionB">
          <el-input type="textarea" v-model="form.optionB" autosize :min-height="122"/>
        </el-form-item>
        <el-form-item label="选项C" prop="optionC">
          <el-input type="textarea" v-model="form.optionC" autosize :min-height="122"/>
        </el-form-item>
        <el-form-item label="选项D" prop="optionD">
          <el-input type="textarea" v-model="form.optionD" autosize :min-height="122"/>
        </el-form-item>
        <el-form-item label="选项E" prop="optionE">
          <el-input type="textarea" v-model="form.optionE" autosize :min-height="122"/>
        </el-form-item>
        <el-form-item label="答案1" prop="answer1">
          <el-input type="textarea" v-model="form.answer1" autosize :min-height="122"/>
        </el-form-item>
        <el-form-item label="答案2" prop="answer2">
          <el-input type="textarea" v-model="form.answer2" autosize :min-height="122"/>
        </el-form-item>
        <el-form-item label="试题解析" prop="parse">
          <el-input type="textarea" v-model="form.parse" autosize :min-height="122"/>
        </el-form-item>
        <el-form-item label="试题题型" prop="qtpye">
          <el-input v-model="form.qtpye" placeholder="请输入试题题型" autosize/>
        </el-form-item>
        <el-form-item label="难易度" prop="diff">
          <el-input-number v-model="form.diff" placeholder="难易度（1-5）" :min="1" :max="5"/>
        </el-form-item>
        <el-form-item label="知识点" prop="knowledges">
          <el-input v-model="form.knowledges" placeholder="请输入知识点" autosize/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormQuestion">确 定</el-button>
        <el-button @click="cancelQuestion">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  handleUpdateBatchQtpyeByIds,
  updateBatchQtpyeByIds,
  listQuestions,
  getQuestions,
  delQuestions,
  addQuestions,
  updateQuestions,
  exportQuestions,
  getQuestionsInfo
} from "@/api/mingxue/questions";
import {getSubjectsList, getPharseGradeList} from "@/api/mxjb/webApi";
import {getSubquestions} from "@/api/back/subquestions";

import Editor from '@/components/Editor';

export default {
  name: "Questions",
  components: {
    Editor
  },
  data() {
    return {
      openSubquestion: false,
      openQuestionText: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 试题表格数据
      questionsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层修改题目类型
      open: false,
      // 是否存在子题，1：存在 关联subquestions.pid字典
      issubOptions: [],
      // 科目
      subjectIdOptions: [],
      // 是否显示弹出层
      openQuestion: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,
        subjectName: null,
        title: null,
        optionA: null,
        optionB: null,
        optionC: null,
        optionD: null,
        optionE: null,
        answer1: null,
        answer2: null,
        parse: null,
        qtpye: null,
        diff: null,
        md5: null,
        subjectid: null,
        gradeid: null,
        knowledges: null,
        area: null,
        year: null,
        papertpye: null,
        source: null,
        fromsite: null,
        issub: null,
        isnormal: null,
        iskonw: null,
        tiid: null,
        similarity: null,
        isunique: null,
        md52: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        title: [
          {required: true, message: "标题不能为空", trigger: "blur"}
        ]
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("bool_flag").then(response => {
      this.issubOptions = response.data;
    });
    getSubjectsList().then(
      (rep) =>
        (this.subjectIdOptions = rep.rows.map((item) => ({
          subjectId: item.subjectid,
          subjectName: item.subjectName,
        })))
    );
  },
  methods: {
    /** 查询试题列表 */
    getList() {
      this.loading = true;
      listQuestions(this.queryParams).then(response => {
        this.questionsList = response.rows;
        this.total = response.total;
        this.loading = false;
        this.mxGlobal.MathQueue('tb-question')
      });
    },
    // 是否存在子题，1：存在 关联subquestions.pid字典翻译
    issubFormat(row, column) {
      return this.selectDictLabel(this.issubOptions, row.issub);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openQuestion = false;
      this.openQuestionText = false;
      this.reset();
    },
    // 取消按钮
    cancelQuestion() {
      this.open = false;
      this.openQuestion = false;
      this.openQuestionText = false;
      this.reset();
    },
    // 取消按钮
    cancelSubquestion() {
      this.openSubquestion = false;
      this.resetSubquestion();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        title: null,
        optionA: null,
        optionB: null,
        optionC: null,
        optionD: null,
        optionE: null,
        answer1: null,
        answer2: null,
        parse: null,
        qtpye: null,
        subjectName: null,
        diff: null,
        md5: null,
        subjectid: null,
        gradeid: null,
        knowledges: null,
        area: null,
        year: null,
        papertpye: null,
        source: null,
        fromsite: null,
        issub: null,
        isnormal: null,
        iskonw: null,
        tiid: null,
        similarity: null,
        isunique: null,
        md52: null
      };
      this.resetForm("form");
    },

    // 表单重置
    resetSubquestion() {
      this.form = {
        id: null,
        title: null,
        optionA: null,
        optionB: null,
        optionC: null,
        optionD: null,
        pid: null,
        answer1: null,
        answer2: null,
        parse: null,
        qtpye: null,
        diff: null,
        subjectid: null,
        gradeid: null,
        knowledges: null,
        source: null,
        tiid: null,
        ptiid: null,
        fromsite: null,
        answerJson: null
      };
      this.resetForm("formSubquestion");
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.openQuestion = true;
      this.title = "添加试题";
    },
    /** 新增按钮操作 */
    handleAddText() {
      this.reset();
      this.openQuestionText = true;
      this.title = "添加试题";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getQuestions(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改试题类型";
      });
    },
    /** 修改按钮操作 */
    handleUpdateQuestion(row, type) {
      this.reset();
      const id = row.id || this.ids
      getQuestionsInfo(id).then(response => {
        this.form = response.data;
        if (type == 1) {
          this.openQuestionText = true;
        } else {
          this.openQuestion = true;
          this.title = "修改试题";
        }

      });
    },
    /** 修改子题操作 */
    handleUpdateSubquestion(row) {
      this.$router.push("/subquestions/" + row.id)
    },
    /** 批量修改题型 */
    handleUpdateBatchQtpyeByIds(row) {
      const ids0 = row.id || this.ids
      const ids = ids0.join()
      this.$prompt('请输入"' + ids + '"的题型', "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消"
      }).then(({value}) => {
        handleUpdateBatchQtpyeByIds(ids, value).then(response => {
          this.getList();
          this.msgSuccess("修改成功，新题型是：" + value);
        });
      }).catch(() => {
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateQuestions(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.openQuestion = false;
              this.openQuestionText = false;
              this.getList();
            });
          } else {
            addQuestions(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.openQuestion = false;
              this.openQuestionText = false;
              this.getList();
            });
          }
        }
      });
    },

    /** 提交按钮 */
    submitFormQuestion() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateQuestions(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.openQuestion = false;
              this.openQuestionText = false;
              this.getList();
            });
          } else {
            addQuestions(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.openQuestion = false;
              this.openQuestionText = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除试题编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delQuestions(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有试题数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.exportLoading = true;
        return exportQuestions(queryParams);
      }).then(response => {
        this.download(response.msg);
        this.exportLoading = false;
      })
    }
  }
};
</script>

<style>
.el-tooltip__popper {
  max-width: min(80vw, 800px); /* 最大为视口80%或500px */
  word-break: break-word; /* 长单词换行 */
}
</style>
