From c4e651ac030ef5fe8870f6974fcc4658d42986c6 Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期四, 21 三月 2024 14:35:01 +0800
Subject: [PATCH] 图书列表,详情页、答题器样式修改,代码合并上传测试服

---
 packageBookService/pages/bookServices/examination/examination.js |  588 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 549 insertions(+), 39 deletions(-)

diff --git a/packageBookService/pages/bookServices/examination/examination.js b/packageBookService/pages/bookServices/examination/examination.js
index a880c26..3bec06c 100644
--- a/packageBookService/pages/bookServices/examination/examination.js
+++ b/packageBookService/pages/bookServices/examination/examination.js
@@ -29,12 +29,34 @@
     total: 0,   // 棰樼洰鎬绘暟
     cardList: [],  // 鎻愪氦椤�,
     questionDataList: [],  // 鏄剧ず棰樼洰鍒楄〃
+    mockid: 0,
+    uuid: 0,
+    mockData: {
+      // 缁勫嵎淇℃伅
+      state: '0',
+      score: 0, // 鎬诲垎
+      sumTime: 0,
+      time: 0, // 绛旈鍓╀綑鏃堕棿
+      datas: [], // 鎵�鏈夋ā鑰冭褰曟暟鎹�(棰樼洰鍒楄〃锛岀敤鎴风瓟棰橈紝鑰冭瘯鎶ュ憡)
+      answer: []
+    },
+    saveTime: 20,
+    isNight: false
   },
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
    */
   onLoad(options) {
+    // wx.enableAlertBeforeUnload({
+    //   message: "鏈彁浜わ紝鏄惁閫�鍑虹瓟棰橈紵",
+    //   success: function (res) {
+    //     console.log('纭畾', res);
+    //   },
+    //   fail: function (err) {
+    //     console.log("澶辫触锛�", err);
+    //   },
+    // });
     const systInfo = wx.getSystemInfoSync();
     const menu = wx.getMenuButtonBoundingClientRect(); // 鑳跺泭淇℃伅
     const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 瀵艰埅鏍忛珮搴�
@@ -46,8 +68,14 @@
       productLinkPath: options.productLinkPath ? options.productLinkPath : '',
       rootCmsItemId: options.rootCmsItemId,
       idPathList: options.idPathList ? JSON.parse(options.idPathList) : [],
-      answerType: options.answerType
+      answerType: options.answerType,
     });
+    if (this.data.answerType == 'mock') {
+      this.setData({
+        uuid: options.uuid,
+        mockid: options.mockid
+      })
+    }
     this.init()
     console.log('浼犲弬', options);
   },
@@ -56,27 +84,37 @@
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚
    */
   onReady() {
-
   },
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず
    */
   onShow() {
-
+    if (this.data.answerType == 'mock') {
+      if (wx.timer) {
+        clearInterval(wx.timer)
+      }
+      wx.timer = setInterval(() => {
+        this.setData({
+          saveTime: this.data.saveTime - 1
+        })
+        if (this.data.saveTime == 0) {
+          this.saveMockData()
+        }
+      }, 1000)
+    }
   },
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰闅愯棌
    */
   onHide() {
-
   },
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍗歌浇
    */
