123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- const app = require('../../utils/util.js');
- const tools = require('../../utils/tools.js');
- Page({
- data: {
- index: 0, // 题目序列
- chooseValue: [], // 选择的答案序列
- questionList: [],
- totalScore: 0,
- id: '', //考试主键id(可取list接口中id)
- paperId: '', //试卷id(可取list接口中paperId)
- answersId: '', // 提交答案
- sessionKey: '',
- },
- /*
- * 单选事件
- */
- radioChange: function (e) {
- let json = {};
- json.currentAnswer = e.detail.value;
- json.id = e.currentTarget.dataset.idx;
- json.questType = e.currentTarget.dataset.questtypes;
- console.log(json, "josnsosjosjdosdjsodjsod");
- this.data.chooseValue[this.data.index] = json;
- const items = this.data.questionList[this.data.index].QuestChoice
- for (let i = 0, len = items.length; i < len; ++i) {
- items[i].checked = items[i].value === e.detail.value
- }
- this.setData({
- questionList: this.data.questionList
- })
- wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
- wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
- wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
- },
- /*
- * 多选事件
- */
- checkboxChange: function (e) {
- console.log(e)
- const questionList = wx.getStorageSync('questionList' + wx.getStorageSync('answersId'));
- console.log(questionList, '我是选项');
- console.log(this.data.index)
- let data = questionList[this.data.index].QuestChoice;
- let json = {};
- let list = e.detail.value;
- let valueData = [];
- data.map(ite => {
- list.map(items => {
- if (ite.name == items) {
- valueData.push(ite.name)
- }
- })
- })
- let aa = valueData.join("||")
- json.currentAnswer = aa;
- json.questType = e.currentTarget.dataset.questtypes;
- json.id = e.currentTarget.dataset.idx;
- console.log(json, "chexboxsssssssssssssssssss");
- this.data.chooseValue[this.data.index] = json;
- const items = this.data.questionList[this.data.index].QuestChoice
- const values = e.detail.value
- for (let i = 0, lenI = items.length; i < lenI; ++i) {
- items[i].checked = false
- for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
- if (items[i].value === values[j]) {
- items[i].checked = true
- break
- }
- }
- }
- this.setData({
- questionList: this.data.questionList
- })
- wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
- wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
- wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
- },
- /*
- * 解答事件
- */
- bindTextAreaBlur(e) {
- let json = {};
- json.currentAnswer = e.detail.value;
- json.id = e.currentTarget.dataset.idx;
- json.questType = e.currentTarget.dataset.questtypes;
- this.data.chooseValue[this.data.index] = json;
- this.data.questionList[this.data.index].currentAnswer = e.detail.value;
- this.setData({
- questionList: this.data.questionList
- })
- wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
- wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
- wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
- },
- /*
- * 下一题/提交 按钮
- */
- nextSubmit: function () {
- // 判断是不是最后一题
- if (this.data.index < this.data.questionList.length - 1) {
- // 渲染下一题
- this.setData({
- index: this.data.index + 1
- })
- wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
- } else {
- if (wx.getStorageSync('chooseValue' + this.data.answersId)) {
- this.setData({
- chooseValue: wx.getStorageSync('chooseValue' + this.data.answersId)
- })
- }
- console.log(this.data.chooseValue, "000000")
- this.submitAll(this.data.chooseValue);
- }
- },
- upSubmit() {
- this.setData({
- index: this.data.index - 1
- })
- wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
- },
- async onLoad(options) {
- wx.showLoading({
- title: '加载中',
- task: true
- })
- const sessionKey = await tools.checkSessionAndLogin();
- wx.setStorageSync('answersId', options.answersId);
- this.setData({
- sessionKey: sessionKey,
- paperId: options.paperId,
- answersId: options.answersId,
- id: options.id,
- })
- if (wx.getStorageSync('questionList' + wx.getStorageSync('answersId'))) {
- const questionList = wx.getStorageSync('questionList' + wx.getStorageSync('answersId'));
- console.log(questionList, "大阪烧");
- const titleINDEX = wx.getStorageSync('titleINDEX' + wx.getStorageSync('answersId'));
- const chooseValue = wx.getStorageSync('chooseValue' + wx.getStorageSync('answersId'));
- console.log(wx.getStorageSync('questionList' + wx.getStorageSync('answersId')))
- this.setData({
- questionList: questionList,
- answersId: wx.getStorageSync('answersId'),
- chooseValue: chooseValue,
- index: titleINDEX
- })
- wx.hideLoading();
- } else {
- this.allShi(options.id, options.paperId, sessionKey);
- }
- },
- allShi(id, paperId, sessionKey) {
- wx.request({
- url: app.globalData.publicUrl + '/wx/paper/detail',
- method: "post",
- data: {
- sessionKey: sessionKey,
- id: id,
- paperId: paperId
- },
- success: (res) => {
- console.log(res)
- let jsonArr = JSON.parse(res.data.paperContent).map(item => {
- let json = {};
- json.QuestType = item.QuestType;
- json.id = item.Id;
- json.QuestAnswer = item.QuestAnswer;
- json.QuestStem = item.QuestStem;
- if (item.QuestChoice) {
- let arr = item.QuestChoice.split('||');
- json.QuestChoice = arr;
- }
- if (item.QuestType == '1') {
- let arr = item.QuestChoice.split('||');
- let arrJson = arr.map(item => {
- let json1 = {};
- json1.name = item;
- json1.value = item;
- json1.checked = false;
- return json1
- });
- json.QuestChoice = arrJson;
- }
- if (item.QuestType == '0') {
- let arr = item.QuestChoice.split('||');
- let arrJson = arr.map(item => {
- let json1 = {};
- json1.name = item;
- json1.value = item;
- json1.checked = false;
- return json1
- });
- json.QuestChoice = arrJson;
- }
- if (item.QuestType == '2') {
- let arr = item.QuestChoice.split('||');
- let arrJson = arr.map(item => {
- let json1 = {};
- json1.name = item;
- json1.value = item;
- json1.checked = false;
- return json1
- });
- json.QuestChoice = arrJson;
- }
- return json;
- })
- this.setData({
- questionList: jsonArr
- })
- wx.hideLoading();
- console.log(this.data.questionList)
- wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), 0);
- wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), []),
- wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
- },
- fail: () => {
- wx.hideLoading()
- }
- })
- },
- submitAll(currentAnswerTemp) {
- wx.showLoading({
- mask: true,
- title: '加载中',
- })
- console.log(currentAnswerTemp, "传值");
- let indexs = currentAnswerTemp.findIndex(item => {
- return !item
- })
- console.log(indexs, "sssssss");
- if (indexs == -1) {
- if (currentAnswerTemp.length == 0) {
- let arr = this.data.questionList.map(item => {
- let json = {};
- json.currentAnswer = '';
- json.questType = item.QuestType;
- json.id = item.id;
- return json
- });
- wx.request({
- url: app.globalData.publicUrl + '/wx/paper/commit',
- method: "post",
- data: {
- sessionKey: this.data.sessionKey,
- currentAnswerTemp: arr,
- answersId: wx.getStorageSync('answersId')
- },
- success: (res) => {
- wx.hideLoading();
- if (res.data.code == 0) {
- wx.showModal({
- showCancel: false,
- content: '恭喜您,提交答案成功,请耐心等待老师判卷',
- success() {
- wx.navigateBack({
- delta: 1
- })
- }
- })
- } else {
- wx.showModal({
- showCancel: false,
- content: res.data.msg,
- success() {
- wx.navigateBack({
- delta: 1
- })
- }
- })
- }
- },
- fail: () => {
- wx.hideLoading()
- }
- })
- } else {
- wx.request({
- url: app.globalData.publicUrl + '/wx/paper/commit',
- method: "post",
- data: {
- sessionKey: this.data.sessionKey,
- currentAnswerTemp: currentAnswerTemp,
- answersId: wx.getStorageSync('answersId')
- },
- success: (res) => {
- wx.hideLoading();
- if (res.data.code == 0) {
- wx.showModal({
- showCancel: false,
- content: '恭喜您,提交答案成功,请耐心等待老师判卷',
- success() {
- wx.navigateBack({
- delta: 1
- })
- }
- })
- } else {
- wx.showModal({
- showCancel: false,
- content: res.data.msg,
- success() {
- wx.navigateBack({
- delta: 1
- })
- }
- })
- }
- },
- fail: () => {
- wx.hideLoading()
- }
- })
- }
- } else {
- wx.hideLoading();
- wx.showModal({
- showCancel: false,
- content: '当前第' + Number(indexs+1) + '没答,请答题',
- })
- }
- }
- })
|