<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
<!--      <el-form-item label="考试编号" prop="examNo">-->
<!--        <el-input-->
<!--          v-model="queryParams.examNo"-->
<!--          placeholder="请输入考试编号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="分类ID" prop="classId">-->
<!--        <el-input-->
<!--          v-model="queryParams.classId"-->
<!--          placeholder="请输入分类ID"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="分类名" prop="className">-->
<!--        <el-input-->
<!--          v-model="queryParams.className"-->
<!--          placeholder="请输入分类名"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="专业ID" prop="majorId">-->
<!--        <el-input-->
<!--          v-model="queryParams.majorId"-->
<!--          placeholder="请输入专业ID"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="专业名" prop="majorName">-->
<!--        <el-input-->
<!--          v-model="queryParams.majorName"-->
<!--          placeholder="请输入专业名"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="职业ID" prop="careerId">-->
<!--        <el-input-->
<!--          v-model="queryParams.careerId"-->
<!--          placeholder="请输入职业ID"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="职业名" prop="careerName">-->
<!--        <el-input-->
<!--          v-model="queryParams.careerName"-->
<!--          placeholder="请输入职业名"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="考试批次" prop="examBatch">
        <el-input
          v-model="queryParams.examBatch"
          placeholder="请输入考试批次"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="考试开始时间">
        <el-date-picker
          v-model="daterangeExamStartTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
<!--      <el-form-item label="报名开始时间">-->
<!--        <el-date-picker-->
<!--          v-model="daterangeSignStartTime"-->
<!--          style="width: 240px"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          type="daterange"-->
<!--          range-separator="-"-->
<!--          start-placeholder="开始日期"-->
<!--          end-placeholder="结束日期"-->
<!--        ></el-date-picker>-->
<!--      </el-form-item>-->
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
          <el-option
            v-for="dict in dict.type.tb_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
