From cd98c69ff835643f518337ee9ab532885c647efb Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期五, 15 三月 2024 18:48:39 +0800
Subject: [PATCH] 合并代码

---
 pages/bookServices/examination/examination.js |  896 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 840 insertions(+), 56 deletions(-)

diff --git a/pages/bookServices/examination/examination.js b/pages/bookServices/examination/examination.js
index a8bc3ce..cfad42b 100644
--- a/pages/bookServices/examination/examination.js
+++ b/pages/bookServices/examination/examination.js
@@ -1,3 +1,4 @@
+import { getPublicImage } from '../../../assets/js/middleGround/tool'
 const app = getApp()
 Page({
 
@@ -9,20 +10,25 @@
     navBarHeight: "",
     loading: false,
     answerTitle: "",  // 瀵艰埅鏍忔爣棰�
+    countdownInterval: null,   // 璁℃椂鍣�
+    isCountdownRunning: true, // 鏄惁鍊掕鏃�
+    countdownTime: 0,  // 鍊掕鏃舵椂闂�
     bookId: "",
     productLinkPath: "",
     rootCmsItemId: "",
     idPathList: [],  // 棰樼洰鍒楄〃
-    answerType: "",  // 绛旈绫诲瀷
+    answerType: "",  // 绛旈妯″紡
     submitStatus: false,  // 鎻愪氦鐘舵��
-    currentIndex: 0, // 褰撳墠绛旈鏁�
+    currentIndex: 0, // 褰撳墠鏄剧ず鐨勯鍙�
     collectList: [],   //  鏀惰棌棰樼洰鍒楄〃 
-    subjectiveNum: 0, // 涓昏棰樺緱鍒�
-    subjectiveGrade: 0, // 涓昏棰樻�诲垎
-    total: 0,   // 棰樼洰鎬绘暟
+    errorList: [],  // 閿欓鍒楄〃
+    subjectiveTotal: 0,  // 瀹㈣棰樻�绘暟
+    subjectiveNum: 0, // 瀹㈣棰樺緱鍒�
+    subjectiveGrade: 0, // 瀹㈣棰樻�诲垎
     correctNum: 0,  // 姝g‘棰樼洰鏁伴噺
+    total: 0,   // 棰樼洰鎬绘暟
     cardList: [],  // 鎻愪氦椤�,
-    questionDataList: []
+    questionDataList: [],  // 鏄剧ず棰樼洰鍒楄〃
   },
 
   /**
@@ -37,12 +43,13 @@
       navBarHeight: navBarHeight,
       answerTitle: options.answerTitle,
       bookId: options.bookId,
-      productLinkPath: options.productLinkPath,
+      productLinkPath: options.productLinkPath ? options.productLinkPath : '',
       rootCmsItemId: options.rootCmsItemId,
-      idPathList: JSON.parse(options.idPathList),
+      idPathList: options.idPathList ? JSON.parse(options.idPathList) : [],
       answerType: options.answerType
     });
     this.init()
+    console.log('浼犲弬', options);
   },
 
   /**
@@ -70,7 +77,9 @@
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍗歌浇
    */
   onUnload() {
-
+    if (this.data.countdownInterval !== null) {
+      clearInterval(this.data.countdownInterval)
+    }
   },
 
   /**
@@ -96,12 +105,243 @@
   goBack() {
     wx.navigateBack();
   },
+
+  // 鑾峰彇淇濆瓨鐨勫�掕鏃舵椂闂�
+  getSavedTime() {
+    const savedTime = wx.getStorageSync('countdownTime')
+    return savedTime ? parseInt(savedTime) : null
+  },
+  // 淇濆瓨鍊掕鏃舵椂闂村埌鏈湴瀛樺偍
+  saveTime() {
+    wx.setStorageSync('countdownTime', this.data.countdownTime.toString())
+  },
+  clearTime() {
+    this.setData({
+      countdownTime: 2 * 60 * 60 * 1000
+    })
+  },
+  // 鏆傚仠鎴栫户缁�掕鏃�
+  toggleCountdown() {
+    if (this.data.countdownInterval) {
+      clearInterval(this.data.countdownInterval)
+      this.setData({
+        countdownInterval: null,
+        isCountdownRunning: false
+      })
+    } else {
+      this.startCountdown()
+      this.setData({
+        isCountdownRunning: true
+      })
+    }
+  },
+  // 寮�濮嬪�掕鏃�
+  startCountdown() {
+    // 濡傛灉璁℃椂鍣ㄥ凡缁忓瓨鍦紝鍏堟竻闄や箣鍓嶇殑璁℃椂鍣�
+    if (this.data.countdownInterval) {
+      clearInterval(this.data.countdownInterval)
+      this.setData({
+        countdownInterval: null
+      })
+    }
+    this.setData({
+      countdownInterval: setInterval(() => {
+        this.setData({
+          countdownTime: this.data.countdownTime - 1000
+        })
+        if (this.data.countdownTime <= 0) {
+          clearInterval(this.data.countdownInterval)
+          this.setData({
+            countdownTime: 0,
+            isCountdownRunning: false
+          })
+        }
+        this.saveTime()
+      }, 1000)
+    })
+  },
+  // 鍒囨崲棰樼洰
+  changeSwiper(e) {
+    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)
+
+  },
+  // 鐐瑰嚮绛旈鍗¤烦杞鐩�
+  goQuestion(e) {
+    console.log(e);
+    const id = e.detail.id
+    this.data.questionDataList.forEach((item, index) => {
+      if (item.id == id) {
+        this.setData({
+          currentIndex: index
+        })
+      }
+    })
+  },
+  // 鍗曢�� 澶氶�� 瑙﹀彂
+  onChangeRadio(e) {
+    const radioData = e.detail.value.currentTarget.dataset.value
+    const id = e.detail.value.currentTarget.dataset.id
+    const radioChecked = e.detail.value.detail.value
+    const questionList = this.data.questionDataList
+    questionList.forEach(item => {
+      if (item.id == id) {
+        item.userAnswer = radioChecked
+      }
+    })
+    this.setData({
+      questionDataList: questionList
+    })
+    console.log(this.data.questionDataList);
+  },
+  // 杈撳叆妗嗚Е鍙�
+  onChangeInput(e) {
+    const inputData = e.detail.value.detail.value
+    const id = e.detail.value.currentTarget.dataset.id
+    const index = e.detail.value.currentTarget.dataset.index
+    const questionList = this.data.questionDataList
+    questionList.forEach(item => {
+      if (item.id == id) {
+        item.userAnswer[index] = inputData
+      }
+    })
+    this.setData({
+      questionDataList: questionList
+    })
+    console.log(this.data.questionDataList);
+  },
+  // 鏁扮粍杞负瀛楃涓叉柟娉�
+  arrayToString(data) {
+    // 妫�鏌ユ槸鍚︿负鏁扮粍
+    if (Array.isArray(data)) {
+      // 浣跨敤 join 鏂规硶灏嗘暟缁勮浆鎹负瀛楃涓诧紝榛樿浣跨敤閫楀彿鍒嗛殧
+      return data.join(',').replace(/<[^>]*>/g, '')
+    } else {
+      // 濡傛灉涓嶆槸鏁扮粍锛岀洿鎺ヨ繑鍥炲師濮嬪��
+      return data.replace(/<[^>]*>/g, '')
+    }
+  },
+  // 鍒ゆ柇鏄惁鏈夌敤鎴风瓟妗�
+  isHaveAnswer(data) {
+    if (typeof data == 'string') {
+      data = data
+        .replace(/<[^>]*>/g, '')
+        .replace(/&nbsp;/g, '')
+        .trim()
+      if (data.length) {
+        return true
+      } else {
+        return false
+      }
+    } else {
+      const answer = data.find((item) => item.length > 0)
+      if (answer) {
+        return true
+      } else {
+        return false
+      }
+    }
+  },
+  // 鎻愪氦閫昏緫
+  submitPaper() {
+    this.setData({
+      submitStatus: true
+    })
+    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()
+      }
+    } else if (this.data.answerType == 'collectQuestion' || this.data.answerType == 'errorQuestion') {
+      this.goBack()
+    }
+
+  },
   // 鍒濆鍖栧嚱鏁�
   async init() {
+    this.setData({
+      loading: true,
+      subjectiveTotal: 0,
+      subjectiveNum: 0,
+      subjectiveGrade: 0
+    })
     if (this.data.answerType == 'option') {
+      if (this.data)
+        this.startCountdown()
+      this.setData({
+        countdownTime: 2 * 60 * 60 * 1000
+      })
       // 娴嬭瘯绛旈
       await this.getCollectIdList() // 鑾峰彇鏀惰棌id鍒楄〃
-      // await getErrorList() // 鑾峰彇閿欓id鍒楄〃
+      await this.getErrorList()   // 鑾峰彇閿欓id鍒楄〃
+    } else if (this.data.answerType == 'collectQuestion') {
+      // 鎴戠殑鏀惰棌
+      await this.getcollectId() // 鑾峰彇鏀惰棌棰樼洰
+    } else if (this.data.answerType == 'errorQuestion') {
+      // 鎴戠殑閿欓
+      // loadings.value = true
+      await this.getErrorIdList()
+      await this.getCollectIdList() // 鑾峰彇鏀惰棌id鍒楄〃
+    }
+  },
+  async restart() {
+    const countDownRef = this.selectComponent('#countDownRef')
+    this.setData({
+      loading: true,
+      total: 0,
+      subjectiveGrade: 0,
+      subjectiveTotal: 0,
+      subjectiveNum: 0,
+      currentIndex: 0,
+      submitStatus: false
+    })
+    if (this.data.answerType == 'option') {
+      this.setData({
+        countdownTime: 2 * 60 * 60 * 1000
+      })
+      this.delAnswerInfo(() => {
+        this.getQuestionList()
+        this.clearTime()
+      })
+      if (!this.data.submitStatus) {
+        this.startCountdown()
+      }
+    } else if (this.data.answerType == 'mock') {
+      // 缁勫嵎妯″紡
+      // 娓呯┖绛旈璁板綍
+      await app.MG.identity.setUserKey({
+        setKeyRequests: [
+          {
+            domain: 'mockAnswerData',
+            key: route.query.uuid,
+            value: JSON.stringify({
+              time: countDownRef.value.countdownTime,
+              answerData: []
+            })
+          }
+        ]
+      })
+      this.init()
+    } else {
+      this.init()
+      this.clearTime()
+      if (submitStatus.value) {
+        this.startCountdown()
+      }
     }
   },
   // 鑾峰彇鏀惰棌棰樼洰鍒楄〃id
@@ -111,7 +351,7 @@
         domain: 'collectData',
         keys: [this.data.rootCmsItemId]
       })
-      .then(async (res) => {
+      .then((res) => {
         try {
           this.setData({
             collectList: JSON.parse(res[0].value)
@@ -120,16 +360,18 @@
         }
         if (this.data.answerType == 'option') {
           // 鍏堣幏鍙栫敤鎴风瓟棰樿褰�
-          await this.getAnswerInfo((res) => {
+          this.getAnswerInfo(async (res) => {
             if (res.length) {
               // 鏈夎褰曪紝涓嶈兘绛旈锛岀姸鎬佽涓哄凡鎻愪氦
               this.setData({
                 submitStatus: true
               })
               let value = JSON.parse(res[0].value)
-              // console.log('绛旈璁板綍', JSON.parse(res[0].value))
               // 鏈夌瓟棰樿褰曪紝寰楀垎璧嬪��
               if (value) {
+                this.setData({
+                  submitStatus: true
+                })
                 value.dataList.forEach((item) => {
                   if (item.name == '瀹㈣棰樺緱鍒�' && item.path == this.data.productLinkPath)
                     this.setData({
@@ -141,11 +383,28 @@
                 currentIndex: value.currentIndex
               })
               // 鎼哄甫绛旈璁板綍 鑾峰彇棰樼洰
-              this.getQuestionList(value.dataList)
+              await this.getQuestionList(value.dataList)
             } else {
-              this.getQuestionList() // 鑾峰彇棰樺簱棰樼洰
+              await this.getQuestionList() // 鑾峰彇棰樺簱棰樼洰
             }
           })
+        }
+      })
+  },
+  // 鑾峰彇閿欓id鍒楄〃
+  getErrorList() {
+    app.MG.identity
+      .getUserKey({
+        domain: 'errorData',
+        keys: [this.data.rootCmsItemId]
+      })
+      .then((res) => {
+        try {
+          this.setData({
+            errorList: JSON.parse(res[0].value)
+          })
+        } catch (error) {
+
         }
       })
   },
@@ -153,22 +412,21 @@
   getQuestionList(oldData) {
     // 娓呯┖姝g‘棰樻暟璁板綍
     this.setData({
-      correctNum: 0
+      cardList: [],
+      correctNum: 0,
     })
     let flag = 0
     this.data.idPathList.forEach((pathitem) => {
       const pathList = this.data.cardList
       pathList.push({
-        name: pathitem.name,
         path: pathitem.productLinkPath,
-        catalogName: pathitem.type,
+        catalogName: pathitem.name,
         infoList: []
       })
       this.setData({
         cardList: pathList
       })
       // 鑾峰彇棰樼洰
-      let questionArr = []
       let query = {
         path: '*',
         queryType: '*',
@@ -210,6 +468,7 @@
           let questionObj = {
             // num: index, // 棰樺彿
             id: item.id,
+            type: pathitem.name,
             stem:
               item.Embedded_QuestionBank_QuestionType == 'completion'
                 ? JSON.parse(item.Embedded_QuestionBank_Stem)
@@ -249,6 +508,8 @@
               questionObj.answer = item.Embedded_QuestionBank_Answer
             }
           }
+          // questionObj.userAnswer = this.arrayToString(questionObj.userAnswer)
+          // questionObj.isHaveAnswer = this.isHaveAnswer(questionObj.userAnswer)
           // 濉┖棰樻敼閫�
           if (questionObj.questionType == 'completion') {
             let index = 0
@@ -264,7 +525,20 @@
               }
             }
           }
-          questionArr.push(questionObj)
+          // 鑾峰彇鍥剧墖
+          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 (questionObj.optionStyle == 'RichText') {
+          //   questionObj.option.forEach(optionItem => {
+          //     optionItem.txt.replace(/<img>/g, "<img class='imgClass'>")
+          //   })
+          // }
           // 鏃ф暟鎹噷 棰樼洰宸茬粡浣滅瓟锛屼慨鏀瑰凡绛旈鐩暟閲�
           // if (oldObj && oldObj.userAnswer.length > 0) countDownRef.value.changeAlready()
           // 鏃ф暟鎹噷 棰樼洰姝g‘ 璁板綍姝g‘鏁伴噺
@@ -273,57 +547,240 @@
               correctNum: this.data.correctNum + 1
             })
           }
-          // if (pathitem.name == '鍒ゆ柇棰�') {
-          //   topicList.value.judge.data = questionArr
-          //   topicList.value.judge.path = pathitem.productLinkPath
-          //   if (oldData) subjectiveTotal.value += 1 // 鏈夋棫鏁版嵁锛岃绠椾富瑙傞鏁�
-          // } else if (pathitem.name == '濉┖棰�') {
-          //   topicList.value.gap.data = questionArr
-          //   topicList.value.gap.path = pathitem.productLinkPath
-          //   if (oldData) subjectiveTotal.value += 1
-          // } else if (pathitem.name == '澶氶�夐') {
-          //   topicList.value.check.data = questionArr
-          //   topicList.value.check.path = pathitem.productLinkPath
-          //   if (oldData) subjectiveTotal.value += 1
-          // } else if (pathitem.name == '鍗曢�夐') {
-          //   topicList.value.radio.data = questionArr
-          //   topicList.value.radio.path = pathitem.productLinkPath
-          //   if (oldData) subjectiveTotal.value += 1
-          // } else if (pathitem.name == '绠�绛旈') {
-          //   topicList.value.short.data = questionArr
-          //   topicList.value.short.path = pathitem.productLinkPath
-          // } else if (pathitem.name == '缈昏瘧棰�') {
-          //   topicList.value.translate.data = questionArr
-          //   topicList.value.translate.path = pathitem.productLinkPath
-          // } else if (pathitem.name == '鍚姏棰�') {
-          //   topicList.value.listen.data = questionArr
-          //   topicList.value.listen.path = pathitem.productLinkPath
-          //   if (oldData) subjectiveTotal.value += 1
-          // }
-          let infoList =
-            this.data.cardList[this.data.cardList.findIndex((item) => item.path == pathitem.productLinkPath)]
-              .infoList
+          if (pathitem.name == '鍒ゆ柇棰�' || pathitem.name == '濉┖棰�' || pathitem.name == '澶氶�夐' || pathitem.name == '鍗曢�夐' || pathitem.name == '鍚姏棰�') {
+            if (oldObj) {
+              this.setData({
+                subjectiveTotal: this.data.subjectiveTotal + 1
+              })
+            }
+
+          }
+          // cardList璧嬪��
+          let cardIndex = this.data.cardList.findIndex((item) => item.path == pathitem.productLinkPath)
+          let infoList = this.data.cardList[cardIndex].infoList
           infoList.push(questionObj)
+          this.setData({
+            [`cardList[${cardIndex}].infoList`]: infoList
+          })
+          //   this.data.cardList[this.data.cardList.findIndex((item) => item.path == pathitem.productLinkPath)]
+          //     .infoList
+          // infoList.push(questionObj)
           flag++;
           let questionList = []
+          const cardUpdatedList = this.data.cardList
           // if (flag == this.data.idPathList.length) {
-          this.data.cardList.forEach(aitem => {
-            aitem.infoList.forEach(bitem => {
+          cardUpdatedList.forEach(aitem => {
+            aitem.infoList.forEach((bitem, bindex) => {
               questionList.push(bitem)
-              bitem.number = questionList.length
+              bitem.number = bindex + 1
+              bitem.grade = 2
             })
           })
           this.setData({
-            questionDataList: questionList
+            questionDataList: questionList,
+            cardList: cardUpdatedList
           })
-          // }
         })
       })
     })
     this.setData({
       loading: false,
     })
-    console.log('棰樼洰鍒楄〃', this.data.questionDataList, this.data.cardList);
+  },
+  // 鎵规敼棰樼洰 锛堢粌涔狅紝鎴戠殑閿欓锛屾垜鐨勬敹钘忥級
+  handleQuestion(num) {
+    const questionList = this.data.questionDataList
+    const index = num - 1 >= 0 ? num - 1 : 0
+    if (questionList[index].isComplete) {
+      // 棰樼洰宸插畬鎴愶紝璺宠繃
+      return true
+    }
+    questionList[index].isComplete = true
+    const item = questionList[index]
+    // 鎵规敼棰樼洰
+    if (item.questionType == 'multipleChoice') {
+      // 澶氶�夐
+      // subjectiveGrade.value += item.score
+      if (item.answer.length == item.userAnswer.length) {
+        const sortedArr1 = item.answer.slice().sort()
+        const sortedArr2 = item.userAnswer.slice().sort()
+        questionList[index].isRight = sortedArr1.every(
+          (value, valueIndex) => value === sortedArr2[valueIndex]
+        )
+      } else {
+        questionList[index].isRight = false
+      }
+    } else if (item.questionType == 'singleChoice' || item.questionType == 'judge') {
+      // 鍗曢�� 鍒ゆ柇
+      // subjectiveGrade.value += item.score
+      questionList[index].isRight = item.answer == item.userAnswer
+    } else if (item.questionType == 'shortAnswer') {
+      // 绠�绛� 缈昏瘧
+      questionList[index].isRight = null
+    } else if (item.questionType == 'completion') {
+      // 濉┖
+      // subjectiveGrade.value += item.score
+      if (typeof item.answer == 'string') {
+        questionList[index].isRight = item.answer == item.userAnswer[0]
+      } else {
+        if (item.answer.length != item.userAnswer.length) {
+          questionList[index].isRight = false
+        } else {
+          questionList[index].isRight = item.answer.every(
+            (value, valueIndex) => value === item.userAnswer[valueIndex]
+          )
+        }
+      }
+    }
+    if (item.questionType != 'shortAnswer') {
+      this.setData({
+        subjectiveTotal: this.data.subjectiveTotal + 1,
+        subjectiveGrade: this.data.subjectiveGrade + item.grade
+      })
+    }
+    if (questionList[index].isRight && item.questionType != 'shortAnswer') {
+      // 瀹㈣棰樺洖绛旀纭�
+      this.setData({
+        subjectiveNum: this.data.subjectiveNum + item.grade,
+        correctNum: this.data.correctNum + 1
+      })
+    }
+    if (!questionList[index].isRight && item.questionType != 'shortAnswer') {
+      // 瀹㈣棰樺洖绛旈敊璇� 璁板綍閿欓
+      if (this.data.errorList.findIndex((errorItem) => errorItem == item.id) == -1) {
+        this.data.errorList.push(item.id)
+      }
+    } else {
+      if (this.data.answerType == 'errorQuestion' || this.data.answerType == 'option') {
+        // 浠庨敊棰橀泦涓Щ闄�
+        let errorIndex = this.data.errorList.findIndex((erroritem) => erroritem == item.id)
+        if (errorIndex > -1) {
+          this.data.errorList.splice(errorIndex, 1)
+        }
+      }
+    }
+    if (this.data.answerType != 'collectQuestion') {
+      // 璁板綍閿欓
+      app.MG.identity
+        .setUserKey({
+          setKeyRequests: [
+            {
+              domain: 'errorData',
+              key: this.data.rootCmsItemId,
+              value: JSON.stringify(this.data.errorList)
+            }
+          ]
+        })
+        .then((res) => {
+          console.log(res)
+        })
+    }
+    this.setData({
+      questionDataList: questionList
+    })
+    const cardUpdatedList = this.data.cardList
+    cardUpdatedList.forEach((item) => {
+      item.infoList.forEach((citem) => {
+        if (citem.id == questionList[index].id) {
+          citem = questionList[index];
+        }
+      });
+    });
+    this.setData({
+      cardList: cardUpdatedList
+    })
+    // console.log(this.data.questionDataList, this.data.cardList);
+  },
+  // 棰樼洰鏀惰棌鎸夐挳,鏀惰棌鍜屽彇娑堝悓涓�鎺ュ彛锛屽彇娑堟暟缁勫噺鍘昏椤筰d
+  setCollect() {
+    const citem = this.data.questionDataList[this.data.currentIndex]
+    const questionList = this.data.questionDataList
+    for (let index = 0; index < questionList.length; index++) {
+      const item = questionList[index];
+      if (item.id == citem.id) {
+        item.isCollect = !item.isCollect
+      }
+    }
+    this.setData({
+      questionDataList: questionList
+    })
+    if (this.data.collectList.length == 0) {
+      this.setData({
+        collectList: [citem.id]
+      })
+    } else {
+      const collectItme = this.data.collectList.filter((item) => item == citem.id)
+      if (collectItme.length) {
+        const arr = this.data.collectList.filter((item) => item != citem.id)
+        this.setData({
+          collectList: arr
+        })
+      } else {
+        const collectArr = this.data.collectList
+        collectArr.push(citem.id)
+        this.setData({
+          collectList: collectArr
+        })
+      }
+    }
+    app.MG.identity
+      .setUserKey({
+        setKeyRequests: [
+          {
+            domain: 'collectData',
+            key: this.data.rootCmsItemId,
+            value: JSON.stringify(this.data.collectList)
+          }
+        ]
+      })
+      .then((res) => { })
+  },
+  // 澶勭悊绛旈鏁版嵁
+  recordAnswerData() {
+    this.data.cardList.push(
+      {
+        name: '瀹㈣棰樺緱鍒�',
+        score: this.data.subjectiveNum,
+        path: this.data.productLinkPath,
+        // infoList: [],
+        // catalogName: ''
+      }
+    )
+    let setInfoData = {
+      currentIndex: this.data.currentIndex,
+      dataList: JSON.parse(JSON.stringify(this.data.cardList))
+    }
+    for (let i = 0; i < setInfoData.dataList.length; i++) {
+      const item = setInfoData.dataList[i]
+      if (!item.name && !item.name == '瀹㈣棰樺緱鍒�') {
+        for (let j = 0; j < item.infoList.length; j++) {
+          let obj = {
+            id: item.infoList[j].id,
+            userAnswer: item.infoList[j].userAnswer,
+            isComplete: item.infoList[j].isComplete,
+            isRight: item.infoList[j].isRight,
+            isCollect: item.infoList[j].isCollect
+          }
+          item.infoList[j] = obj
+        }
+      }
+    }
+
+    this.setAnswerInfo(setInfoData)
+  },
+  // 鎻愪氦绛旈鏁版嵁
+  setAnswerInfo(data) {
+    app.MG.identity
+      .setUserKey({
+        setKeyRequests: [
+          {
+            domain: 'answerData',
+            key: this.data.productLinkPath,
+            value: JSON.stringify(data)
+          }
+        ]
+      })
+      .then((res) => { })
   },
   // 鑾峰彇绛旈鏁版嵁
   getAnswerInfo(callback) {
@@ -335,5 +792,332 @@
       .then((res) => {
         if (callback) callback(res)
       })
+  },
+  // 鍒犻櫎绛旈鏁版嵁
+  delAnswerInfo(callback) {
+    app.MG.identity
+      .delUserKey({
+        domain: 'answerData',
+        keys: [this.data.productLinkPath]
+      })
+      .then((res) => {
+        if (callback) callback()
+      })
+  },
+  // 鎴戠殑鏀惰棌妯″紡涓嬭幏鍙栨敹钘忛鐩甶d
+  async getcollectId() {
+    app.MG.identity
+      .getUserKey({
+        domain: 'collectData',
+        keys: [this.data.rootCmsItemId]
+      })
+      .then(async (res) => {
+        try {
+          this.setData({
+            collectList: JSON.parse(res[0].value)
+          })
+          // total.value = collectList.value.length
+        } catch (error) {
+        }
+        if (this.data.collectList && this.data.collectList.length) {
+          await this.getCollectDataList()
+        } else {
+          this.setData({
+            loading: false
+          })
+          wx.showModal({
+            title: '鎻愮ず',
+            content: '鏀惰棌澶规殏鏃犳暟鎹�',//editable濡傛灉涓簍rue锛岃繖灏辨槸杈撳叆妗嗙殑鍐呭
+            editable: false,//鏄惁鏄剧ず杈撳叆妗�
+            showCancel: false,
+            success: (res) => {
+              if (res.confirm) {
+                this.setData({
+                  submitStatus: true
+                })
+                this.goBack()
+              }
+
+            }
+          })
+        }
+        // console.log('鏀惰棌', collectList.value)
+      })
+  },
+  // 鑾峰彇鏀惰棌澶�
+  async getCollectDataList() {
+    let questionArr = []
+    this.setData({
+      cardList: [
+        {
+          catalogName: '鏀惰棌澶�',
+          infoList: []
+        }
+      ]
+    })
+    let query = {
+      path: '*',
+      cmsPath: this.data.rootCmsItemId,
+      cmsType: '*',
+      productId: this.data.bookId,
+      queryType: '*',
+      itemIds: this.data.collectList.map((item) => item + ''),
+      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: []
+      }
+    }
+    app.MG.store.getProductDetail(query).then((res) => {
+      let questionArr = []
+      res.datas.cmsDatas[0].datas.forEach((item, index) => {
+        const questionObj = {
+          number: index + 1, // 棰樺彿
+          id: item.id,
+          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:
+            item.Embedded_QuestionBank_QuestionType == 'completion' ||
+              item.Embedded_QuestionBank_QuestionType == 'multipleChoice'
+              ? []
+              : '',
+          isSubmit: false, // 鏌ョ湅瑙f瀽
+          isRight: null, // 鏄惁姝g‘
+          isComplete: false,
+          isCollect: true
+        }
+        // 澶氶�夊拰濉┖绛旀鑲负鏁扮粍锛岃杞崲JSON鏍煎紡
+        if (
+          questionObj.questionType == 'completion' ||
+          questionObj.questionType == 'multipleChoice'
+        ) {
+          try {
+            questionObj.answer = JSON.parse(questionObj.answer)
+          } catch (error) {
+            //
+          }
+        }
+        // 濉┖棰樻敼閫�
+        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'
+              }
+              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 (item.Embedded_QuestionBank_QuestionType == 'judge') {
+        //   topicList.value.judge.data.push(questionObj)
+        // } else if (item.Embedded_QuestionBank_QuestionType == 'singleChoice') {
+        //   topicList.value.radio.data.push(questionObj)
+        // } else if (item.Embedded_QuestionBank_QuestionType == 'multipleChoice') {
+        //   topicList.value.check.data.push(questionObj)
+        // } else if (item.Embedded_QuestionBank_QuestionType == 'completion') {
+        //   topicList.value.gap.data.push(questionObj)
+        // } else if (item.Embedded_QuestionBank_QuestionType == 'shortAnswer') {
+        //   topicList.value.short.data.push(questionObj)
+        // }
+        questionArr.push(questionObj)
+        // cardList.value[0].infoList.push(questionObj)
+      })
+      // loadings.value = false
+      this.setData({
+        questionDataList: questionArr,
+        ['cardList[0].infoList']: questionArr,
+        loading: false,
+      })
+    })
+  },
+  // 鎴戠殑閿欓妯″紡涓嬭幏鍙栭敊棰榠d鍒楄〃
+  async getErrorIdList() {
+    await app.MG.identity
+      .getUserKey({
+        domain: 'errorData',
+        keys: [this.data.rootCmsItemId]
+      })
+      .then((res) => {
+        try {
+          this.setData({
+            errorList: JSON.parse(res[0].value)
+          })
+        } catch (error) {
+        }
+        if (this.data.errorList && this.data.errorList.length) {
+          this.getErrorDataList()
+        } else {
+          this.setData({
+            loading: true
+          })
+          wx.showModal({
+            title: '鎻愮ず',
+            content: '閿欓闆嗘殏鏃犳暟鎹�',//editable濡傛灉涓簍rue锛岃繖灏辨槸杈撳叆妗嗙殑鍐呭
+            editable: false,//鏄惁鏄剧ず杈撳叆妗�
+            showCancel: false,
+            success: (res) => {
+              if (res.confirm) {
+                this.setData({
+                  submitStatus: true
+                })
+                this.goBack()
+              }
+            }
+          })
+        }
+      })
+  },
+  // 鑾峰彇閿欓闆�
+  async getErrorDataList() {
+    this.setData({
+      cardList: [
+        {
+          catalogName: '閿欓闆�',
+          infoList: []
+        }
+      ]
+    })
+    let query = {
+      path: '*',
+      cmsPath: this.data.rootCmsItemId,
+      cmsType: '*',
+      productId: this.data.bookId,
+      queryType: '*',
+      itemIds: this.data.errorList.map((item) => item + ''),
+      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) => {
+      let questionArr = []
+      res.datas.cmsDatas[0].datas.forEach((item, index) => {
+        const questionObj = {
+          number: index + 1, // 棰樺彿
+          id: item.id,
+          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:
+            item.Embedded_QuestionBank_QuestionType == 'completion' ||
+              item.Embedded_QuestionBank_QuestionType == 'multipleChoice'
+              ? []
+              : '',
+          isSubmit: false, // 鏌ョ湅瑙f瀽
+          isRight: null, // 鏄惁姝g‘
+          isComplete: false,
+          isCollect: this.data.collectList.some((collectItem) => collectItem == item.id)
+        }
+        // 澶氶�夊拰濉┖绛旀鑲负鏁扮粍锛岃杞崲JSON鏍煎紡
+        if (
+          questionObj.questionType == 'completion' ||
+          questionObj.questionType == 'multipleChoice'
+        ) {
+          try {
+            questionObj.answer = JSON.parse(questionObj.answer)
+          } catch (error) {
+            //
+          }
+        }
+        // 濉┖棰樻敼閫�
+        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'
+              }
+              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 (item.Embedded_QuestionBank_QuestionType == 'judge') {
+        //   topicList.value.judge.data.push(questionObj)
+        // } else if (item.Embedded_QuestionBank_QuestionType == 'singleChoice') {
+        //   topicList.value.radio.data.push(questionObj)
+        // } else if (item.Embedded_QuestionBank_QuestionType == 'multipleChoice') {
+        //   topicList.value.check.data.push(questionObj)
+        // } else if (item.Embedded_QuestionBank_QuestionType == 'completion') {
+        //   topicList.value.gap.data.push(questionObj)
+        // } else if (item.Embedded_QuestionBank_QuestionType == 'shortAnswer') {
+        //   topicList.value.short.data.push(questionObj)
+        // }
+        questionArr.push(questionObj)
+      })
+      this.setData({
+        questionDataList: questionArr,
+        ['cardList[0].infoList']: questionArr,
+        loading: false
+      })
+    })
+    // loadings.value = false
+    // console.log('閿欓闆�', topicList.value)
   }
 })
\ No newline at end of file

--
Gitblit v1.9.1