WANG 6 anos atrás
pai
commit
3cb5ac1349
1 arquivos alterados com 195 adições e 4 exclusões
  1. 195 4
      src/modules/examwork/view/offlineExam.vue

+ 195 - 4
src/modules/examwork/view/offlineExam.vue

@@ -1,14 +1,205 @@
 <template>
-  <div><section class="content"></section></div>
+  <div>
+    <section class="content" style="margin-top: -10px;">
+      <div class="box box-info">
+        <!-- 正文信息 -->
+        <div class="box-body">
+          <el-form
+            :inline="true"
+            :rules="rules"
+            ref="form"
+            :model="form"
+            label-position="right"
+          >
+            <div style="margin-bottom: 10px">
+              <el-button-group>
+                <el-button type="primary" @click="saveExam">保 存</el-button>
+                <el-button @click="back">返 回</el-button>
+              </el-button-group>
+            </div>
+            <el-tabs type="border-card" v-model="activeName">
+              <!-- 基础信息 -->
+              <el-tab-pane label="基础信息" name="tab1">
+                <el-row>
+                  <el-form-item
+                    label="考试名称"
+                    label-width="80px"
+                    placeholder="请输入考试名称"
+                    prop="name"
+                  >
+                    <el-input v-model="form.name"></el-input>
+                  </el-form-item>
+                </el-row>
+                <el-row>
+                  <el-form-item label="考试类型" label-width="80px">
+                    <el-select
+                      style="width:205px"
+                      :disabled="true"
+                      v-model="form.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-row>
+                <el-row>
+                  <el-form-item label="是否开启" label-width="80px">
+                    <el-radio-group
+                      v-model="form.enable"
+                      style="margin-left: 15px"
+                    >
+                      <el-radio label="true">开启</el-radio>
+                      <el-radio label="false">关闭</el-radio>
+                    </el-radio-group>
+                  </el-form-item>
+                </el-row>
+                <el-row>
+                  <el-form-item
+                    label="考试时间"
+                    prop="examDatetimeRange"
+                    label-width="70px"
+                  >
+                    <el-date-picker
+                      style="margin-left: 10px"
+                      v-model="examDatetimeRange"
+                      type="datetimerange"
+                      range-separator="至"
+                      start-placeholder="开始日期"
+                      end-placeholder="结束日期"
+                      value-format="yyyy-MM-dd HH:mm:ss"
+                      :clearable="false"
+                    >
+                    </el-date-picker>
+                  </el-form-item>
+                </el-row>
+              </el-tab-pane>
+            </el-tabs>
+          </el-form>
+        </div>
+      </div>
+    </section>
+  </div>
 </template>
 
 <script>
+import { EXAM_TYPE, EXAM_WORK_API } from "@/constants/constants.js";
+import moment from "moment";
+
+let _this = null;
+
+let validateName = (rule, value, callback) => {
+  let name = _this.form.name;
+  if (name == "") {
+    callback(new Error("请输入考试名称"));
+    _this.activeName = "tab1";
+  } else {
+    callback();
+  }
+};
+
 export default {
   data() {
-    return {};
+    return {
+      activeName: "tab1",
+      examDatetimeRange: [],
+      show_ckeditor: false,
+      form: {
+        started: false,
+        name: "",
+        examType: "OFFLINE",
+        examTimes: 1,
+        beginTime: null,
+        endTime: null,
+        duration: 120,
+        enable: "true",
+        properties: {}
+      },
+      examTypeList: EXAM_TYPE,
+      examId: "",
+      rules: {
+        name: [{ required: true, validator: validateName, trigger: "blur" }]
+      }
+    };
+  },
+
+  methods: {
+    init() {
+      if (this.examId != "add") {
+        let url = EXAM_WORK_API + "/exam/" + this.examId;
+        this.$http.get(url).then(response => {
+          let body = response.data;
+          body.properties = this.form.properties;
+          this.form = Object.assign(this.form, response.data);
+          this.form.enable = this.form.enable ? "true" : "false";
+          this.examDatetimeRange = [this.form.beginTime, this.form.endTime];
+          console.log("getOnlineExam(); form: ", this.form);
+
+          let url = EXAM_WORK_API + "/exam/allProperties/" + this.examId;
+          this.$http.get(url).then(response => {
+            this.form.properties = Object.assign(
+              this.form.properties,
+              response.data
+            );
+            this.show_ckeditor = true;
+          });
+        });
+      } else {
+        let now = moment().format("YYYY-MM-DD HH:mm:ss");
+        this.examDatetimeRange = [now, now];
+        this.show_ckeditor = true;
+      }
+    },
+    saveExam: function() {
+      this.form.beginTime = this.examDatetimeRange[0];
+      this.form.endTime = this.examDatetimeRange[1];
+      console.log(this.form);
+      let url = EXAM_WORK_API + "/exam";
+      this.$refs.form.validate(valid => {
+        if (valid) {
+          if (this.examId != "add") {
+            this.$http.put(url, this.form).then(response => {
+              if (200 != response.status) {
+                this.$notify({
+                  type: "error",
+                  message: response.body.desc
+                });
+                return;
+              }
+              this.$notify({
+                type: "success",
+                message: "保存成功"
+              });
+            });
+          } else {
+            this.$http.post(url, this.form).then(response => {
+              console.log(response);
+              this.$notify({
+                type: "success",
+                message: "新增成功"
+              });
+              this.back();
+            });
+          }
+        } else {
+          return false;
+        }
+      });
+    },
+    back() {
+      this.$router.push({ path: "/examwork/examInfo" });
+    }
   },
-  methods: {},
-  created() {}
+  created() {
+    _this = this;
+    this.examId = this.$route.params.id;
+    this.init();
+  }
 };
 </script>
 <style scoped></style>