From c192e381734b9caf173c90bb9141dff0326785ee Mon Sep 17 00:00:00 2001
From: QYF-GitLab1 <1940665526@qq.com>
Date: 星期四, 17 七月 2025 14:20:11 +0800
Subject: [PATCH] 京师智教小程序的专题活动模块      不做点击进入页面提示复制链接       点击时直接提示“请移步PC端查看”

---
 packageBookService/pages/psychologyAnswer/psychologyAnswer.js |  301 ++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 243 insertions(+), 58 deletions(-)

diff --git a/packageBookService/pages/psychologyAnswer/psychologyAnswer.js b/packageBookService/pages/psychologyAnswer/psychologyAnswer.js
index 1c612c6..77d6c63 100644
--- a/packageBookService/pages/psychologyAnswer/psychologyAnswer.js
+++ b/packageBookService/pages/psychologyAnswer/psychologyAnswer.js
@@ -1,8 +1,5 @@
 // packageBookService/pages/psychologyAnswer/psychologyAnswer.js
 import {
-  getPublicImage
-} from "../../../assets/js/middleGround/tool";
-import {
   loginInfo
 } from '../../../assets/js/login';
 const app = getApp();
@@ -12,10 +9,12 @@
    * 椤甸潰鐨勫垵濮嬫暟鎹�
    */
   data: {
+    isBuy: false, // 鏄惁闇�瑕佽喘涔�
+    questuionName: "", //璇曞嵎鍚嶇О
     dataList: "",
     barHeight: "",
     navBarHeight: "",
-    loading: false,
+    loading: true,
     answerTitle: "", // 瀵艰埅鏍忔爣棰�
     submitStatus: false, // 鎻愪氦鐘舵��
     currentIndex: 0, // 褰撳墠鏄剧ず鐨勯鍙�
@@ -31,6 +30,7 @@
     sliderValue: 0, // 瀛椾綋婊戝潡
     showDialog: false, // 鏈彁浜ら��鍑烘嫤鎴脊绐�
     showId: '',
+    uuid: "",
     isShowDialog: false, // 娴嬭瘯鎶ュ憡寮圭獥鏄惁鏄剧ず
   },
 
@@ -38,34 +38,86 @@
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
    */
   onLoad(options) {
-    const indexof = options.listIndex;
-    const systInfo = wx.getSystemInfoSync();
-    const menu = wx.getMenuButtonBoundingClientRect(); // 鑳跺泭淇℃伅
-    const navBarHeight =
-      (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 瀵艰埅鏍忛珮搴�
+    // 鍦ㄦ杩涜鏄惁璐拱鐨勬煡璇�
+    const questionName = options.listName
     this.setData({
-      dataList: pastData,
-      questionDataList: pastData.postData.list[indexof].list,
-      questionDataTitle: pastData.postData.list[indexof].title,
-      questionDataOptions: pastData.postData.list[indexof].optionList,
-      scoreDataList: pastData.postData.list[indexof].scoreData
+      questuionName: questionName
     });
-    wx.setNavigationBarTitle({
-      title: pastData.postData.list[indexof].name,
-    })
-    const token = wx.getStorageSync(app.config.tokenKey)
-    if (!token) {
-      loginInfo(app, (data) => {
-        if (data) {
-          this.init();
-        } else {
-          this.init();
-        }
-      })
+    const isEmption = questionName.includes('-璇勫')
+    if (isEmption) {
+      this.initialize()
     } else {
-      this.init()
+      const questionList = pastData.postData.list
+      var listIndex = 0
+      for (let index = 0; index < questionList.length; index++) {
+        const item = questionList[index];
+        if (item.name == questionName) {
+          listIndex = index
+        }
+      }
+      const indexof = listIndex
+      const idPath = questionList[indexof].idPath;
+      const bookId = questionList[indexof].bookId;
+      const bookName = "澶у鐢熷績鐞嗗仴搴凤紙绗�3鐗堬級锛堣瀺濯掍綋鐗堬級"
+      const formPath = "questionBank"
+      // 杩涜澶勭悊
+      const query = {
+        path: "*",
+        queryType: "*",
+        productId: bookId,
+        cmsPath: "161796",
+        cmsType: "*"
+      };
+      app.MG.store.getProductDetail(query).then(async (res) => {
+        const linkPathList = res.datas.cmsDatas[0].datas
+        const isBuyList = res.datas.purchasedSaleMethodIdList
+        let isBuy = false
+        const idParhList = idPath.split("/").reverse()
+        for (let index = 0; index < idParhList.length; index++) {
+          const item = idParhList[index];
+          const thisItem = linkPathList.find(citem => item == citem.id);
+          if (thisItem.saleMethod.length > 0) {
+            if (isBuyList.includes(thisItem.saleMethod[0].Id) || thisItem.saleMethod[0].Price == 0) {
+              isBuy = true
+              break
+            } else {
+              isBuy = false
+              break
+            }
+          }
+        }
+        this.setData({
+          isBuy: isBuy
+        });
+        if (!isBuy) {
+          wx.showModal({
+            icon: 'error',
+            title: '娓╅Θ鎻愮ず',
+            content: '璇疯喘涔伴搴擄紝鍗冲皢杩斿洖璐拱椤�',
+            confirmText: '纭畾',
+            showCancel: false, // 鍏抽棴鍙栨秷鎸夐挳
+            success: function (res) {
+              if (res.confirm) {
+                wx.navigateTo({
+                  url: '/packageBookService/pages/bookServices/detail/index?id=' + bookId + '&name=' + bookName + '&tabValue=' + formPath,
+                })
+              }
+            }
+          });
+          return; // 鐩存帴杩斿洖锛岄伩鍏嶆墽琛屽悗缁唬鐮�
+        }
+        // 鍏朵粬閫昏緫
+        this.initialize()
+      }).catch((err) => {
+        console.error('妫�鏌ラ搴撳け璐�:', err);
+        wx.showToast({
+          icon: 'error',
+          title: '鍔犺浇澶辫触锛岃閲嶈瘯'
+        });
+      });
     }
   },
+
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚
@@ -94,6 +146,7 @@
         }
       }, 1000);
     }
