From df26c5424389cbd7fb1aa28a610b124cbac26c54 Mon Sep 17 00:00:00 2001
From: liuyg <376836862@qq.com>
Date: Sat, 09 Oct 2021 16:23:39 +0800
Subject: [PATCH] +

---
 src/views/startexam/index.vue |  306 +++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 272 insertions(+), 34 deletions(-)

diff --git a/src/views/startexam/index.vue b/src/views/startexam/index.vue
index cb39537..cd275b0 100644
--- a/src/views/startexam/index.vue
+++ b/src/views/startexam/index.vue
@@ -39,13 +39,13 @@
                       >答题卡</el-button
                     >
                   </div>
-                  <el-button
+                  <!-- <el-button
                     type="success"
                     icon="el-icon-date"
                     @click="submitExam"
                     v-bind:disabled="disableSubmit"
                     >提交</el-button
-                  >
+                  > -->
                 </div>
               </el-col>
               <el-col :span="18">
@@ -86,12 +86,18 @@
                       type="primary"
                       >下一题</el-button
                     >
+                    <!-- :disabled="timesIT" -->
                     <el-button
                       type="success"
-                      style="display: none"
                       @click="submitExam"
-                      v-bind:disabled="disableSubmit"
-                      >提交</el-button
+                      :title="
+                        timesIT
+                          ? '根据国家考试要求,30分钟内不可提交! 剩(' +
+                            timesITValue +
+                            ')分钟'
+                          : '点击完成考试'
+                      "
+                      >完成考试 {{ time }}</el-button
                     >
                   </div>
                 </div>
@@ -104,6 +110,7 @@
               top="10vh"
               :modal="false"
               center
+              class="datika"
             >
               <div class="answer-card-title">
                 {{ exam.examinationName }}(共{{
@@ -127,6 +134,7 @@
                   :key="index"
                   >&nbsp;{{ index + 1 }}&nbsp;</el-button
                 >
+                <!-- @click="toSubject(value.everyID, value.type, index)" -->
               </el-row>
             </el-dialog>
           </div>
@@ -139,7 +147,7 @@
 import { mapState } from "vuex";
 import CountDown from "vue2-countdown";
 import { saveAndNext } from "@/api/exam/answer";
-import { getSubjectIds } from "@/api/exam/exam";
+import { getSubjectIds, getSubjectRefresh } from "@/api/exam/exam";
 import { getCurrentTime } from "@/api/exam/examRecord";
 import { getSubjectResultInfo } from "@/api/exam/subject";
 
@@ -217,14 +225,36 @@
         newRecord: false,
       },
       firstFlag: true,
+      times: ["30", "00"],
+      timeOut: null,
+      timeOTiv: null,
+      timesIT: true,
+      timesITValue: 0,
+      first: true,
     };
   },
   computed: {
     ...mapState({
       userInfo: (state) => state.user.userInfo,
+      scoreId: (state) =>
+        state.exam.scoreId
+          ? state.exam.scoreId
+          : window.localStorage.getItem("scoreId"),
     }),
+    time() {
+      var d = [+this.times[0], +this.times[1]];
+    },
   },
   created() {
+    if (window.name == "") {
+      // console.log("首次被加载");
+      window.name = "first"; // 在首次进入页面时我们可以给window.name设置一个固定值
+      this.first = true;
+    } else if (window.name == "first") {
+      // console.log("页面被刷新");
+      this.first = false;
+    }
+
     const examInfo = this.$route.params.id;
 
     if (isNotEmpty(examInfo)) {
@@ -253,6 +283,43 @@
       messageSuccess(this, "考试开始");
       this.startTime = this.getCurrentTimes();
     },
+    bottonControl(time) {
+      //倒计时循环
+      let times = time * 60;
+      var setTime = function (time) {
+        let a, b, d;
+        a = parseInt(time / 60);
+        b = time - a * 60;
+        d = a + ":" + b;
+        return d;
+      };
+      if (this.timeOTiv == null) {
+        this.timeOTiv = setInterval((res) => {
+          times--;
+          this.timesITValue = setTime(times);
+        }, 1000);
+      } else {
+        clearTimeout(this.timeOTiv);
+        this.timeOTiv = null;
+        this.timeOTiv = setInterval((res) => {
+          times--;
+          this.timesITValue = setTime(times);
+        }, 1000);
+      }
+      //倒计时定时
+      if (this.timeOut == null) {
+        this.timeOut = setTimeout((res) => {
+          this.timesIT = false;
+          this.timesITValue--;
+        }, time * 3600);
+      } else {
+        clearTimeout(this.timeOut);
+        this.timeOut = null;
+        this.timeOut = setTimeout((res) => {
+          this.timesIT = false;
+        }, time * 3600);
+      }
+    },
     validateExamTime() {
       getCurrentTime()
         .then((response) => {
@@ -262,26 +329,188 @@
           } else if (currentTime.isBefore(this.exam.startTime)) {
             messageWarn(this, "考试未开始");
           } else {
-            this.startExam();
-            const current = currentTime.valueOf();
-            this.currentTime = current;
-            this.startTime = current;
-            this.subjectStartTime = current;
-            // this.endTime = moment(this.exam.endTime).valueOf()
-            this.endTime = current + 60 * 60 * 1000;
-            // this.endTime = current + 1 * 60 * 1000;
-            this.disableSubmit = false;
+            //判断是否是答过题
+            this.startExam(currentTime);
+            //判断是否是答过题
+            if (this.first) {
+              const current = currentTime.valueOf();
+              // console.log(current, "首次");
+              this.currentTime = current;
+              this.startTime = current;
+              this.subjectStartTime = current;
+              //   // this.endTime = moment(this.exam.endTime).valueOf()
+              this.endTime = current + 60 * 60 * 1000;
+              this.bottonControl(60);
+            }
+            // this.disableSubmit = false;
           }
         })
         .catch(() => {
           messageFail(this, "开始考试失败!15");
         });
     },
