From 0b04ed8c61813de116127100c5236bb2ff040682 Mon Sep 17 00:00:00 2001
From: QYF-GitLab1 <1940665526@qq.com>
Date: 星期三, 16 七月 2025 21:56:15 +0800
Subject: [PATCH] 资源扫码

---
 packageBookService/pages/psychologyAnswer/psychologyAnswer.js |  131 +++++++++++++++++++++++++++++++++----------
 1 files changed, 99 insertions(+), 32 deletions(-)

diff --git a/packageBookService/pages/psychologyAnswer/psychologyAnswer.js b/packageBookService/pages/psychologyAnswer/psychologyAnswer.js
index a913ecf..8911ba3 100644
--- a/packageBookService/pages/psychologyAnswer/psychologyAnswer.js
+++ b/packageBookService/pages/psychologyAnswer/psychologyAnswer.js
@@ -9,11 +9,12 @@
    * 椤甸潰鐨勫垵濮嬫暟鎹�
    */
   data: {
+    isBuy: false, // 鏄惁闇�瑕佽喘涔�
     questuionName: "", //璇曞嵎鍚嶇О
     dataList: "",
     barHeight: "",
     navBarHeight: "",
-    loading: false,
+    loading: true,
     answerTitle: "", // 瀵艰埅鏍忔爣棰�
     submitStatus: false, // 鎻愪氦鐘舵��
     currentIndex: 0, // 褰撳墠鏄剧ず鐨勯鍙�
@@ -37,27 +38,67 @@
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
    */
   onLoad(options) {
-    const questuionName = options.listName
+    // 鍦ㄦ杩涜鏄惁璐拱鐨勬煡璇�
+    const questionName = options.listName
     this.setData({
-      questuionName: questuionName
-    })
-    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();
-        }
-      })
+      questuionName: questionName
+    });
+    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 questionId = questionList[indexof].id;
+      const bookId = questionList[indexof].bookId;
+      const bookName = "澶у鐢熷績鐞嗗仴搴凤紙绗�3鐗堬級锛堣瀺濯掍綋鐗堬級"
+      const formPath = "questionBank"
+      const query = {
+        "cmsItemId": Number(questionId)
+      };
+      app.MG.file.checkCmsItem(query)
+        .then((res) => {
+          const isBuys = res;
+          this.setData({
+            isBuy: isBuys
+          });
+          if (!isBuys) {
+            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: '鍔犺浇澶辫触锛岃閲嶈瘯'
+          });
+        });
     }
   },
+
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚
@@ -86,6 +127,7 @@
         }
       }, 1000);
     }
+
     this.setData({
       startTime: Date.now(),
     });
@@ -107,6 +149,7 @@
     }
   },
 
+
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍗歌浇
    */
@@ -123,6 +166,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();
     }
   },
 
@@ -289,6 +351,7 @@
       showId: lastItem.id
     });
   },
+
   // 鎴戠殑閿欓锛屾敹钘忔煡鐪嬭В鏋愭寜閽�
   viewParsing() {
     if (
@@ -387,6 +450,12 @@
         radioChange(citem)
       }
     }
+    const listLength = this.data.questionDataList.length - 1
+    if (this.data.currentIndex < listLength) {
+      this.setData({
+        currentIndex: this.data.currentIndex + 1
+      })
+    }
   },
   // 杈撳叆妗嗚Е鍙�
   onChangeInput(e) {
@@ -484,9 +553,6 @@
     });
     this.setData({
       loading: false,
-      showDialog: false,
-    });
-    this.setData({
       isShowDialog: true,
       submitStatus: true,
     });
@@ -494,7 +560,8 @@
   // 鍒濆鍖栧嚱鏁�
   async init(isReset) {
     this.setData({
-      loading: false,
+      isShowDialog: false,
+      loading: true,
     });
     const questuionName = this.data.questuionName
     const questuionList = pastData.postData.list
@@ -651,6 +718,7 @@
   },
   async restart() {
     this.setData({
+      isShowDialog: false,
       currentIndex: 0,
       submitStatus: false,
     });
@@ -714,25 +782,24 @@
           this.setData({
             questionDataList: newArr,
             scoreDataList: scoreArr,
+            loading: false,
           })
         } catch (error) {
           this.setData({
             questionDataList: newArr,
-            scoreDataList: scoreArr
+            scoreDataList: scoreArr,
+            loading: false,
           })
           console.log(error);
         }
+        const e = {
+          detail: {
+            index: 0
+          }
+        };
+        this.changeSwiper(e)
       });
   },
-
-
-
-
-
-
-
-
-
 
   // 璁板綍妯¤�冪瓟棰樻暟鎹�
   saveMockData() {

--
Gitblit v1.9.1