+
     this.setData({
       startTime: Date.now(),
     });
@@ -115,6 +168,7 @@
     }
   },
 
+
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍗歌浇
    */
@@ -131,6 +185,25 @@
     if (wx.getStorageSync(app.config.tokenKey)) {
       let duration = this.data.pauseTime - this.data.startTime;
       this.count(duration);
+    }
+  },
+
+  initialize() {
+    const systInfo = wx.getSystemInfoSync();
+    const menu = wx.getMenuButtonBoundingClientRect(); // 鑳跺泭淇℃伅
+    const navBarHeight =
+      (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 瀵艰埅鏍忛珮搴�
+    const token = wx.getStorageSync(app.config.tokenKey);
+    if (!token) {
+      loginInfo(app, (data) => {
+        if (data) {
+          this.init();
+        } else {
+          this.init();
+        }
+      });
+    } else {
+      this.init();
     }
   },
 
@@ -290,22 +363,14 @@
   },
   // 鍒囨崲棰樼洰
   changeSwiper(e) {
-    let index = e.detail.index - 1 >= 0 ? e.detail.index - 1 : 0;
-    const item = this.data.questionDataList[index];
-    const lastItem = this.data.questionDataList[index + 1];
+    let index = e.detail.index;
+    const lastItem = this.data.questionDataList[index];
     this.setData({
       currentIndex: e.detail.index,
       showId: lastItem.id
     });
-    if (
-      (this.data.answerType == "collectQuestion" ||
-        this.data.answerType == "errorQuestion") &&
-      !item.isComplete
-    ) {
-      let flag = this.isHaveAnswer(item.userAnswer);
-      if (flag) this.handleQuestion(index);
-    }
   },
+
   // 鎴戠殑閿欓锛屾敹钘忔煡鐪嬭В鏋愭寜閽�
   viewParsing() {
     if (
@@ -404,6 +469,12 @@
         radioChange(citem)
       }
     }
+    const listLength = this.data.questionDataList.length - 1
+    if (this.data.currentIndex < listLength) {
+      this.setData({
+        currentIndex: this.data.currentIndex + 1
+      })
+    }
   },
   // 杈撳叆妗嗚Е鍙�
   onChangeInput(e) {
@@ -479,10 +550,6 @@
     // 鍏堥亶鍘嗘墍鏈夐鐩紝灏嗘湭鎵规敼鐨勯鐩壒鏀�
     const qustionList = this.data.questionDataList;
     if (qustionList.length) this.handleQuestion();
-    this.setData({
-      isShowDialog: true,
-      submitStatus: true,
-    })
     // 璁板綍鐢ㄦ埛绛旈鏁版嵁
     let saveData = [];
     for (let index = 0; index < this.data.questionDataList.length; index++) {
@@ -493,16 +560,59 @@
         isRight: item.isRight,
       });
     }
+    app.MG.identity.setUserKey({
+      setKeyRequests: [{
+        domain: "answerData",
+        key: this.data.uuid,
+        value: JSON.stringify({
+          answerData: saveData,
+          scoreData: this.data.scoreDataList
+        }),
+      }, ],
+    });
     this.setData({
       loading: false,
-      showDialog: false,
+      isShowDialog: true,
+      submitStatus: true,
     });
   },
   // 鍒濆鍖栧嚱鏁�
