From 1fa2461678d7f93b88f5666c4898e5b6c72080f3 Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期一, 16 十二月 2024 10:21:06 +0800
Subject: [PATCH] 个人中心,班级、课程模块

---
 packageBookService/pages/bookServices/examination/examination.js |  286 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 263 insertions(+), 23 deletions(-)

diff --git a/packageBookService/pages/bookServices/examination/examination.js b/packageBookService/pages/bookServices/examination/examination.js
index 7e2f406..4b751df 100644
--- a/packageBookService/pages/bookServices/examination/examination.js
+++ b/packageBookService/pages/bookServices/examination/examination.js
@@ -1,6 +1,9 @@
 import {
   getPublicImage
 } from "../../../../assets/js/middleGround/tool";
+import {
+  loginInfo
+} from '../../../../assets/js/login';
 const app = getApp();
 Page({
   /**
@@ -15,6 +18,7 @@
     isCountdownRunning: true, // 鏄惁鍊掕鏃�
     countdownTime: 0, // 鍊掕鏃舵椂闂�
     storeInfo: '',
+    jslx: '',
     bookId: "",
     productLinkPath: "",
     rootCmsItemId: "",
@@ -49,7 +53,11 @@
     startTime: "", //杩涘叆椤甸潰褰撳墠鏃堕棿
     pauseTime: 0, //鏆傚仠鏃堕棿
     showDialog: false, // 鏈彁浜ら��鍑烘嫤鎴脊绐�
-    showId: ''
+    showId: '',
+    isShowDialog: false, // 娴嬭瘯鎶ュ憡寮圭獥鏄惁鏄剧ず
+    joinGroup: false, // 鏄惁鍔犲叆鐝骇
+    visible: false, // 鍔犲叆鐝骇寮圭獥鏄惁鎵撳紑
+    classList: [] // 鐝骇鍒楄〃
   },
 
   /**
@@ -70,6 +78,7 @@
       idPathList: options.idPathList ? JSON.parse(options.idPathList) : [],
       answerType: options.answerType,
       storeInfo: options.storeInfo,
+      jslx: options.jslx,
     });
     wx.setNavigationBarTitle({
       title: options.answerTitle,
@@ -80,7 +89,21 @@
         mockid: options.mockid,
       });
     }
-    this.init();
+
+    const token = wx.getStorageSync(app.config.tokenKey)
+
+    if (!token) {
+      loginInfo(app, (data) => {
+        if (data) {
+          this.init();
+        } else {
+          this.init();
+        }
+      })
+    } else {
+      this.init()
+    }
+
   },
 
   /**
@@ -183,6 +206,7 @@
    * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜�
    */
   onShareAppMessage() {},
+  onShareTimeline() {},
 
   // 鐩戝惉watch
   watch(context, variableName, callback) {
@@ -278,11 +302,9 @@
     this.setData({
       sliderValue: e.detail.value,
     });
-    console.log(e.detail.value);
   },
   // 杩斿洖
   goBack() {
-    console.log(this.data.submitStatus);
     wx.navigateBack();
   },
   //璁剧疆鑳屾櫙鑹�
@@ -464,7 +486,6 @@
     const inputData = e.detail.value.detail.value;
     const id = e.detail.value.currentTarget.dataset.id;
     const index = Number(e.detail.value.currentTarget.dataset.index);
-    console.log(index);
     const questionList = this.data.questionDataList;
     questionList.forEach((item) => {
       if (item.id == id) {
@@ -531,11 +552,13 @@
       submitStatus: true,
       loading: true,
     });
-    const child = this.selectComponent("#question-options");
+    const child = this.selectComponent('#question-options');
+
     if (
       this.data.answerType == "option" ||
       this.data.answerType == "errorQuestion" ||
-      this.data.answerType == "mock"
+      this.data.answerType == "mock" ||
+      this.data.answerType == 'interaction'
     ) {
       // 鍏堥亶鍘嗘墍鏈夐鐩紝灏嗘湭鎵规敼鐨勯鐩壒鏀�
       const qustionList = this.data.questionDataList;
@@ -547,7 +570,11 @@
     if (this.data.answerType == "option") {
       this.toggleCountdown();
       this.recordAnswerData();
-      child.openTestReportDialog();
+      // this.selectComponent 鎷夸笉鍒� 缁勪欢浜嗭紝 鏀逛负鐩戝惉缁勪欢浼犲�� 鎵撳紑寮圭獥
+      // child.openTestReportDialog();
+      this.setData({
+        isShowDialog: true
+      })
     } else if (
       this.data.answerType == "collectQuestion" ||
       this.data.answerType == "errorQuestion"
@@ -590,7 +617,13 @@
           }),
         }, ],
       });