-  onUnload() {
+  onUnload(e) {
     if (this.data.countdownInterval !== null) {
       clearInterval(this.data.countdownInterval)
     }
@@ -101,11 +139,37 @@
    */
   onShareAppMessage() {
   },
-  // 杩斿洖
-  goBack() {
-    wx.navigateBack();
+
+  // 鐩戝惉watch
+  watch(context, variableName, callback) {
+    let value = context.data[variableName]; // 鑾峰彇琚洃鍚睘鎬х殑褰撳墠鍊�
+
+    // 浣跨敤 Object.defineProperty 鏂规硶鍦ㄦ暟鎹璞′笂瀹氫箟灞炴�х殑 getter 鍜� setter
+    Object.defineProperty(context.data, variableName, {
+      configurable: true, // 鍙厤缃�
+      enumerable: true, // 鍙灇涓�
+      get: function () {
+        return value; // 杩斿洖灞炴�х殑褰撳墠鍊�
+      },
+      set: function (newVal) {
+        const oldVal = value; // 璁板綍灞炴�х殑鏃у��
+        value = newVal; // 鏇存柊灞炴�х殑鍊�
+        callback.call(context, newVal, oldVal); // 璋冪敤鍥炶皟鍑芥暟锛屼紶閫掓柊鍊煎拰鏃у��
+      }
+    });
   },
 
+  // 杩斿洖
+  goBack() {
+    console.log(this.data.submitStatus);
+    wx.navigateBack();
+  },
+  //璁剧疆鑳屾櫙鑹�
+  changeBGColor(e) {
+    this.setData({
+      isNight: e.detail.value
+    })
+  },
   // 鑾峰彇淇濆瓨鐨勫�掕鏃舵椂闂�
   getSavedTime() {
     const savedTime = wx.getStorageSync('countdownTime')
@@ -165,14 +229,14 @@
     this.setData({
       currentIndex: e.detail.index
     })
-    let index = e.detail.index - 1 >= 0 ? e.detail.index - 1 : 0
-    let flag = this.isHaveAnswer(this.data.questionDataList[index].userAnswer)
-    if (flag) this.handleQuestion(e.detail.index)
-
+    if (this.data.answerType == 'collectQuestion' || this.data.answerType == 'errorQuestion') {
+      let index = e.detail.index - 1 >= 0 ? e.detail.index - 1 : 0
+      let flag = this.isHaveAnswer(this.data.questionDataList[index].userAnswer)
+      if (flag) this.handleQuestion(e.detail.index)
+    }
   },
   // 鐐瑰嚮绛旈鍗¤烦杞鐩�
   goQuestion(e) {
-    console.log(e);
     const id = e.detail.id
     this.data.questionDataList.forEach((item, index) => {
       if (item.id == id) {
@@ -191,12 +255,17 @@
     questionList.forEach(item => {
       if (item.id == id) {
         item.userAnswer = radioChecked
+        item.isUserAnswer = this.isHaveAnswer(radioChecked)
       }
     })
     this.setData({
       questionDataList: questionList
     })
-    console.log(this.data.questionDataList);
+    if (this.data.answerType == 'mock') {
+      this.setData({
+        saveTime: 20
+      })
+    }
   },
   // 杈撳叆妗嗚Е鍙�
   onChangeInput(e) {
@@ -206,13 +275,18 @@
     const questionList = this.data.questionDataList
     questionList.forEach(item => {
       if (item.id == id) {
-        item.userAnswer[index] = inputData
+        item.userAnswer[index] = inputData,
+          item.isUserAnswer = this.isHaveAnswer(item.userAnswer)
       }
     })
     this.setData({
       questionDataList: questionList
     })
-    console.log(this.data.questionDataList);
+    if (this.data.answerType == 'mock') {
+      this.setData({
+        saveTime: 20
+      })
+    }
   },
   // 鏁扮粍杞负瀛楃涓叉柟娉�
   arrayToString(data) {
@@ -237,37 +311,79 @@
       } else {
         return false
       }
-    } else {
+    } else if (typeof data == 'object') {
       const answer = data.find((item) => item.length > 0)
       if (answer) {
         return true
       } else {
         return false
       }
+    } else {
+      return false
     }
   },
   // 鎻愪氦閫昏緫
   submitPaper() {
+    // 鍏抽棴閫�鍑洪〉闈㈢洃鍚�
+    wx.disableAlertBeforeUnload()
     this.setData({
       submitStatus: true
     })
+    const child = this.selectComponent('#question-options')
+    if (this.data.answerType == 'option' || this.data.answerType == 'errorQuestion' || this.data.answerType == 'mock') {
+      // 鍏堥亶鍘嗘墍鏈夐鐩紝灏嗘湭鎵规敼鐨勯鐩壒鏀�
+      const qustionList = this.data.questionDataList
+      for (let index = 0; index < qustionList.length; index++) {
+        const item = qustionList[index];
+        if (!item.isComplete) this.handleQuestion(index + 1)
+      }
+    }
     if (this.data.answerType == 'option') {
       this.toggleCountdown()
-      const child = this.selectComponent('#question-options')
-      if (this.data.answerType == 'option' || this.data.answerType == 'errorQuestion') {
-        // 鍏堥亶鍘嗘墍鏈夐鐩紝灏嗘湭鎵规敼鐨勯鐩壒鏀�
-        const qustionList = this.data.questionDataList
-        for (let index = 0; index < qustionList.length; index++) {
-          const item = qustionList[index];
-          if (!item.isComplete) this.handleQuestion(index + 1)
-        }
-      }
-      if (this.data.answerType == 'option') {
-        this.recordAnswerData()
-        child.openTestReportDialog()
-      }
+      this.recordAnswerData()
+      child.openTestReportDialog()
     } else if (this.data.answerType == 'collectQuestion' || this.data.answerType == 'errorQuestion') {
       this.goBack()
+    } else if (this.data.answerType == 'mock') {
+      this.toggleCountdown()
+      // 璁剧疆妯¤�冪姸鎬佷负宸插畬鎴�
+      const mockData = this.data.mockData
+      mockData.datas.forEach((item) => {
+        if (item.id == this.data.uuid) {
+          item.state = '3'
+          item.report = {
+            userScore: this.data.subjectiveNum
+          }
+        }
+      })
+      this.setData({
+        mockData: mockData,
+        submitStatus: true
+      })
+      this.setMockInfo(mockData.datas)
+      // 璁板綍鐢ㄦ埛绛旈鏁版嵁
+      let saveData = []
+      for (let index = 0; index < this.data.questionDataList.length; index++) {
+        const item = this.data.questionDataList[index];
+        saveData.push({
+          id: item.id,
+          answer: item.userAnswer,
+          isRight: item.isRight
+        })
+      }
+      app.MG.identity.setUserKey({
+        setKeyRequests: [
+          {
+            domain: 'mockAnswerData',
+            key: this.data.uuid,
+            value: JSON.stringify({
+              time: this.data.countdownTime,
+              answerData: saveData
+            })
+          }
+        ]
+      })
+      child.openTestReportDialog()
     }
 
   },
@@ -296,6 +412,47 @@
       // loadings.value = true
       await this.getErrorIdList()
       await this.getCollectIdList() // 鑾峰彇鏀惰棌id鍒楄〃
+    } else if (this.data.answerType == 'mock') {
+      this.getErrorList()
+      this.getCollectIdList()
+      this.getMockInfo(async (res) => {
+        let mocklist
+        try {
+          mocklist = JSON.parse(res[0].value)
+        } catch (error) {
+          mocklist = []
+        }
+        if (mocklist.length && this.data.uuid) {
+          const oldMockData = mocklist.find((mockItem) => mockItem.id == this.data.uuid)
+          this.setData({
+            'mockData.state': oldMockData.state,
+            'mockData.score': oldMockData.score,
+            'mockData.datas': mocklist,
+          })
+          if (oldMockData.state == '0') {
+            // 缁勫嵎璐拱浜嗭紝浣嗘湭杩涘叆椤甸潰
+            await this.getEduQuizConfig()
+          } else if (oldMockData.state == '1' || oldMockData.state == '2' || oldMockData.state == '3') {
+            // 缁勫嵎鍚庤繘鍏ヨ繃椤甸潰锛屼絾鏄湭绛旇繃棰�
+            let oldQuestionList = []
+            oldQuestionList = await this.getMockQuestionList()
+            const userAnswerList = await this.getMockAnswer()
+            await this.getMockDataList(oldQuestionList, userAnswerList)
+            this.setData({
+              'mockData.sumTime': oldMockData.time,
+              cardList: oldQuestionList
+            })
+          }
+          if (oldMockData.state == '0' || oldMockData.state == '1' || oldMockData.state == '2') {
+            this.startCountdown()
+          }
+          if (oldMockData.state == '3') {
+            this.setData({
+              submitStatus: true
+            })
+          }
+        }
+      })
     }
   },
   async restart() {
@@ -327,9 +484,9 @@
         setKeyRequests: [
           {
             domain: 'mockAnswerData',
-            key: route.query.uuid,
+            key: this.data.uuid,
             value: JSON.stringify({
-              time: countDownRef.value.countdownTime,
+              time: this.data.countdownTime,
               answerData: []
             })
           }
@@ -369,6 +526,7 @@
               let value = JSON.parse(res[0].value)
               // 鏈夌瓟棰樿褰曪紝寰楀垎璧嬪��
               if (value) {
+                wx.disableAlertBeforeUnload()
                 this.setData({
                   submitStatus: true
                 })
@@ -382,6 +540,7 @@
               this.setData({
                 currentIndex: value.currentIndex
               })
+              console.log(this.data.submitStatus);
               // 鎼哄甫绛旈璁板綍 鑾峰彇棰樼洰
               await this.getQuestionList(value.dataList)
             } else {
@@ -492,6 +651,7 @@
                 item.Embedded_QuestionBank_QuestionType == 'multipleChoice'
                 ? []
                 : '',
+            isUserAnswer: oldObj ? this.isHaveAnswer(oldObj.userAnswer) : false,
             isRight: oldObj ? oldObj.isRight : null,
             isComplete: oldObj ? oldObj.isComplete : false,
             isCollect: this.data.collectList.indexOf(item.id) > -1 ? true : false,
@@ -573,7 +733,7 @@
             aitem.infoList.forEach((bitem, bindex) => {
               questionList.push(bitem)
               bitem.number = bindex + 1
-              bitem.grade = 2
+              bitem.score = 2
             })
           })
           this.setData({
@@ -587,7 +747,7 @@
       loading: false,
     })
   },
-  // 鎵规敼棰樼洰 锛堢粌涔狅紝鎴戠殑閿欓锛屾垜鐨勬敹钘忥級
+  // 鎵规敼棰樼洰 锛堢粌涔狅紝鎴戠殑閿欓锛屾垜鐨勬敹钘�,锛岀粍鍗凤級
   handleQuestion(num) {
     const questionList = this.data.questionDataList
     const index = num - 1 >= 0 ? num - 1 : 0
@@ -635,13 +795,13 @@
     if (item.questionType != 'shortAnswer') {
       this.setData({
         subjectiveTotal: this.data.subjectiveTotal + 1,
-        subjectiveGrade: this.data.subjectiveGrade + item.grade
+        subjectiveGrade: this.data.subjectiveGrade + item.score
       })
     }
     if (questionList[index].isRight && item.questionType != 'shortAnswer') {
       // 瀹㈣棰樺洖绛旀纭�
       this.setData({
-        subjectiveNum: this.data.subjectiveNum + item.grade,
+        subjectiveNum: this.data.subjectiveNum + item.score,
         correctNum: this.data.correctNum + 1
       })
     }
@@ -675,6 +835,7 @@
           console.log(res)
         })
     }