-  async init() {
+  async init(isReset) {
     this.setData({
-      loading: false,
+      isShowDialog: false,
+      loading: true,
     });
+    const questuionName = this.data.questuionName
+    const questuionList = pastData.postData.list
+    var listIndex = 0
+    for (let index = 0; index < questuionList.length; index++) {
+      const item = questuionList[index];
+      if (item.name == questuionName) {
+        listIndex = index
+      }
+    }
+    const indexof = listIndex;
+    this.setData({
+      dataList: pastData,
+      // questionDataList: pastData.postData.list[indexof].list,
+      questionDataTitle: pastData.postData.list[indexof].title,
+      questionDataOptions: pastData.postData.list[indexof].optionList,
+      // scoreDataList: pastData.postData.list[indexof].scoreData,
+      uuid: pastData.postData.list[indexof].name
+    });
+    wx.setNavigationBarTitle({
+      title: pastData.postData.list[indexof].name,
+    })
+    const list = [...pastData.postData.list[indexof].list]
+    const scoreList = [...pastData.postData.list[indexof].scoreData]
+    if (isReset) {
+      list.forEach(item => item.userAnswer = "")
+      scoreList.forEach(item => {
+        item.dispatch = "",
+          item.score = 0
+      })
+    }
+    this.getAnswerInfo(list, scoreList)
   },
 
   // 鑾峰彇棰樺簱棰樼洰
@@ -510,7 +620,6 @@
     // 娓呯┖姝g‘棰樻暟璁板綍
     this.setData({
       noData: false,
-      cardList: [],
       correctNum: 0,
     });
   },
@@ -555,7 +664,9 @@
       const scoreItem = scoreData[cindex];
       if (scoreItem.range == 'all') {
         questionList.forEach((item) => {
-          scoreItem.score += item.score
+          if (item.score) {
+            scoreItem.score += item.score
+          }
         })
       } else {
         questionList.forEach((item, index) => {
@@ -624,16 +735,90 @@
       })
       .then((res) => {});
   },
-
-
-
-
-
-
-
-
-
-
+  async restart() {
+    this.setData({
+      isShowDialog: false,
+      currentIndex: 0,
+      submitStatus: false,
+    });
+    await app.MG.identity.setUserKey({
+      setKeyRequests: [{
+        domain: "answerData",
+        key: this.data.uuid,
+        value: JSON.stringify({
+          answerData: [],
+        }),
+      }, ],
+    });
+    this.init(true);
+  },
+  openIsShowDialog() {
+    this.setData({
+      isShowDialog: true,
+    })
+  },
+  // 鑾峰彇鏃х瓟棰樻暟鎹�
+  getAnswerInfo(arr, scoreListArr) {
+    let newArr = [...arr];
+    let scoreArr = [...scoreListArr];
+    app.MG.identity
+      .getUserKey({
+        domain: "answerData",
+        keys: [this.data.uuid],
+      })
+      .then((res) => {
+        try {
+          const data = JSON.parse(res[0].value)
+          if (data.answerData?.length > 0 && newArr.length) {
+            this.setData({
+              isShowDialog: true,
+              submitStatus: true,
+            })
+            newArr.forEach(item => {
+              const obj = data.answerData.find(citem => citem.id == item.id)
+              if (obj?.answer) {
+                item.userAnswer = obj.answer
+              } else {
+                item.userAnswer = ""
+              }
+            })
+          }
+          if (data.scoreData?.length > 0 && scoreArr.length) {
+            scoreArr.forEach(item => {
+              const obj = data.scoreData.find(citem => citem.name == item.name)
+              if (obj?.score) {
+                item.score = obj.score
+              } else {
+                item.score = 0
+              }
+              if (obj?.dispatch) {
+                item.dispatch = obj.dispatch
+              } else {
+                item.dispatch = ""
+              }
+            })
+          }
+          this.setData({
+            questionDataList: newArr,
+            scoreDataList: scoreArr,
+            loading: false,
+          })
+        } catch (error) {
+          this.setData({
+            questionDataList: newArr,
+            scoreDataList: scoreArr,
+            loading: false,
+          })
+          console.log(error);
+        }
+        const e = {
+          detail: {
+            index: 0
+          }
+        };
+        this.changeSwiper(e)
+      });
+  },
 
   // 璁板綍妯¤�冪瓟棰樻暟鎹�
   saveMockData() {
@@ -670,7 +855,7 @@
     app.MG.identity
       .setUserKey({
         setKeyRequests: [{
-          domain: "mockAnswerData",
+          domain: "answerData",
           key: this.data.uuid,
           value: JSON.stringify({
             currentIndex: this.data.currentIndex,

--
Gitblit v1.9.1