From c0ff00c32bca4077b140d0d69b2863851ae31273 Mon Sep 17 00:00:00 2001 From: zhongshujie <2862698242@qq.com> Date: 星期二, 08 七月 2025 16:29:17 +0800 Subject: [PATCH] 优化 --- packageBookService/pages/psychologyAnswer/psychologyAnswer.js | 129 ++++++++++++++++++++++++++++-------------- 1 files changed, 85 insertions(+), 44 deletions(-) diff --git a/packageBookService/pages/psychologyAnswer/psychologyAnswer.js b/packageBookService/pages/psychologyAnswer/psychologyAnswer.js index ad07a50..f4bbd95 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,71 @@ * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 */ onLoad(options) { - const questuionName = 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(); + // 鍦ㄦ杩涜鏄惁璐拱鐨勬煡璇� + const questionId = options.listId; + const bookId = options.bookId + const bookName = options.bookName + const formPath = options.formPath + 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; // 鐩存帴杩斿洖锛岄伩鍏嶆墽琛屽悗缁唬鐮� + } + + // 鍏朵粬閫昏緫 + const questuionName = options.listName; + this.setData({ + questionName: 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(); + } + }); } else { this.init(); } }) - } else { - this.init() - } + .catch((err) => { + console.error('妫�鏌ラ搴撳け璐�:', err); + wx.showToast({ + icon: 'error', + title: '鍔犺浇澶辫触锛岃閲嶈瘯' + }); + }); }, + /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚 @@ -282,22 +327,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 ( @@ -396,6 +433,12 @@ radioChange(citem) } } + const listLength = this.data.questionDataList.length - 1 + if (this.data.currentIndex < listLength) { + this.setData({ + currentIndex: this.data.currentIndex + 1 + }) + } }, // 杈撳叆妗嗚Е鍙� onChangeInput(e) { @@ -471,10 +514,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++) { @@ -497,13 +536,15 @@ }); this.setData({ loading: false, - showDialog: false, + isShowDialog: true, + submitStatus: true, }); }, // 鍒濆鍖栧嚱鏁� async init(isReset) { this.setData({ - loading: false, + isShowDialog: false, + loading: true, }); const questuionName = this.data.questuionName const questuionList = pastData.postData.list @@ -660,6 +701,7 @@ }, async restart() { this.setData({ + isShowDialog: false, currentIndex: 0, submitStatus: false, }); @@ -723,25 +765,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