-    startExam() {
+    startExam(currentTime) {
+      var scoreId = window.localStorage.getItem("scoreId");
+      console.log(scoreId, this.first, "scoreIdscoreIdscoreIdscoreId");
+      this.subjectIds = [];
+      // if (this.first) {
+      //   const current = currentTime.valueOf();
+      //   console.log(current, "首次");
+      //   this.currentTime = current;
+      //   this.startTime = current;
+      //   this.subjectStartTime = current;
+      //   //   // this.endTime = moment(this.exam.endTime).valueOf()
+      //   this.endTime = current + 60 * 60 * 1000;
+      // }
+      if (!this.first) {
+        getSubjectRefresh(scoreId).then((obj) => {
+          const objs = obj.data.data;
+          console.log(objs, "objobjobjobjobjobj");
+          const subjectData = objs.examSubjectChoicesVOSList;
+          if (subjectData.length > 0) {
+            //重载题目
+            for (let i = 0; i < subjectData.length; i++) {
+              this.subjectIds.push({
+                subjectId: 1,
+                everyID: subjectData[i].id,
+                type: subjectData[i].choicesType,
+                index: i + 1,
+                answered: false,
+                answer: "",
+                score: subjectData[i].score,
+                color: "#fff",
+                fontColor: "#000",
+              });
+            }
+            //题目类型
+            // this.query.type = parseInt(this.subjectIds[0].type);
+            // 题目id
+            // this.query.subjectId = this.subjectIds[0].everyID;
+            this.updateSubjectIndex();
+            // 获取当前题目信息
+            getSubjectResultInfo({
+              id: this.subjectIds[0].everyID,
+            })
+              .then((response) => {
+                if (isNotEmpty(response.data.data)) {
+                  response.data.data.answer = "";
+                  this.setSubjectInfo(response.data.data);
+                }
+              })
+              .catch(() => {
+                messageFail(this, "获取题目失败!");
+              });
+
+            //重载到当前题目
+            const nowObj = objs.examSubjectChoicesVO;
+            for (var i = 0; i < this.subjectIds.length; i++) {
+              if (nowObj.id == this.subjectIds[i].everyID) {
+                //定位显示题目
+                this.subjectIndex = i + 1;
+                //题目类型
+                this.query.type = parseInt(this.subjectIds[i].type);
+                // 题目id
+                this.query.subjectId = this.subjectIds[i].everyID;
+              }
+            }
+            // 添加到答题卡
+            const anSwer = objs.examAnswerRecordList;
+            for (var i = 0; i < this.subjectIds.length; i++) {
+              for (var n = 0; n < anSwer.length; n++) {
+                // console.log(anSwer[i].subjectChoicesId);
+                if (anSwer[n].subjectChoicesId == this.subjectIds[i].everyID) {
+                  if (anSwer[n].answerResult == 1) {
+                    this.subjectIds[i].color = "#67C23A";
+                    this.subjectIds[i].fontColor = "#fff";
+                  }
+                  if (anSwer[n].answerResult == 2) {
+                    this.subjectIds[i].color = "red";
+                    this.subjectIds[i].fontColor = "#fff";
+                  }
+                  var test = /,/g;
+                  if (test.test(anSwer[n].answerOption)) {
+                    let ans = anSwer[n].answerOption.split(","),
+                      anw = [];
+                    for (var k = 0; k < ans.length; k++) {
+                      anw.push({
+                        key: k + 1,
+                        value: ans[k],
+                      });
+                    }
+                    this.subjectIds[i].answer = anw;
+                  } else {
+                    this.subjectIds[i].answer = anSwer[n].answerOption;
+                  }
+                  // console.log(anSwer[n].answerOption, 1);
+                  // console.log(this.subjectIds[i].answer, 2);
+                }
+              }
+            }
+            //适应时间
+            const datyTime = objs.examScore.examTime;
+            var duibiTime = function (newTime, oldTime) {
+              var newYear = newTime.split(" ")[0],
+                newDat = newTime.split(" ")[1],
+                oldYear = oldTime.split(" ")[0],
+                oldDat = oldTime.split(" ")[1];
+              if (newYear !== oldYear) {
+                return false;
+              } else {
+                let newD = {
+                  s: +newDat.split(":")[0],
+                  f: +newDat.split(":")[1],
+                  m: +newDat.split(":")[2],
+                };
+                let oldD = {
+                  s: +oldDat.split(":")[0],
+                  f: +oldDat.split(":")[1],
+                  m: +oldDat.split(":")[2],
+                };
+                if (newD.s - oldD.s > 1) {
+                  return false;
+                } else if (newD.s - oldD.s == 1) {
+                  if (newD.f < oldD.f) {
+                    return oldD.f - newD.f;
+                  } else {
+                    return false;
+                  }
+                } else if (newD.s == oldD.s) {
+                  return 60 - (newD.f - oldD.f);
+                }
+                return [newD, oldD];
+              }
+              // return false;
+            };
+            var listTime = duibiTime(currentTime._i, datyTime);
+            // console.log(listTime, "listTimelistTimelistTime");
+            const current = currentTime.valueOf();
+            this.currentTime = current;
+            this.startTime = current;
+            this.subjectStartTime = current;
+            // // this.endTime = moment(this.exam.endTime).valueOf()
+            if (listTime) {
+              this.endTime = current + listTime * 60 * 1000;
+              this.bottonControl(listTime - 30);
+            } else {
+              this.endTime = current + 0 * 60 * 1000;
+              this.bottonControl(0);
+            }
+            // console.log(datyTime, currentTime, "刷新");
+          }
+        });
+        // this.first = true;
+        return;
+      }
+      // console.log(this.subjectIds);
       // 获取题目ID列表
-      getSubjectIds()
+      getSubjectIds(scoreId)
         .then((subjectResponse) => {
           const subjectData = subjectResponse.data.data;
+          console.log(
+            subjectResponse,
+            "subjectResponsesubjectResponsesubjectResponse"
+          );
+          console.log(subjectData, "subjectDatasubjectDatasubjectData");
           if (subjectData.length > 0) {
             for (let i = 0; i < subjectData.length; i++) {
               this.subjectIds.push({
@@ -357,7 +586,10 @@
       for (let i = 0; i < this.subjectIds.length; i++) {
         if (this.subjectIds[i].everyID == this.query.subjectId) {
           if (this.getAnswer() == "") {
-            messageSuccess(this, "请选择答案");
+            this.$message({
+              message: "请选择答案",
+              type: "warning",
+            });
             return;
           }
 
@@ -388,35 +620,34 @@
     saveCurrentSubjectAndGetNextSubject(nextType, nextSubjectId, subjectIds) {
       this.startLoading(nextType);
 
-
-      console.log()
+      // console.log();
 
       var answerData = this.getAnswer();
 
-      var str = '';
+      var str = "";
 
       if (Array.isArray(answerData)) {
-        answerData.forEach(item => {
-          str += item.value + ','
-        })
+        answerData.forEach((item) => {
+          str += item.value + ",";
+        });
 
         str = str.substr(0, str.length - 1);
 
-        answerData = str
+        answerData = str;
       }
-
 
       var data = {
         id: nextSubjectId,
         preSubJectId: this.query.subjectId,
         preResult: answerData,
+        scoreId: this.scoreId,
       };
       getSubjectResultInfo(data)
         .then((response) => {
           if (response.data.data !== null) {
             // 保存成功后更新答题卡状态
             const subject = response.data.data;
-
+            console.log(subject.answer, 123456);
             //结果
             this.result = response.data.data.result;
 
@@ -538,9 +769,9 @@
       this.subjectIndex = index + 1;
       this.firstFlag = true;
       // 保存当前题目,同时加载下一题
-      console.log(nextSubjectType.next,111);
-      console.log(everyID,222);
-      console.log(type,333);
+      console.log(nextSubjectType.next, 111);
+      console.log(everyID, 222);
+      console.log(type, 333);
       this.saveCurrentSubjectAndGetNextSubject(
         nextSubjectType.next,
         everyID,
@@ -551,6 +782,7 @@
     },
     // 提交
     submitExam(val) {
+      console.log(val);
       var ind = this.subjectIndex;
 
       if (this.firstFlag == false) {
@@ -596,8 +828,11 @@
         examResultVOS: null,
       };
       var arr = [];
-      this.subjectIds.forEach((item) => {
-        if (item.type == 3) {
+      // console.log(this.subjectIds);
+      for (var i = 0; i < this.subjectIds.length; i++) {
+        let item = this.subjectIds[i];
+        // console.log(item.answer, i);
+        if (item.type == 3 || item.type == 1) {
           var str = "";
 
           if (item.answer.length > 0) {
@@ -622,9 +857,12 @@
             grade: item.score,
           });
         }
-      });
-
+      }
+      console.log(arr);
+      // return;
       obj.examResultVOS = arr;
+      // console.log(this.subjectIds);
+      // console.log(obj.examResultVOS);
 
       saveAndNext(obj)
         .then((response) => {

--
Gitblit v1.9.3