<template>
  <div>
    <section class="content" style="margin-top: -10px;">
      <div class="box box-info">
        <!-- 头信息 -->
        <div
          class="box-header with-border"
          style="background-color:#D3DCE6;margin-bottom:20px;"
        >
          <h3 class="box-title">网络考试</h3>
          <div class="box-tools pull-right">
            <button
              type="button"
              class="btn btn-box-tool"
              data-widget="collapse"
            >
              <i class="fa fa-minus"></i>
            </button>
          </div>
        </div>

        <!-- 正文信息 -->
        <div class="box-body">
          <el-form
            :inline="true"
            :rules="rules"
            ref="onlineExamForm"
            :model="onlineExamForm"
            label-position="right"
            label-width="100px"
          >
            <div style="text-align:right">
              <el-button type="primary" @click="saveOnlineExam"
                >保 存</el-button
              >
              <el-button @click="back">返 回</el-button>
            </div>
            <el-tabs v-model="tabs">
              <el-tab-pane label="基础信息" name="first">
                <el-row :gutter="10">
                  <el-col>
                    <el-form-item
                      label="考试名称"
                      :label-width="formLabelWidth"
                      prop="name"
                    >
                      <el-input
                        style="width:200px"
                        :maxlength="50"
                        type="textarea"
                        autosize
                        v-model="onlineExamForm.name"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="10">
                  <el-col :xs="15" :sm="15" :md="15" :lg="15">
                    <el-form-item
                      label="考试类型"
                      class="select-margin"
                      prop="examType"
                    >
                      <el-select
                        style="width:200px"
                        :disabled="true"
                        v-model="onlineExamForm.examType"
                        placeholder="请选择"
                      >
                        <el-option
                          v-for="item in examTypeList"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value"
                        >
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="10">
                  <el-col :xs="15" :sm="15" :md="15" :lg="15">
                    <el-form-item
                      label="开始时间"
                      :label-width="formLabelWidth"
                      prop="beginTime"
                    >
                      <el-date-picker
                        style="width:200px"
                        v-model="onlineExamForm.beginTime"
                        type="datetime"
                        placeholder="选择考试开始时间"
                        @change="getBeginTime"
                      >
                      </el-date-picker>
                    </el-form-item>
                    <el-form-item
                      label="结束时间"
                      :label-width="formLabelWidth"
                      prop="endTime"
                    >
                      <el-date-picker
                        style="width:200px"
                        v-model="onlineExamForm.endTime"
                        type="datetime"
                        placeholder="选择考试结束时间"
                        @change="getEndTime"
                      >
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="10">
                  <el-col :xs="15" :sm="15" :md="15" :lg="15">
                    <el-form-item
                      label="是否开启"
                      :label-width="formLabelWidth"
                    >
                      <el-radio-group v-model="onlineExamForm.enable">
                        <el-radio label="true">开启</el-radio>
                        <el-radio label="false">关闭</el-radio>
                      </el-radio-group>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-tab-pane>
            </el-tabs>
            <el-tabs v-model="tabs">
              <el-tab-pane label="控制设置" name="first">
                <el-row :gutter="10">
                  <el-col :xs="15" :sm="15" :md="15" :lg="15">
                    <el-form-item
                      label="考试时长"
                      :label-width="formLabelWidth"
                      prop="duration"
                    >
                      <el-input
                        v-model.number="onlineExamForm.duration"
                        auto-complete="off"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="分钟"></el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="10">
                  <el-col :xs="15" :sm="15" :md="15" :lg="15">
                    <el-form-item
                      label="考试次数"
                      :label-width="formLabelWidth"
                      prop="examTimes"
                    >
                      <el-input
                        v-model.number="onlineExamForm.examTimes"
                        auto-complete="off"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="次"></el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="10">
                  <el-col :xs="15" :sm="15" :md="15" :lg="15">
                    <el-form-item
                      label="交卷冻结时间"
                      :label-width="formLabelWidth"
                      prop="freezeTime"
                    >
                      <el-input
                        v-model.number="onlineExamForm.properties.FREEZE_TIME"
                        auto-complete="off"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="分钟"></el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="10">
                  <el-col :xs="15" :sm="15" :md="15" :lg="15">
                    <el-form-item
                      label="断点续考时间"
                      :label-width="formLabelWidth"
                      prop="examReconnectTime"
                    >
                      <el-input
                        v-model.number="
                          onlineExamForm.properties.EXAM_RECONNECT_TIME
                        "
                        auto-complete="off"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="分钟"></el-form-item>
                  </el-col>
                </el-row>
              </el-tab-pane>
            </el-tabs>
            <el-tabs v-model="tabs">
              <el-tab-pane label="显示设置" name="first">
                <el-row :gutter="10" v-if="show_ckeditor">
                  <el-col :xs="15" :sm="15" :md="15" :lg="15">
                    <el-form-item
                      label="考前说明"
                      :label-width="formLabelWidth"
                    >
                      <ckeditor
                        v-model="onlineExamForm.properties.BEFORE_EXAM_REMARK"
                        :height="'100px'"
                      ></ckeditor>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="10" v-if="show_ckeditor">
                  <el-col :xs="15" :sm="15" :md="15" :lg="15">
                    <el-form-item
                      label="考后说明"
                      :label-width="formLabelWidth"
                    >
                      <ckeditor
                        v-model="onlineExamForm.properties.AFTER_EXAM_REMARK"
                        :height="'100px'"
                      ></ckeditor>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="10">
                  <el-col :xs="15" :sm="15" :md="15" :lg="15">
                    <el-form-item
                      label="展示作弊说明"
                      :label-width="formLabelWidth"
                    >
                      <el-radio-group
                        v-model="onlineExamForm.properties.SHOW_CHEATING_REMARK"
                      >
                        <el-radio label="true">开启</el-radio>
                        <el-radio label="false">关闭</el-radio>
                      </el-radio-group>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="10" v-if="show_ckeditor">
                  <el-col :xs="15" :sm="15" :md="15" :lg="15">
                    <el-form-item
                      label="作弊说明"
                      :label-width="formLabelWidth"
                    >
                      <ckeditor
                        v-model="onlineExamForm.properties.CHEATING_REMARK"
                        :height="'100px'"
                      ></ckeditor>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="10">
                  <el-col :xs="15" :sm="15" :md="15" :lg="15">
                    <el-form-item
                      label="单选题补充说明"
                      :label-width="formLabelWidth"
                    >
                      <el-input
                        :disabled="!onlineExamForm.properties.SINGLE_EDIT"
                        v-model="onlineExamForm.properties.SINGLE_ANSWER_REMARK"
                        auto-complete="off"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="" :label-width="formLabelWidth">
                      <el-switch
                        v-model="onlineExamForm.properties.SINGLE_EDIT"
                        on-text="启用"
                        off-text="禁用"
                      ></el-switch>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="10">
                  <el-col :xs="15" :sm="15" :md="15" :lg="15">
                    <el-form-item
                      label="多选题补充说明"
                      :label-width="formLabelWidth"
                    >
                      <el-input
                        :disabled="!onlineExamForm.properties.MUTIPLE_EDIT"
                        v-model="
                          onlineExamForm.properties.MUTIPLE_ANSWER_REMARK
                        "
                        auto-complete="off"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="" :label-width="formLabelWidth">
                      <el-switch
                        v-model="onlineExamForm.properties.MUTIPLE_EDIT"
                        on-text="启用"
                        off-text="禁用"
                      ></el-switch>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="10">
                  <el-col :xs="15" :sm="15" :md="15" :lg="15">
                    <el-form-item
                      label="判断题补充说明"
                      :label-width="formLabelWidth"
                    >
                      <el-input
                        :disabled="!onlineExamForm.properties.BOOL_EDIT"
                        v-model="onlineExamForm.properties.BOOL_ANSWER_REMARK"
                        auto-complete="off"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="" :label-width="formLabelWidth">
                      <el-switch
                        v-model="onlineExamForm.properties.BOOL_EDIT"
                        on-text="启用"
                        off-text="禁用"
                      ></el-switch>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="10">
                  <el-col :xs="15" :sm="15" :md="15" :lg="15">
                    <el-form-item
                      label="填空题补充说明"
                      :label-width="formLabelWidth"
                    >
                      <el-input
                        :disabled="!onlineExamForm.properties.FILL_BLANK_EDIT"
                        v-model="onlineExamForm.properties.FILL_BLANK_REMARK"
                        auto-complete="off"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="" :label-width="formLabelWidth">
                      <el-switch
                        v-model="onlineExamForm.properties.FILL_BLANK_EDIT"
                        on-text="启用"
                        off-text="禁用"
                      ></el-switch>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="10">
                  <el-col :xs="15" :sm="15" :md="15" :lg="15">
                    <el-form-item
                      label="客观题成绩显示"
                      :label-width="formLabelWidth"
                    >
                      <el-radio-group
                        v-model="onlineExamForm.properties.IS_OBJ_SCORE_VIEW"
                      >
                        <el-radio label="true">开启</el-radio>
                        <el-radio label="false">关闭</el-radio>
                      </el-radio-group>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-tab-pane>
            </el-tabs>
            <el-tabs v-model="tabs">
              <el-tab-pane label="人脸识别设置" name="first">
                <el-row :gutter="10">
                  <el-col :xs="15" :sm="15" :md="15" :lg="15">
                    <el-form-item
                      label="是否开启"
                      :label-width="formLabelWidth"
                    >
                      <el-radio-group
                        v-model="onlineExamForm.properties.IS_FACE_ENABLE"
                        @change="faceChange"
                      >
                        <el-radio label="true">开启</el-radio>
                        <el-radio label="false">关闭</el-radio>
                      </el-radio-group>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row
                  :gutter="10"
                  v-show="onlineExamForm.properties.IS_FACE_ENABLE == 'true'"
                >
                  <el-col :xs="15" :sm="15" :md="15" :lg="15">
                    <el-form-item
                      label="考试强制使用"
                      :label-width="formLabelWidth"
                    >
                      <el-radio-group
                        v-model="onlineExamForm.properties.IS_FACE_CHECK"
                      >
                        <el-radio label="true">强制</el-radio>
                        <el-radio label="false">非强制</el-radio>
                      </el-radio-group>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row
                  :gutter="10"
                  v-show="onlineExamForm.properties.IS_FACE_ENABLE == 'true'"
                >
                  <el-col :xs="15" :sm="15" :md="15" :lg="15">
                    <el-form-item
                      label="抓拍间隔"
                      :label-width="formLabelWidth"
                      prop="snapshotInterval"
                    >
                      <el-input
                        v-model.number="
                          onlineExamForm.properties.SNAPSHOT_INTERVAL
                        "
                        auto-complete="off"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="分钟"></el-form-item>
                  </el-col>
                </el-row>
                <el-row
                  :gutter="10"
                  v-show="onlineExamForm.properties.IS_FACE_ENABLE == 'true'"
                >
                  <el-col :xs="15" :sm="15" :md="15" :lg="15">
                    <el-form-item
                      label="预警阀值"
                      :label-width="formLabelWidth"
                      prop="warnThreshold"
                    >
                      <el-input
                        v-model.number="
                          onlineExamForm.properties.WARN_THRESHOLD
                        "
                        auto-complete="off"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="%"></el-form-item>
                  </el-col>
                </el-row>
                <el-row
                  :gutter="10"
                  v-show="onlineExamForm.properties.IS_FACE_ENABLE == 'true'"
                >
                  <el-col :xs="15" :sm="15" :md="15" :lg="15">
                    <el-form-item
                      label="真实性预警阀值"
                      :label-width="formLabelWidth"
                      prop="livingWarnThreshold"
                    >
                      <el-input
                        v-model.number="
                          onlineExamForm.properties.LIVING_WARN_THRESHOLD
                        "
                        auto-complete="off"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="%"></el-form-item>
                  </el-col>
                </el-row>
              </el-tab-pane>
            </el-tabs>
            <el-tabs v-model="tabs">
              <el-tab-pane label="阅卷设置" name="first">
                <el-row :gutter="10">
                  <el-col :xs="15" :sm="15" :md="15" :lg="15">
                    <el-form-item
                      label="阅卷方式"
                      :label-width="formLabelWidth"
                    >
                      <el-radio-group
                        :disabled="onlineExamForm.started"
                        v-model="onlineExamForm.properties.MARKING_TYPE"
                      >
                        <el-radio label="ALL">全部评阅</el-radio>
                        <el-radio label="OBJECT_SCORE_MAX">客观分最高</el-radio>
                        <el-radio label="LAST_SUBMIT">最后一次提交</el-radio>
                      </el-radio-group>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-tab-pane>
            </el-tabs>
            <el-tabs v-model="tabs">
              <el-tab-pane label="网络设置" name="first">
                <el-row :gutter="10">
                  <el-col :xs="15" :sm="15" :md="15" :lg="15">
                    <el-form-item label="IP限制" :label-width="formLabelWidth">
                      <el-radio-group
                        v-model="onlineExamForm.properties.IP_LIMIT"
                      >
                        <el-radio label="true">开启</el-radio>
                        <el-radio label="false">关闭</el-radio>
                      </el-radio-group>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="10">
                  <el-col :xs="15" :sm="15" :md="15" :lg="15">
                    <el-form-item
                      label="IP段( *表示任意 )"
                      :label-width="formLabelWidth"
                    >
                      <el-input
                        style="width:200px"
                        :maxlength="500"
                        type="textarea"
                        autosize
                        v-model="onlineExamForm.properties.IP_ADDRESSES"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-tab-pane>
            </el-tabs>
          </el-form>
        </div>
      </div>
    </section>
  </div>