+
     this.setData({
       questionDataList: questionList
     })
@@ -689,7 +850,6 @@
     this.setData({
       cardList: cardUpdatedList
     })
-    // console.log(this.data.questionDataList, this.data.cardList);
   },
   // 棰樼洰鏀惰棌鎸夐挳,鏀惰棌鍜屽彇娑堝悓涓�鎺ュ彛锛屽彇娑堟暟缁勫噺鍘昏椤筰d
   setCollect() {
@@ -841,7 +1001,6 @@
             }
           })
         }
-        // console.log('鏀惰棌', collectList.value)
       })
   },
   // 鑾峰彇鏀惰棌澶�
@@ -1118,6 +1277,357 @@
       })
     })
     // loadings.value = false
-    // console.log('閿欓闆�', topicList.value)
+  },
+  // 鑾峰彇缁勫嵎缁撴灉
+  async getEduQuizConfig() {
+    await app.MG.edu
+      .getEduQuizConfigResult({
+        idOrRefCode: this.data.mockid
+      })
+      .then(async (configRes) => {
+        // 鑾峰彇 鍒嗘暟 鏃堕棿
+        this.setData({
+          'mockData.score': configRes.score
+        })
+        try {
+          this.setData({
+            'mockData.time': JSON.parse(configRes.config).time * 1000,
+            countdownTime: JSON.parse(configRes.config).time * 1000
+          })
+        } catch (error) {
+          this.setData({
+            'mockData.time': 3600 * 1000,
+            countdownTime: 3600 * 1000,
+          })
+        }
+        this.setData({
+          'mockData.sumTime': this.data.mockData.time
+        })
+        let itemIds = []
+        let numberIndex = 1
+        // 鑾峰彇鎶介缁撴灉
+        const cardList = configRes.eduQuizConfigStageResultList.map((item) => {
+          let questionIds = []
+          // 鑾峰彇蹇呭惈棰樼洰
+          let list = item.cmsItemList.map((idItem) => {
+            itemIds.push(idItem.id + '')
+            questionIds.push({ id: idItem.id + '', score: idItem.score })
+            numberIndex++
+            return {
+              number: numberIndex,
+              id: idItem.id,
+              score: idItem.score
+            }
+          })
+          // 鑾峰彇鎶介棰樼洰
+          let extractList = []
+          for (let i = 0; i < item.generatorResultList.length; i++) {
+            const extractItem = item.generatorResultList[i]
+            let extractItemList = extractItem.cmsItemList.map((extractCmsItem) => {
+              itemIds.push(extractCmsItem.id + '')
+              questionIds.push({ id: extractCmsItem.id + '', score: extractCmsItem.score })
+              numberIndex++
+              return {
+                number: numberIndex,
+                id: extractCmsItem.id,
+                score: extractCmsItem.score
+              }
+            })
+            extractList = extractList.concat(extractItemList)
+          }
+          return {
+            path: item.id,
+            catalogName: item.name,
+            infoList: list.concat(extractList)
+          }
+        })
+        this.setData({
+          cardList: cardList
+        })
+        // 鏇存柊璇ユ潯缁勫嵎鐨勬暟鎹姸鎬侊紝鍖呮嫭璁板綍鏀硅瘯鍗锋�诲垎锛屾洿鏀圭粍鍗风姸鎬乻tate涓�1锛岃〃绀哄凡缁忔娊棰樺畬鎴愶紝骞惰灏嗘娊灞夋暟鎹褰曚笅鏉�
+        if (this.data.mockData.datas && this.data.mockData.datas.length) {
+          const mockData = this.data.mockData
+          mockData.datas.forEach((item, index) => {
+            if (item.id == this.data.uuid) {
+              item.state = '1'
+              item.time = mockData.time
+              item.score = configRes.score
+              mockData.state = '1'
+            }
+          })
+          this.setData({
+            mockData: mockData
+          })
+        }
+        this.setMockInfo(this.data.mockData.datas) // 璁板綍璇曞嵎鎬诲垎 鏃堕暱锛屼慨鏀箂tate涓� 1
+        // 鏇存柊鏈湴mockData
+        this.saveMockQuestionList(this.data.cardList) // 璁板綍棰樼洰鍒楄〃
+        await this.getMockDataList(this.data.cardList) // 璇锋眰棰樼洰鏁版嵁
+      })
+  },
+  // 鑾峰彇缁勫嵎棰樼洰鍒楄〃
+  async getMockDataList(questionList, oldList) {
+    const questionDataList = this.data.questionDataList
+    questionList.forEach(async (pathitem, pathindex) => {
+      let itemIds = []
+      pathitem.infoList.forEach(item => {
+        itemIds.push(item.id + '')
+      })
+      let query = {
+        path: '*',
+        cmsPath: this.data.rootCmsItemId,
+        cmsType: '*',
+        productId: this.data.bookId,
+        queryType: '*',
+        itemIds,
+        itemFields: {
+          Embedded_QuestionBank_Stem: [],
+          Embedded_QuestionBank_AnalysisCon: [],
+          Embedded_QuestionBank_Answer: [],
+          Embedded_QuestionBank_Option: [],
+          Embedded_QuestionBank_QuestionType: [],
+          Embedded_QuestionBank_StemStyle: [],
+          Embedded_QuestionBank_OptionStyle: [],
+          Embedded_QuestionBank_KnowledgePoint: [],
+          Embedded_QuestionBank_Difficulty: []
+        }
+      }
+      await app.MG.store.getProductDetail(query).then((res) => {
+        res.datas.cmsDatas[0].datas.forEach((item, index) => {
+          // 寰幆questionList,缁欐瘡棰樿祴鍊煎垎鏁�
+          let oldObj
+          if (oldList) oldObj = oldList.find((oldItem) => oldItem.id == item.id)
+          let questionObj = {
+            // number: pathitem.infoList.find(infoItem => infoItem.itemId == item.id).number,
+            id: item.id,
+            score: pathitem.infoList.find(infoItem => infoItem.id == item.id).score,
+            stem:
+              item.Embedded_QuestionBank_QuestionType == 'completion'
+                ? JSON.parse(item.Embedded_QuestionBank_Stem)
+                  .stemTxt.replaceAll('<vacancy>', ',input,')
+                  .split(',')
+                : JSON.parse(item.Embedded_QuestionBank_Stem), // 棰樺共
+            answer: item.Embedded_QuestionBank_Answer, // 绛旀
+            option: item.Embedded_QuestionBank_Option
+              ? JSON.parse(item.Embedded_QuestionBank_Option)
+              : '', // 閫夋嫨棰橀�夐」
+            analysisCon: item.Embedded_QuestionBank_AnalysisCon, // 瑙f瀽
+            questionType: item.Embedded_QuestionBank_QuestionType, // 棰樺瀷
+            optionStyle: item.Embedded_QuestionBank_OptionStyle, // 閫夐」鏄剧ず绫诲瀷
+            stemStyle: item.Embedded_QuestionBank_StemStyle, // 棰樺共鏄剧ず绫诲瀷
+            difficulty: item.Embedded_QuestionBank_Difficulty
+              ? 4 - item.Embedded_QuestionBank_Difficulty
+              : 0, // 闅惧害绛夌骇
+            userAnswer: oldObj
+              ? oldObj.answer
+              : item.Embedded_QuestionBank_QuestionType == 'completion' ||
+                item.Embedded_QuestionBank_QuestionType == 'multipleChoice'
+                ? []
+                : '',
+            isUserAnswer: oldObj ? this.isHaveAnswer(oldObj.userAnswer) : false,
+            isRight: oldObj ? oldObj.isRight : null,
+            // isComplete: oldObj ? oldObj.isComplete : false,
+            isComplete: this.data.mockData.state == '3' ? true : oldObj ? this.isHaveAnswer(oldObj.answer) : false,
+            isCollect: this.data.collectList.indexOf(item.id) > -1 ? true : false,
+            isUnfold: '' // 鎺у埗瑙f瀽鐨勬姌鍙犻潰鏉挎槸鍚﹀睍寮�
+          }
+          // 澶氶�夊拰濉┖绛旀鑲负鏁扮粍锛岃杞崲JSON鏍煎紡
+          if (
+            questionObj.questionType == 'completion' ||
+            questionObj.questionType == 'multipleChoice'
+          ) {
+            try {
+              questionObj.answer = JSON.parse(questionObj.answer)
+            } catch (error) {
+              questionObj.answer = item.Embedded_QuestionBank_Answer
+            }
+          }
+          // 濉┖棰樻敼閫�
+          if (questionObj.questionType == 'completion') {
+            let index = 0
+            for (let i = 0; i < questionObj.stem.length; i++) {
+              const item = questionObj.stem[i]
+              if (item == 'input') {
+                questionObj.stem[i] = {
+                  num: index,
+                  data: 'input'
+                }
+                if (!oldObj) questionObj.userAnswer[index] = ''
+                index++
+              }
+            }
+          }
+          // 鑾峰彇鍥剧墖
+          if (questionObj.stemStyle == 'Image' || questionObj.stemStyle == 'TxtAndImage') {
+            questionObj.stem.stemImage = getPublicImage(questionObj.stem.stemImage, 150)
+          }
+          if (questionObj.optionStyle == 'Image' || questionObj.optionStyle == 'TxtAndImage') {
+            questionObj.option.forEach(optionItem => {
+              if (optionItem.img) optionItem.img = getPublicImage(optionItem.img, 150)
+            })
+          }
+          if (oldObj && oldObj.isRight) {
+            this.setData({
+              correctNum: this.data.correctNum + 1
+            })
+          }
+          if (item.questionType != 'shortAnswer' && item.isComplete) {
+            this.setData({
+              subjectiveTotal: this.data.subjectiveTotal + 1
+            })
+          }
+          // if (oldObj && isHaveAnswer(oldObj.answer)) countDownRef.value.changeAlready()
+          // cardList璧嬪��
+          let cardIndex = this.data.cardList.findIndex((item) => item.catalogName == pathitem.catalogName)
+          let infoIndex = this.data.cardList[cardIndex].infoList.findIndex(infoItem => infoItem.id == item.id)
+          this.setData({
+            [`cardList[${cardIndex}].infoList[${infoIndex}]`]: questionObj
+          })
+          let questionList = []
+          const cardUpdatedList = this.data.cardList
+          cardUpdatedList.forEach(aitem => {
+            aitem.infoList.forEach((bitem, bindex) => {
+              questionList.push(bitem)
+              bitem.number = bindex + 1
+            })
+          })
+          this.setData({
+            questionDataList: questionList,
+            cardList: cardUpdatedList
+          })
+          console.log('缁勫嵎棰樼洰鍒楄〃', this.data.questionDataList);
+        })
+      })
+    })
+    this.setData({
+      // questionDataList: questionDataList,
+      loading: false
+    })
+  },
+  // 鑾峰彇缁勫嵎鏁版嵁
+  getMockInfo(callback) {
+    app.MG.identity
+      .getUserKey({
+        domain: 'mockData',
+        keys: [this.data.bookId]
+      })
+      .then((res) => {
+        if (callback) callback(res)
+      })
+  },
+  // 璁板綍璐拱缁勫嵎鏃堕棿
+  setMockInfo(data) {
+    app.MG.identity.setUserKey({
+      setKeyRequests: [
+        {
+          domain: 'mockData',
+          key: this.data.bookId + '',
+          value: JSON.stringify(data)
+        }
+      ]
+    })
+  },
+  // 璁板綍缁勫嵎棰樼洰鍒楄〃
+  saveMockQuestionList(data) {
+    app.MG.identity
+      .setUserKey({
+        setKeyRequests: [
+          {
+            domain: 'mockQuestionData',
+            key: this.data.uuid,
+            value: JSON.stringify(data)
+          }
+        ]
+      })
+      .then((res) => {
+        console.log('妯¤�冮鐩垪琛ㄥ凡璁板綍')
+      })
+  },
+  // 鑾峰彇璁板綍缁勫嵎棰樼洰鍒楄〃
+  async getMockQuestionList() {
+    let list = []
+    await app.MG.identity
+      .getUserKey({
+        domain: 'mockQuestionData',
+        keys: [this.data.uuid]
+      })
+      .then((res) => {
+        list = JSON.parse(res[0].value)
+      })
+    return list
+  },
+  // 鑾峰彇妯¤�冪敤鎴风瓟棰樻暟鎹�
+  async getMockAnswer() {
+    let data
+    await app.MG.identity
+      .getUserKey({
+        domain: 'mockAnswerData',
+        keys: [this.data.uuid]
+      })
+      .then((res) => {
+        if (res[0]) {
+          this.setData({
+            currentIndex: JSON.parse(res[0].value).currentIndex,
+            'mockData.time': JSON.parse(res[0].value).time,
+            countdownTime: JSON.parse(res[0].value).time ? JSON.parse(res[0].value).time : this.data.mockData.sumTime,
+            'mockData.answer': JSON.parse(res[0].value).answerData
+          })
+          console.log(JSON.parse(res[0].value));
+          data = JSON.parse(res[0].value).answerData
+        }
+      })
+    return data
+  },
+
+  // 璁板綍妯¤�冪瓟棰樻暟鎹�
+  saveMockData() {
+    const data = this.data.mockData.datas.find((itme) => itme.id == this.data.uuid)
+    if (data.state == '3') return true
+    const saveData = this.data.mockData.answer
+    for (let i = 0; i < this.data.questionDataList.length; i++) {
+      const item = this.data.questionDataList[i]
+      if (this.isHaveAnswer(item.userAnswer)) {
+        const index = saveData.findIndex((saveitem) => saveitem.id == item.id)
+        if (index + '' != '-1') {
+          saveData[index].answer = item.userAnswer
+        } else {
+          saveData.push({
+            id: item.id,
+            answer: item.userAnswer
+          })
+        }
+      }
+    }
+    // 
+    if (this.data.mockData.state == '1') {
+      const datas = this.data.mockData.datas
+      datas.forEach((item) => {
+        if (item.id == this.data.uuid) {
+          item.state = '2'
+        }
+      })
+      this.setMockInfo(datas)
+    }
+    // 
+    app.MG.identity
+      .setUserKey({
+        setKeyRequests: [
+          {
+            domain: 'mockAnswerData',
+            key: this.data.uuid,
+            value: JSON.stringify({
+              currentIndex: this.data.currentIndex,
+              time: this.data.countdownTime,
+              answerData: saveData
+            })
+          }
+        ]
+      })
+      .then((res) => {
+        this.setData({
+          saveTime: 20
+        })
+        console.log('妯¤�冪瓟棰樻暟鎹凡璁板綍')
+      })
   }
 })
\ No newline at end of file

--
Gitblit v1.9.1