From ecabd20b3dfbd956dad14ffb6ba3dc2efcfdd7c1 Mon Sep 17 00:00:00 2001 From: yiming <m13691596795@163.com> Date: 星期一, 25 三月 2024 16:23:32 +0800 Subject: [PATCH] 微信支付 --- packageBookService/pages/bookServices/examination/examination.js | 117 +++++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 91 insertions(+), 26 deletions(-) diff --git a/packageBookService/pages/bookServices/examination/examination.js b/packageBookService/pages/bookServices/examination/examination.js index 6b82781..e444433 100644 --- a/packageBookService/pages/bookServices/examination/examination.js +++ b/packageBookService/pages/bookServices/examination/examination.js @@ -48,6 +48,15 @@ * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 */ onLoad(options) { + // wx.enableAlertBeforeUnload({ + // message: "鏈彁浜わ紝鏄惁閫�鍑虹瓟棰橈紵", + // success: function (res) { + // console.log('纭畾', res); + // }, + // fail: function (err) { + // console.log("澶辫触锛�", err); + // }, + // }); const systInfo = wx.getSystemInfoSync(); const menu = wx.getMenuButtonBoundingClientRect(); // 鑳跺泭淇℃伅 const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 瀵艰埅鏍忛珮搴� @@ -75,13 +84,17 @@ * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚 */ onReady() { - }, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず */ onShow() { + if (this.data.answerType != 'mock') { + if (wx.timer) { + clearInterval(wx.timer) + } + } if (this.data.answerType == 'mock') { if (wx.timer) { clearInterval(wx.timer) @@ -101,13 +114,18 @@ * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰闅愯棌 */ onHide() { - + if (wx.timer) { + clearInterval(wx.timer) + } }, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍗歌浇 */ - onUnload() { + onUnload(e) { + if (wx.timer) { + clearInterval(wx.timer) + } if (this.data.countdownInterval !== null) { clearInterval(this.data.countdownInterval) } @@ -132,8 +150,29 @@ */ onShareAppMessage() { }, + + // 鐩戝惉watch + watch(context, variableName, callback) { + let value = context.data[variableName]; // 鑾峰彇琚洃鍚睘鎬х殑褰撳墠鍊� + + // 浣跨敤 Object.defineProperty 鏂规硶鍦ㄦ暟鎹璞′笂瀹氫箟灞炴�х殑 getter 鍜� setter + Object.defineProperty(context.data, variableName, { + configurable: true, // 鍙厤缃� + enumerable: true, // 鍙灇涓� + get: function () { + return value; // 杩斿洖灞炴�х殑褰撳墠鍊� + }, + set: function (newVal) { + const oldVal = value; // 璁板綍灞炴�х殑鏃у�� + value = newVal; // 鏇存柊灞炴�х殑鍊� + callback.call(context, newVal, oldVal); // 璋冪敤鍥炶皟鍑芥暟锛屼紶閫掓柊鍊煎拰鏃у�� + } + }); + }, + // 杩斿洖 goBack() { + console.log(this.data.submitStatus); wx.navigateBack(); }, //璁剧疆鑳屾櫙鑹� @@ -201,10 +240,11 @@ 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) - + if (this.data.answerType == 'collectQuestion' || this.data.answerType == 'errorQuestion') { + 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) { @@ -229,8 +269,18 @@ item.isUserAnswer = this.isHaveAnswer(radioChecked) } }) + const cardListUpdata = this.data.cardList + cardListUpdata.forEach(item => { + item.infoList.forEach(citem => { + if (citem.id == id) { + citem.userAnswer = radioChecked + citem.isUserAnswer = this.isHaveAnswer(radioChecked) + } + }) + }) this.setData({ - questionDataList: questionList + questionDataList: questionList, + cardList: cardListUpdata }) if (this.data.answerType == 'mock') { this.setData({ @@ -242,16 +292,27 @@ 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 index = Number(e.detail.value.currentTarget.dataset.index) + console.log(index); const questionList = this.data.questionDataList questionList.forEach(item => { if (item.id == id) { - item.userAnswer[index] = inputData, - item.isUserAnswer = this.isHaveAnswer(item.userAnswer) + item.userAnswer[index] = inputData + return item.isUserAnswer = this.isHaveAnswer(inputData) } }) + const cardListUpdata = this.data.cardList + cardListUpdata.forEach(item => { + item.infoList.forEach(citem => { + if (citem.id == id) { + citem.userAnswer[index] = inputData + return citem.isUserAnswer = this.isHaveAnswer(inputData) + } + }) + }) this.setData({ - questionDataList: questionList + questionDataList: questionList, + cardList: cardListUpdata, }) if (this.data.answerType == 'mock') { this.setData({ @@ -295,6 +356,8 @@ }, // 鎻愪氦閫昏緫 submitPaper() { + // 鍏抽棴閫�鍑洪〉闈㈢洃鍚� + wx.disableAlertBeforeUnload() this.setData({ submitStatus: true }) @@ -406,18 +469,19 @@ let oldQuestionList = [] oldQuestionList = await this.getMockQuestionList() const userAnswerList = await this.getMockAnswer() - await this.getMockDataList(oldQuestionList, userAnswerList) this.setData({ 'mockData.sumTime': oldMockData.time, cardList: oldQuestionList }) + await this.getMockDataList(oldQuestionList, userAnswerList) } if (oldMockData.state == '0' || oldMockData.state == '1' || oldMockData.state == '2') { this.startCountdown() } if (oldMockData.state == '3') { this.setData({ - submitStatus: true + submitStatus: true, + subjectiveNum: oldMockData.report.userScore }) } } @@ -495,6 +559,7 @@ let value = JSON.parse(res[0].value) // 鏈夌瓟棰樿褰曪紝寰楀垎璧嬪�� if (value) { + wx.disableAlertBeforeUnload() this.setData({ submitStatus: true }) @@ -508,6 +573,7 @@ this.setData({ currentIndex: value.currentIndex }) + console.log(this.data.submitStatus); // 鎼哄甫绛旈璁板綍 鑾峰彇棰樼洰 await this.getQuestionList(value.dataList) } else { @@ -530,19 +596,19 @@ errorList: JSON.parse(res[0].value) }) } catch (error) { - } }) }, // 鑾峰彇棰樺簱棰樼洰 - getQuestionList(oldData) { + async getQuestionList(oldData) { // 娓呯┖姝g‘棰樻暟璁板綍 this.setData({ cardList: [], correctNum: 0, }) let flag = 0 - this.data.idPathList.forEach((pathitem) => { + for (let index = 0; index < this.data.idPathList.length; index++) { + const pathitem = this.data.idPathList[index]; const pathList = this.data.cardList pathList.push({ path: pathitem.productLinkPath, @@ -575,7 +641,7 @@ size: 999 } } - app.MG.store.getProductDetail(query).then((res) => { + await app.MG.store.getProductDetail(query).then((res) => { this.setData({ total: res.datas.cmsDatas[0].datas.length }) @@ -705,13 +771,13 @@ }) this.setData({ questionDataList: questionList, - cardList: cardUpdatedList + cardList: cardUpdatedList, }) }) }) - }) + } this.setData({ - loading: false, + loading: false }) }, // 鎵规敼棰樼洰 锛堢粌涔狅紝鎴戠殑閿欓锛屾垜鐨勬敹钘�,锛岀粍鍗凤級 @@ -1335,7 +1401,8 @@ // 鑾峰彇缁勫嵎棰樼洰鍒楄〃 async getMockDataList(questionList, oldList) { const questionDataList = this.data.questionDataList - questionList.forEach(async (pathitem, pathindex) => { + for (let pathindex = 0; pathindex < questionList.length; pathindex++) { + const pathitem = questionList[pathindex]; let itemIds = [] pathitem.infoList.forEach(item => { itemIds.push(item.id + '') @@ -1394,7 +1461,7 @@ isUserAnswer: oldObj ? this.isHaveAnswer(oldObj.userAnswer) : false, isRight: oldObj ? oldObj.isRight : null, // isComplete: oldObj ? oldObj.isComplete : false, - isComplete: this.data.mockData.state == '3' ? true : oldObj ? this.isHaveAnswer(oldObj.answer) : false, + isComplete: this.data.mockData.state == '3' ? true : false, isCollect: this.data.collectList.indexOf(item.id) > -1 ? true : false, isUnfold: '' // 鎺у埗瑙f瀽鐨勬姌鍙犻潰鏉挎槸鍚﹀睍寮� } @@ -1462,12 +1529,10 @@ questionDataList: questionList, cardList: cardUpdatedList }) - console.log('缁勫嵎棰樼洰鍒楄〃', this.data.questionDataList); }) }) - }) + } this.setData({ - // questionDataList: questionDataList, loading: false }) }, -- Gitblit v1.9.1