</template>

<script>
import { exam_work_api, EXAM_TYPE } from "../store/global";
import ckeditor from "../components/ckeditor.vue";

let _this = null;

export default {
  components: { ckeditor },
  data() {
    var validateBeginTime = (rule, value, callback) => {
      if (!_this.onlineExamForm.beginTime) {
        callback(new Error("请选择考试开始日期"));
      } else {
        callback();
      }
    };
    var validateEndTime = (rule, value, callback) => {
      if (!_this.onlineExamForm.endTime) {
        callback(new Error("请选择考试结束日期"));
      } else if (
        _this.onlineExamForm.beginTime > _this.onlineExamForm.endTime
      ) {
        callback(new Error("开始日期不能大于结束日期"));
      } else {
        callback();
      }
    };
    var validateName = (rule, value, callback) => {
      if (_this.onlineExamForm.name == "") {
        callback(new Error("请输入考试名称"));
      } else if (
        !_this.onlineExamForm.name.match(/^[\u4E00-\u9FA5A-Za-z0-9_]+$/)
      ) {
        callback(new Error("只能为英文、汉字、数字"));
      } else if (_this.onlineExamForm.name.length > 50) {
        callback(new Error("最大长度为50"));
      } else {
        callback();
      }
    };
    var validateDuration = (rule, value, callback) => {
      var duration = _this.onlineExamForm.duration;
      if (duration == "") {
        callback(new Error("请输入考试时长"));
      } else if (!duration.match(/^[1-9]\d*|0$/)) {
        callback(new Error("只能是非负整数"));
      } else {
        callback();
      }
    };
    var validateFreezeTime = (rule, value, callback) => {
      var freezeTime = _this.onlineExamForm.properties.FREEZE_TIME;
      var duration = _this.onlineExamForm.duration;
      if (freezeTime == "") {
        callback(new Error("请输入交卷冻结时长"));
      } else if (!freezeTime.match(/^[1-9]\d*|0$/)) {
        callback(new Error("只能是非负整数"));
      } else if (parseInt(freezeTime) > parseInt(duration)) {
        callback(new Error("交卷冻结时长不能大于考试时长"));
      } else {
        callback();
      }
    };
    var validateSnapshot = (rule, value, callback) => {
      var isFaceEnable = _this.onlineExamForm.properties.IS_FACE_ENABLE;
      var snapshotnterval = _this.onlineExamForm.properties.SNAPSHOT_INTERVAL;
      var duration = _this.onlineExamForm.duration;
      if (isFaceEnable == "true") {
        if (snapshotnterval == "") {
          callback(new Error("请输入抓拍间隔"));
        } else if (!snapshotnterval.match(/^[1-9]\d*$/)) {
          callback(new Error("只能是正整数"));
        } else if (parseInt(snapshotnterval) > parseInt(duration)) {
          callback(new Error("抓拍间隔不能大于考试时长"));
        } else {
          callback();
        }
      } else {
        callback();
      }
    };
    var validateWarnThreshold = (rule, value, callback) => {
      var isFaceEnable = _this.onlineExamForm.properties.IS_FACE_ENABLE;
      var warnThreshold = _this.onlineExamForm.properties.WARN_THRESHOLD;
      if (isFaceEnable == "true") {
        if (warnThreshold == "") {
          callback(new Error("请输入预警阀值"));
        } else if (!warnThreshold.match(/^[1-9]\d*$/)) {
          callback(new Error("只能是正整数"));
        } else {
          callback();
        }
      } else {
        callback();
      }
    };
    var validateLivingWarnThreshold = (rule, value, callback) => {
      var isFaceEnable = _this.onlineExamForm.properties.IS_FACE_ENABLE;
      var livingWarnThreshold =
        _this.onlineExamForm.properties.LIVING_WARN_THRESHOLD;
      if (isFaceEnable == "true") {
        if (livingWarnThreshold == "") {
          callback(new Error("请输入真实性预警阀值"));
        } else if (!livingWarnThreshold.match(/^[1-9]\d*$/)) {
          callback(new Error("只能是正整数"));
        } else {
          callback();
        }
      } else {
        callback();
      }
    };
    var validateExamTimes = (rule, value, callback) => {
      var examTimes = _this.onlineExamForm.examTimes;
      if (examTimes == "") {
        callback(new Error("请输入考试次数"));
      } else if (!examTimes.match(/^[1-9]\d*$/)) {
        callback(new Error("只能是正整数"));
      } else {
        callback();
      }
    };
    var validateExamReconnectTime = (rule, value, callback) => {
      var examReconnectTime =
        _this.onlineExamForm.properties.EXAM_RECONNECT_TIME;
      if (examReconnectTime == "") {
        callback(new Error("请输入断点续考时间"));
      } else if (!examReconnectTime.match(/^[1-9]\d*$/)) {
        callback(new Error("只能是正整数"));
      } else {
        callback();
      }
    };

    return {
      tabs: "first",
      show_ckeditor: false,
      onlineExamForm: {
        started: false,
        name: "",
        examType: "ONLINE",
        examTimes: 1,
        beginTime: null,
        endTime: null,
        duration: 120,
        enable: "true",
        properties: {
          IS_OBJ_SCORE_VIEW: "true",
          EXAM_RECONNECT_TIME: 30,
          FREEZE_TIME: 0,
          BEFORE_EXAM_REMARK: "",
          AFTER_EXAM_REMARK: "",
          SHOW_CHEATING_REMARK: "true",
          CHEATING_REMARK: "",
          SINGLE_EDIT: "false",
          MUTIPLE_EDIT: "false",
          BOOL_EDIT: "false",
          FILL_BLANK_EDIT: "false",
          SINGLE_ANSWER_REMARK: "",
          MUTIPLE_ANSWER_REMARK: "",
          FILL_BLANK_REMARK: "",
          BOOL_ANSWER_REMARK: "",
          IS_FACE_ENABLE: "false",
          IS_FACE_CHECK: "false",
          SNAPSHOT_INTERVAL: 30,
          WARN_THRESHOLD: 50,
          MARKING_TYPE: "ALL",
          IP_LIMIT: "false",
          IP_ADDRESSES: null,
          LIVING_WARN_THRESHOLD: 50
        }
      },
      examTypeList: EXAM_TYPE,
      formLabelWidth: "120px",
      examId: "",
      rules: {
        name: [{ required: true, validator: validateName, trigger: "blur" }],
        examType: [
          { required: true, message: "请选择考试类型", trigger: "change" }
        ],
        beginTime: [
          { required: true, validator: validateBeginTime, trigger: "change" }
        ],
        endTime: [
          { required: true, validator: validateEndTime, trigger: "change" }
        ],
        duration: [
          { required: true, validator: validateDuration, trigger: "blur" }
        ],
        freezeTime: [
          { required: true, validator: validateFreezeTime, trigger: "blur" }
        ],
        examTimes: [
          { required: true, validator: validateExamTimes, trigger: "blur" }
        ],
        examReconnectTime: [
          {
            required: true,
            validator: validateExamReconnectTime,
            trigger: "blur"
          }
        ],
        snapshotInterval: [
          { required: true, validator: validateSnapshot, trigger: "blur" }
        ],
        warnThreshold: [
          { required: true, validator: validateWarnThreshold, trigger: "blur" }
        ],
        livingWarnThreshold: [
          {
            required: true,
            validator: validateLivingWarnThreshold,
            trigger: "blur"
          }
        ]
      }
    };
  },

  methods: {
    getBeginTime(val) {
      this.onlineExamForm.beginTime = val;
    },
    getEndTime(val) {
      this.onlineExamForm.endTime = val;
    },
    faceChange() {
      if (this.onlineExamForm.properties.IS_FACE_ENABLE == "false") {
        this.onlineExamForm.properties.SNAPSHOT_INTERVAL = 30;
        this.onlineExamForm.properties.WARN_THRESHOLD = 50;
      }
    },
    init() {
      if (this.examId != "add") {
        var url = exam_work_api + "/exam/" + this.examId;
        this.$http.get(url).then(
          response => {
            var body = response.body;
            body.properties = this.onlineExamForm.properties;
            this.onlineExamForm = Object.assign(
              this.onlineExamForm,
              response.body
            );
            this.onlineExamForm.enable = this.onlineExamForm.enable
              ? "true"
              : "false";
            console.log(
              "getOnlineExam(); onlineExamForm: ",
              this.onlineExamForm
            );

            var url = exam_work_api + "/exam/allProperties/" + this.examId;
            this.$http.get(url).then(
              response => {
                this.onlineExamForm.properties = Object.assign(
                  this.onlineExamForm.properties,
                  response.body
                );
                this.onlineExamForm.properties.SINGLE_EDIT =
                  this.onlineExamForm.properties.SINGLE_EDIT == "true"
                    ? true
                    : false;
                this.onlineExamForm.properties.MUTIPLE_EDIT =
                  this.onlineExamForm.properties.MUTIPLE_EDIT == "true"
                    ? true
                    : false;
                this.onlineExamForm.properties.BOOL_EDIT =
                  this.onlineExamForm.properties.BOOL_EDIT == "true"
                    ? true
                    : false;
                this.onlineExamForm.properties.FILL_BLANK_EDIT =
                  this.onlineExamForm.properties.FILL_BLANK_EDIT == "true"
                    ? true
                    : false;

                this.show_ckeditor = true;
              },
              response => {
                this.$notify({
                  type: "error",
                  message: response.body.desc
                });
              }
            );
          },
          response => {
            this.$notify({
              type: "error",
              message: response.body.desc
            });
          }
        );
      } else {
        this.show_ckeditor = true;
      }
    },
    saveOnlineExam: function() {
      var url = exam_work_api + "/exam";
      console.log(this.onlineExamForm);
      this.$refs.onlineExamForm.validate(valid => {
        if (valid) {
          if (this.examId != "add") {
            this.$http.put(url, this.onlineExamForm).then(
              response => {
                if (200 != response.status) {
                  this.$notify({
                    type: "error",
                    message: response.body.desc
                  });
                  return;
                }
                this.$notify({
                  type: "success",
                  message: "保存成功"
                });
              },
              response => {
                this.$notify({
                  type: "error",
                  message: response.body.desc
                });
              }
            );
          } else {
            this.$http.post(url, this.onlineExamForm).then(
              response => {
                if (200 != response.status) {
                  this.$notify({
                    type: "error",
                    message: response.body.desc
                  });
                  return;
                }
                this.$notify({
                  type: "success",
                  message: "新增成功"
                });
                this.back();
              },
              response => {
                this.$notify({
                  type: "error",
                  message: response.body.desc
                });
              }
            );
          }
        } else {
          return false;
        }
      });
    },
    back() {
      this.$router.push({ path: "/index/examInfo" });
    }
  },
  created() {
    _this = this;
    this.examId = this.$route.params.id;
    this.init();
  }
};
</script>
<style scoped></style>