From 09e445694a7360893a17152252f2dc5c1b77b2cf Mon Sep 17 00:00:00 2001 From: zhongshujie <2862698242@qq.com> Date: 星期四, 12 十二月 2024 17:01:39 +0800 Subject: [PATCH] 量表提交保存 --- packageBookService/pages/psychologyAnswer/psychologyAnswer.js | 148 +++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 129 insertions(+), 19 deletions(-) diff --git a/packageBookService/pages/psychologyAnswer/psychologyAnswer.js b/packageBookService/pages/psychologyAnswer/psychologyAnswer.js index 1c612c6..ccdacf5 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,6 +9,7 @@ * 椤甸潰鐨勫垵濮嬫暟鎹� */ data: { + questuionName: "", //璇曞嵎鍚嶇О dataList: "", barHeight: "", navBarHeight: "", @@ -31,6 +29,7 @@ sliderValue: 0, // 瀛椾綋婊戝潡 showDialog: false, // 鏈彁浜ら��鍑烘嫤鎴脊绐� showId: '', + uuid: "", isShowDialog: false, // 娴嬭瘯鎶ュ憡寮圭獥鏄惁鏄剧ず }, @@ -38,21 +37,14 @@ * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 */ onLoad(options) { - const indexof = options.listIndex; + 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; // 瀵艰埅鏍忛珮搴� - 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 - }); - wx.setNavigationBarTitle({ - title: pastData.postData.list[indexof].name, - }) const token = wx.getStorageSync(app.config.tokenKey) if (!token) { loginInfo(app, (data) => { @@ -493,16 +485,57 @@ 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, }); }, // 鍒濆鍖栧嚱鏁� - async init() { + async init(isReset) { this.setData({ loading: false, }); + 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 +543,6 @@ // 娓呯┖姝g‘棰樻暟璁板綍 this.setData({ noData: false, - cardList: [], correctNum: 0, }); }, @@ -520,6 +552,7 @@ const questionList = this.data.questionDataList; const optionList = this.data.questionDataOptions; const scoreData = this.data.scoreDataList; + debugger for (let index = 0; index < questionList.length; index++) { const item = questionList[index]; if (item.questionType == 'judge' && item.userAnswer) { @@ -555,7 +588,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,7 +659,82 @@ }) .then((res) => {}); }, - + async restart() { + this.setData({ + 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, + }) + } catch (error) { + this.setData({ + questionDataList: newArr, + scoreDataList: scoreArr + }) + console.log(error); + } + console.log(this.data.scoreDataList, "scoreDataList"); + }); + }, @@ -670,7 +780,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