<!--      <el-form-item label="创建时间" prop="createTime">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.createTime"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择创建时间">-->
<!--        </el-date-picker>-->
<!--      </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="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['hezhi:exam: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="['hezhi:exam:edit']"
        >修改</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="['hezhi:exam:remove']"
        >删除</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['hezhi:exam:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="examList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="考试主键ID" align="center" prop="examId" />-->
<!--      <el-table-column label="考试编号" align="center" prop="examNo" />-->
<!--      <el-table-column label="分类ID" align="center" prop="classId" />-->
<!--      <el-table-column label="分类名" align="center" prop="className" />-->
<!--      <el-table-column label="专业ID" align="center" prop="majorId" />-->
<!--      <el-table-column label="专业名" align="center" prop="majorName" />-->
<!--      <el-table-column label="职业ID" align="center" prop="careerId" />-->
<!--      <el-table-column label="职业名" align="center" prop="careerName" />-->
      <el-table-column label="logo" align="center" prop="logo" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.logo" :width="50" :height="50"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="文件" align="center" prop="fileUrl" />-->
      <el-table-column label="名称" align="center" prop="name" />
<!--      <el-table-column label="标题" align="center" prop="title" />-->
<!--      <el-table-column label="内容" align="center" prop="content" />-->
<!--      <el-table-column label="介绍" align="center" prop="introduce" />-->
<!--      <el-table-column label="考试单选题数" align="center" prop="singleSelectNum" />-->
<!--      <el-table-column label="考试单选题每题X分" align="center" prop="singleSelectScore" />-->
<!--      <el-table-column label="考试多选题数" align="center" prop="manySelectNum" />-->
<!--      <el-table-column label="考试多选题每题X分" align="center" prop="manySelectScore" />-->
<!--      <el-table-column label="考试判断题数" align="center" prop="judgeNum" />-->
<!--      <el-table-column label="考试判断题每题X分" align="center" prop="judgeScore" />-->
<!--      <el-table-column label="考试论述题数" align="center" prop="discussNum" />-->
<!--      <el-table-column label="考试论述题每题X分" align="center" prop="discussScore" />-->
      <el-table-column label="考试总分" align="center" prop="totalScore" />
      <el-table-column label="及格分" align="center" prop="passScore" />
      <el-table-column label="考试时间(分钟)" align="center" prop="examMinute" />
<!--      <el-table-column label="考试批次" align="center" prop="examBatch" width="100" />-->
<!--      <el-table-column label="提示" align="center" prop="tips" />-->
<!--      <el-table-column label="考试开始时间" align="center" prop="examStartTime" width="150" />-->
<!--      <el-table-column label="考试结束时间" align="center" prop="examEndTime" width="150" />-->
<!--      <el-table-column label="报名开始时间" align="center" prop="signStartTime" width="150" />-->
<!--      <el-table-column label="报名结束时间" align="center" prop="signEndTime" width="150" />-->
      <el-table-column label="报名费" align="center" prop="price" />
<!--      <el-table-column label="考试状态" align="center" prop="examStatus" />-->
<!--      <el-table-column label="是否定时更换题目" align="center" prop="isChange" />-->
<!--      <el-table-column label="更换题目天数" align="center" prop="changeDay" />-->
<!--      <el-table-column label="类型" align="center" prop="type" />-->
<!--      <el-table-column label="审核状态" align="center" prop="examineStatus">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.tb_examine_status" :value="scope.row.examineStatus"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="审核反馈" align="center" prop="examineFeedback" />-->
<!--      <el-table-column label="排序" align="center" prop="sort" />-->
<!--      <el-table-column label="备注" align="center" prop="remarks" />-->
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.tb_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="260px" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['hezhi:exam:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleSimulateExamUpdate(scope.row)"
            v-hasPermi="['hezhi:exam:edit']"
          >设置考试信息</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['hezhi:exam:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <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="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
        <el-form-item label="logo" prop="logo">
          <image-upload v-model="form.logo" :limit="1"/>
        </el-form-item>
<!--        <el-form-item label="文件" prop="fileUrl">-->
<!--          <file-upload v-model="form.fileUrl"/>-->
<!--        </el-form-item>-->
        <el-form-item label="名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="标题" prop="title">
          <el-input v-model="form.title" placeholder="请输入标题" />
        </el-form-item>
        <el-form-item label="等级" prop="level">
          <el-select v-model="form.level" placeholder="请选择等级">
            <el-option
              v-for="dict in dict.type.tb_subject_level"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="机构">
          <el-select v-model="form.evaluateAgencyId" placeholder="请选择机构"  @change="handleAgencyChange()">
            <el-option
              v-for="(item, index) in evaluateAgencyOptions"
              :key="index"
              :label="item.evaluateAgencyName"
              :value="item.evaluateAgencyId">
            </el-option>
          </el-select>
<!--          <exam-course :exam-course-list="form.examCourseList" />-->
        </el-form-item>
        <el-form-item label="职业名称">
          <el-select v-model="form.careerId" placeholder="请选择职业名称">
            <el-option
              v-for="(item, index) in getCourseOptions()"
              :key="index"
              :label="item.courseName"
              :value="item.courseId">
            </el-option>
          </el-select>
        </el-form-item>
<!--        <el-form-item label="职业名称">-->
<!--          <exam-course :exam-course-list="form.examCourseList" />-->
<!--        </el-form-item>-->
        <el-form-item label="报名提前天数" prop="examBatchEarly">
          <el-input-number v-model="form.examBatchEarly" :step="1" step-strictly />
        </el-form-item>
        <el-form-item label="考试批次">
          <exam-batch :exam-batch-list="form.examBatchList" />
        </el-form-item>
<!--        <el-form-item label="介绍" prop="introduce">-->
<!--          <el-input v-model="form.introduce" type="textarea" placeholder="请输入内容" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="考试批次" prop="examBatch">-->
<!--          <el-input v-model="form.examBatch" placeholder="请输入考试批次" />-->
<!--        </el-form-item>-->
<!--        <el-row>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="考试开始时间" prop="examStartTime">-->
<!--              <el-date-picker clearable-->
<!--                              v-model="form.examStartTime"-->
<!--                              type="datetime"-->
<!--                              value-format="yyyy-MM-dd HH:mm:ss"-->
<!--                              placeholder="请选择考试开始时间">-->
<!--              </el-date-picker>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="考试结束时间" prop="examEndTime">-->
<!--              <el-date-picker clearable-->
<!--                              v-model="form.examEndTime"-->
<!--                              type="datetime"-->
<!--                              value-format="yyyy-MM-dd HH:mm:ss"-->
<!--                              placeholder="请选择考试结束时间">-->
<!--              </el-date-picker>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--        </el-row>-->
<!--        <el-row>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="报名开始时间" prop="signStartTime">-->
<!--              <el-date-picker clearable-->
<!--                              v-model="form.signStartTime"-->
<!--                              type="datetime"-->
<!--                              value-format="yyyy-MM-dd HH:mm:ss"-->
<!--                              placeholder="请选择报名开始时间">-->
<!--              </el-date-picker>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="报名结束时间" prop="signEndTime">-->
<!--              <el-date-picker clearable-->
<!--                              v-model="form.signEndTime"-->
<!--                              type="datetime"-->
<!--                              value-format="yyyy-MM-dd HH:mm:ss"-->
<!--                              placeholder="请选择报名结束时间">-->
<!--              </el-date-picker>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--        </el-row>-->
        <el-row>
          <el-col :span="12">
            <el-form-item label="考试时间（分钟）" prop="examMinute">
              <el-input-number v-model="form.examMinute" :step="1" :min="0" step-strictly />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="及格分数" prop="passScore">
              <el-input-number v-model="form.passScore" :step="1" :min="0" step-strictly />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="考试提示" prop="tips">
          <el-input v-model="form.tips" placeholder="请输入考试提示" />
        </el-form-item>
        <el-form-item label="报名费" prop="price">
          <el-input-number
            v-model="form.price"
            placeholder="请输入报名费"
            :step="0.1"
            :precision="1"
            :min="0" />
        </el-form-item>
        <el-form-item label="定时更换题目">
          <el-radio-group v-model="form.isChange">
            <el-radio :label="0">否</el-radio>
            <el-radio :label="1">是</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="更换题目天数" prop="changeDay" v-if="this.form.isChange === 1">
          <el-input-number v-model="form.changeDay" :step="1" :min="1" step-strictly />
        </el-form-item>
<!--        <el-form-item label="审核状态" prop="examineStatus">-->
<!--          <el-radio-group v-model="form.examineStatus">-->
<!--            <el-radio-->
<!--              v-for="dict in dict.type.tb_examine_status"-->
<!--              :key="dict.value"-->
<!--              :label="parseInt(dict.value)"-->
<!--            >{{dict.label}}</el-radio>-->
<!--          </el-radio-group>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="审核反馈" prop="examineFeedback">-->
<!--          <el-input v-model="form.examineFeedback" type="textarea" placeholder="请输入内容" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="排序" prop="sort">-->
<!--          <el-input v-model="form.sort" placeholder="请输入排序" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="备注" prop="remarks">-->
<!--          <el-input v-model="form.remarks" type="textarea" placeholder="请输入内容" />-->
<!--        </el-form-item>-->
        <el-form-item label="状态" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio
              v-for="dict in dict.type.tb_status"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="内容">
          <editor v-model="form.content" :min-height="192"/>
        </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 :title="title" :visible.sync="openExam" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="考试单选题数" prop="singleSelectNum">
              <el-input-number v-model="form.singleSelectNum" :step="1" :min="0" step-strictly />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="单选题每题X分" prop="singleSelectScore">
              <el-input v-model="form.singleSelectScore" :min="0" type="number" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="考试多选题数" prop="manySelectNum">
              <el-input-number v-model="form.manySelectNum" :step="1" :min="0" step-strictly />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="多选题每题X分" prop="manySelectScore">
              <el-input v-model="form.manySelectScore" :min="0" type="number" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="考试判断题数" prop="judgeNum">
              <el-input-number v-model="form.judgeNum" :step="1" :min="0" step-strictly />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="判断题每题X分" prop="judgeScore">
              <el-input v-model="form.judgeScore" :min="0" type="number" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="考试论述题数" prop="discussNum">
              <el-input-number v-model="form.discussNum" :step="1" :min="0" step-strictly />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="论述题每题X分" prop="discussScore">
              <el-input v-model="form.discussScore" :min="0" type="number" />
            </el-form-item>
          </el-col>
        </el-row>

<!--        <el-form-item label="考试时间(分)" prop="examMinute">-->
<!--          <el-input-number v-model="form.examMinute" :step="1" :min="0" step-strictly />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="及格分" prop="passScore">-->
<!--          <el-input-number v-model="form.passScore" :step="1" :min="0" step-strictly />-->
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitExamForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {addExam, delExam, getExam, listExam, updateExam, updateExamConfig} from "@/api/hezhi/exam";
import ExamCourse from "@/components/ExamCourse/index.vue";
import ExamBatch from "@/views/hezhi/exam/examBatch.vue";
import {getSelectList} from "@/api/hezhi/evaluateAgency";
import {getAllCourseList, getAllCourseListByQuery} from "@/api/hezhi/link";

export default {
  name: "Exam",
  components: {ExamBatch, ExamCourse},
  dicts: ['tb_examine_status', 'tb_status', 'tb_subject_level'],
  data() {
    return {
      openExam: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 考试表格数据
      examList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 删除标记时间范围
      daterangeExamStartTime: [],
      // 删除标记时间范围
      daterangeExamEndTime: [],
      // 删除标记时间范围
      daterangeSignStartTime: [],
      // 删除标记时间范围
      daterangeSignEndTime: [],
      evaluateAgencyOptions:[],
      courseOptions:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        examNo: null,
        classId: null,
        className: null,
        majorId: null,
        majorName: null,
        careerId: null,
        careerName: null,
        logo: null,
        fileUrl: null,
        name: null,
        title: null,
        content: null,
        introduce: null,
        singleSelectNum: null,
        singleSelectScore: null,
        manySelectNum: null,
        manySelectScore: null,
        judgeNum: null,
        judgeScore: null,
        discussNum: null,
        discussScore: null,
        totalScore: null,
        passScore: null,
        examMinute: null,
        examBatch: null,
        tips: null,
        examStartTime: null,
        examEndTime: null,
        signStartTime: null,
        signEndTime: null,
        price: null,
        examStatus: null,
        isChange: null,
        changeDay: null,
        type: null,
        examineStatus: null,
        examineFeedback: null,
        sort: null,
        remarks: null,
        status: null,
        publicationTime: null,
        publisher: null,
        createTime: null,
        deleteTime: null,
        deleteBy: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        // logo: [
        //   { required: true, message: "logo不能为空", trigger: "blur" }
        // ],
        name: [
          { required: true, message: "名称不能为空", trigger: "blur" }
        ],
        level: [
          { required: true, message: "等级不能为空", trigger: "blur" }
        ],
        examBatchEarly: [
          { required: true, message: "报名提前天数不能为空", trigger: "blur" }
        ],
        examBatch: [
          { required: true, message: "考试批次不能为空", trigger: "blur" }
        ],
        examStartTime: [
          { required: true, message: "考试开始时间不能为空", trigger: "blur" }
        ],
        examEndTime: [
          { required: true, message: "考试结束时间不能为空", trigger: "blur" }
        ],
        signStartTime: [
          { required: true, message: "报名开始时间不能为空", trigger: "blur" }
        ],
        signEndTime: [
          { required: true, message: "报名结束时间不能为空", trigger: "blur" }
        ],
        price: [
          { required: true, message: "报名费不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    getSelectList().then(response => {
      this.evaluateAgencyOptions = response.data;
    });
  },
  methods: {
    getAllCourse(careerId) {
      getAllCourseListByQuery({careerId}).then(response => {
        this.courseOptions = response.data;
      })
    },
    // 重选机构清空对应课程
    handleAgencyChange() {
      this.form.careerId = undefined;
    },
    getCourseOptions() {
      let evaluateAgencyId = this.form.evaluateAgencyId;
      return this.courseOptions.filter(item => item.evaluateAgencyId === evaluateAgencyId);
    },
    /**
     * 处理价格输入，限制最多两位小数
     */
    handlePriceInput(value) {
      if (value === '') return;

      // 使用正则表达式保留最多两位小数
      const reg = /^(\d+)(\.\d{0,1})?$/;
      if (!reg.test(value)) {
        this.form.price = parseFloat(value.replace(/[^\d.]/g, '')).toFixed(1);
      }
    },
    /** 修改模拟考试设置按钮操作 */
    handleSimulateExamUpdate(row) {
      this.reset();
      const examId = row.examId
      getExam(examId).then(response => {
        this.form = response.data;
        this.openExam = true;
        this.title = "修改考试设置";
      });
    },
    /** 修改模拟考试设置提交按钮 */
    submitExamForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.examId != null) {
            updateExamConfig(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.openExam = false;
              this.getList();
            });
          }
        }
      });
    },

    /** 查询考试列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeExamStartTime && '' != this.daterangeExamStartTime) {
        this.queryParams.params["beginExamStartTime"] = this.daterangeExamStartTime[0];
        this.queryParams.params["endExamStartTime"] = this.daterangeExamStartTime[1];
      }
      if (null != this.daterangeExamEndTime && '' != this.daterangeExamEndTime) {
        this.queryParams.params["beginExamEndTime"] = this.daterangeExamEndTime[0];
        this.queryParams.params["endExamEndTime"] = this.daterangeExamEndTime[1];
      }
      if (null != this.daterangeSignStartTime && '' != this.daterangeSignStartTime) {
        this.queryParams.params["beginSignStartTime"] = this.daterangeSignStartTime[0];
        this.queryParams.params["endSignStartTime"] = this.daterangeSignStartTime[1];
      }
      if (null != this.daterangeSignEndTime && '' != this.daterangeSignEndTime) {
        this.queryParams.params["beginSignEndTime"] = this.daterangeSignEndTime[0];
        this.queryParams.params["endSignEndTime"] = this.daterangeSignEndTime[1];
      }
      listExam(this.queryParams).then(response => {
        this.examList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openExam = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        examId: null,
        examNo: null,
        classId: null,
        className: null,
        majorId: null,
        majorName: null,
        evaluateAgencyId: null,
        evaluateAgencyName: null,
        careerId: null,
        careerName: null,
        logo: null,
        fileUrl: null,
        name: null,
        title: null,
        content: null,
        introduce: null,
        singleSelectNum: 0,
        singleSelectScore: 0,
        manySelectNum: 0,
        manySelectScore: 0,
        judgeNum: 0,
        judgeScore: 0,
        discussNum: 0,
        discussScore: 0,
        totalScore: null,
        passScore: 60,
        examMinute: 10,
        examBatchEarly: 0,
        examBatch: null,
        tips: null,
        examStartTime: null,
        examEndTime: null,
        signStartTime: null,
        signEndTime: null,
        price: null,
        examStatus: null,
        isChange: 0,
        changeDay: 1,
        type: null,
        examineStatus: null,
        examineFeedback: null,
        sort: null,
        remarks: null,
        status: 0,
        publicationTime: null,
        publisher: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        deleteTime: null,
        deleteBy: null,
        examCourseList: [],
        examBatchList: [],
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeExamStartTime = [];
      this.daterangeExamEndTime = [];
      this.daterangeSignStartTime = [];
      this.daterangeSignEndTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.examId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加考试";
      this.getAllCourse()
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const examId = row.examId || this.ids
      getExam(examId).then(response => {
        this.form = response.data;
        this.getAllCourse(this.form.careerId)
        this.open = true;
        this.title = "修改考试";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          let majorId = this.form.majorId;
          if (majorId && majorId.length > 0){
            this.form.majorId = majorId[majorId.length-1]
          }
          if (this.form.examId != null) {
            updateExam(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addExam(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const examIds = row.examId || this.ids;
      this.$modal.confirm('是否确认删除考试编号为"' + examIds + '"的数据项？').then(function() {
        return delExam(examIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('hezhi/exam/export', {
        ...this.queryParams
      }, `exam_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