-      child.openTestReportDialog();
+      // child.openTestReportDialog();
+      this.setData({
+        isShowDialog: true
+      })
+    } else if (this.data.answerType == 'interaction') {
+      this.toggleCountdown();
+      this.handleClassQuestion()
     }
     this.setData({
       loading: false,
@@ -613,6 +646,13 @@
       // 娴嬭瘯绛旈
       await this.getCollectIdList(); // 鑾峰彇鏀惰棌id鍒楄〃
       await this.getErrorList(); // 鑾峰彇閿欓id鍒楄〃
+    } else if (this.data.answerType == "interaction") {
+      this.setData({
+        countdownTime: 2 * 60 * 60 * 1000,
+      });
+      this.getCurrentClassList()
+      this.getinteractionInfo()
+      // 鏁欏浜掑姩
     } else if (this.data.answerType == "collectQuestion") {
       this.setData({
         submitStatus: true,
@@ -820,7 +860,6 @@
       let query = {
         path: "*",
         queryType: "*",
-
         productId: this.data.bookId,
         cmsPath: pathitem.productLinkPath,
         itemFields: {
@@ -854,12 +893,9 @@
           oldList = oldData.find(
             (item) => item.path == pathitem.productLinkPath
           ).infoList;
-          this.setData({
-            submitStatus: true,
-          });
         }
         res.datas.cmsDatas[0].datas.forEach((item, index) => {
-          if (this.data.storeInfo) {
+          if (this.data.storeInfo || this.data.jslx) {
             if (item.Embedded_QuestionBank_QuestionType == 'singleChoice') {
               pathitem.name = "鍗曢�夐"
             } else if (item.Embedded_QuestionBank_QuestionType == 'shortAnswer') {
@@ -907,7 +943,8 @@
             questionObj.questionType == "multipleChoice"
           ) {
             try {
-              questionObj.answer = JSON.parse(questionObj.answer).toString();
+              // questionObj.answer = JSON.parse(questionObj.answer).toString();
+              questionObj.answer = JSON.parse(questionObj.answer)
             } catch (error) {
               questionObj.answer = item.Embedded_QuestionBank_Answer;
             }
@@ -1051,17 +1088,17 @@
     }
     // 鏈夐鐩啀寮�濮嬪�掕鏃�
     if (this.data.questionDataList.length) {
-      console.log(this.data.questionDataList);
       this.startCountdown();
+      this.setData({
+        loading: false,
+        showId: this.data.questionDataList[0].id
+      })
     } else {
       this.setData({
-        noData: true
+        noData: true,
+        loading: false,
       })
     }
-    this.setData({
-      loading: false,
-      showId: this.data.questionDataList[0].id
-    });
   },
   // 鎵规敼棰樼洰 锛堢粌涔狅紝鎴戠殑閿欓锛屾垜鐨勬敹钘�,锛岀粍鍗凤級
   handleQuestion(index) {
@@ -1094,7 +1131,7 @@
       // 绠�绛� 缈昏瘧
       questionList[index].isRight = null;
     } else if (item.questionType == "completion") {
-      if (item.answer == "string") {
+      if (typeof item.answer == "string") {
         item.isRight = item.answer == item.userAnswer[0];
       } else {
         if (item.answer.length != item.userAnswer.length) {
@@ -1413,6 +1450,7 @@
             questionObj.questionType == "completion" ||
             questionObj.questionType == "multipleChoice"
           ) {
+            console.log(questionObj.answer, "111")
             try {
               questionObj.answer = JSON.parse(questionObj.answer).toString();
             } catch (error) {
@@ -1792,6 +1830,7 @@
         cardList: cardList,
         loading: false,
       });
+      console.log(this.data.questionDataList, "questionDataList");
     });
   },
   // 鑾峰彇缁勫嵎缁撴灉
@@ -2204,7 +2243,6 @@
 
   // 瀵屾枃鏈鐞�
   formatRichText(html) {
-    console.log(html);
     let newContent = html.replace(/<img[^>]*>/gi, function (match, capture) {
       match = match
         .replace(/style="[^"]+"/gi, "")
@@ -2238,4 +2276,206 @@
     );
     return newContent;
   },
+  // 鏁欏浜掑姩妯″紡鐩稿叧
+  // 鑾峰彇鐝骇鍒楄〃
+  getCurrentClassList() {
+    const query = {
+      start: 0,
+      size: 999,
+      filterList: [],
+    }
+    app.MG.identity.joinedGroupByList(query).then((res) => {
+      res.datas.forEach(async item => {
+        item.topicId = null
+        const data = await this.getTopicInfo(item.id)
+        if (data) {
+          item.topicId = data.id
+        }
+      })
+      if (res.datas.length) {
+        this.setData({
+          joinGroup: true,
+          classList: res.datas,
+        })
+      } else {
+        // 鏈姞鍏ョ彮绾э紝鍞よ捣鍔犲叆鐝骇寮圭獥
+        this.setData({
+          joinGroup: false,
+          visible: true
+        })
+      }
+    })
+  },
+  // 鍔犲叆鐝骇
+  joinClass(e) {
+    const data = {
+      refCode: e.detail.value
+    }
+    app.MG.identity.joinGroupByRefCode(data).then((res) => {
+      if (res == '缁勪笉瀛樺湪') {
+        wx.showToast({
+          icon: 'error',
+          title: '鏃犳晥鐨勭彮绾�',
+        })
+      } else if (res == '缁勬垚鍛樻暟閲忓凡鏈�澶�,涓嶈兘鍔犲叆') {
+        wx.showToast({
+          icon: 'error',
+          title: '鐝骇鎴愬憳鏁伴噺宸叉渶澶э紝涓嶈兘鍔犲叆',
+        })
+      } else if (res == '宸茬粡鐢宠杩囧姞鍏ユ缁�') {
+        wx.showToast({
+          icon: 'error',
+          title: '宸茬粡鐢宠杩囧姞鍏ユ鐝骇',
+        })
+      } else {
+        wx.showToast({
+          icon: "success",
+          title: '宸叉垚鍔燂紝绛夊緟瀹℃牳涓�...',
+        })
+        this.setData({
+          visible: false
+        })
+        this.getCurrentClassList()
+      }
+    })
+  },
+  // 鑾峰彇鐝骇topic
+  async getTopicInfo(classId) {
+    let query = {
+      classId,
+      refCodes: ["TeachInteraction"]
+    }
+    const res = await app.MG.edu.getClassTopic(query)
+    return res[0] ?? null
+  },
+  // 鑾峰彇鏃ф暀瀛︿簰鍔ㄧ瓟棰樻暟鎹�
+  getinteractionInfo() {
+    app.MG.identity
+      .getUserKey({
+        domain: "interactionData",
+        keys: [this.data.productLinkPath],
+      })
+      .then((res) => {
+        if (res.length) {
+          let value = JSON.parse(res[0].value);
+          this.setData({
+            submitStatus: value.submitStatus,
+            currentIndex: value.currentIndex,
+          });
+          // 鎼哄甫绛旈璁板綍 鑾峰彇棰樼洰
+          this.getQuestionList(value.dataList);
+        } else {
+          this.getQuestionList(); // 鑾峰彇棰樺簱棰樼洰
+          this.setData({
+            showDialog: true
+          })
+        }
+      });
+  },
+  // 鎻愪氦鏁欏浜掑姩绛旈鏁版嵁
+  setinteractionInfo(submitStatus) {
+    const list = []
+    this.data.cardList.forEach(item => {
+      list.push({
+        catalogName: item.catalogName,
+        path: item.path,
+        infoList: item.infoList.map((citem) => ({
+          id: citem.id,
+          userAnswer: citem.userAnswer
+        }))
+      })
+    })
+    console.log('鎻愪氦鏁版嵁', list);
+    app.MG.identity
+      .setUserKey({
+        setKeyRequests: [{
+          domain: "interactionData",
+          key: this.data.productLinkPath,
+          value: JSON.stringify({
+            submitStatus,
+            currentIndex: this.data.currentIndex,
+            dataList: list
+          }),
+        }, ],
+      })
+      .then((res) => {});
+  },
+  // 澶勭悊鏁欏浜掑姩绛旈 
+  handleClassQuestion() {
+    debugger
+    const flag = this.data.questionDataList.some(item => !item.userAnswer)
+    if (flag) {
+      // 娌″仛瀹岋紝淇濆瓨鍗冲彲
+      const isAnswer = this.data.questionDataList.some(item => item.userAnswer)
+      if (isAnswer) this.setinteractionInfo(false)
+    } else {
+      // 鍋氬畬浜嗭紝鎻愪氦鍒癿essage
+      this.setinteractionInfo(true)
+      if (this.data.classList.length) {
+        this.data.classList.forEach(item => {
+          this.newTopicMessage(item.topicId)
+        })
+      }
+    }
+    this.setData({
+      submitStatus: true
+    })
+  },
+
+  // 鏂板缓topicMessage
+  newTopicMessage(topicId) {
+    let content = []
+    for (let cindex = 0; cindex < this.data.questionDataList.length; cindex++) {
+      const citem = this.data.questionDataList[cindex];
+      content.push({
+        cmsItemId: citem.id,
+        answer: citem.userAnswer,
+        state: citem.questionType == 'shortAnswer' ? 'none' : citem.isRight,
+        type: citem.questionType
+      })
+    }
+    const data = {
+      description: '',
+      icon: '',
+      state: 'Normal',
+      topicIdOrRefCode: String(topicId),
+      name: this.data.answerTitle,
+      content: JSON.stringify({
+        bookId: this.data.bookId,
+        userName: JSON.parse(wx.getStorageSync(app.config.userInfoKey)).name,
+        path: this.data.productLinkPath,
+        content
+      }),
+      type: 'Normal',
+      cmsTypeRefCode: '',
+      newDataListRequest: []
+    }
+    app.MG.ugc.newTopicMessage(data).then((res) => {
+      if (res) {
+        this.setData({
+          isShowDialog: true
+        })
+      }
+    })
+  },
+  // 鏂板缓瀛恡opicMessage
+  // newTopicSubMessage(parentId,topicId) {
+  //   const data = {
+  //     description: '',
+  //     icon: '',
+  //     parentId,
+  //     state: 'Normal',
+  //     topicIdOrRefCode: String(topicId),
+  //     name: this.data.answerTitle,
+  //     content: '',
+  //     type: 'Normal',
+  //     cmsTypeRefCode: '',
+  //     newDataListRequest: []
+  //   }
+  //   MG.ugc.newTopicMessage(data).then((res) => {
+  //     if (res) {
+
+  //     }
+  //   })
+  // },
 });
\ No newline at end of file

--
Gitblit v1.9.1