let app = getApp() const util = require("../../../utils/util") Page({ data: { preList:["A","B","C", "D", "E", "F"], info:{}, total:0, unfinish:0, answerId:0, type:1, showResult: false, types:{ 1:'判断题', 2:'单选题', 3:'多选题', 4:'案例题' }, groupId:0 }, onLoad: function(options) { let groupId = +options.groupId||1; let type = +options.type||1; let total = +options.count ||0; this.setData({ groupId, type, total }); }, onChange(event){ const showResult = event.detail.value; let {info} = this.data; if( showResult ) { info.select = info.result; }else{ info.select = 0 } this.setData({showResult, info}) }, onShow: function(){ app.checkLogin( userInfo =>{ this.setData({userInfo, from:0}) this.loadAnswer() }) }, loadAnswer( ){ let {groupId, type, showResult} = this.data app.formPost('Exam.LoadAnswerLimit', {groupId, type}).then(res => { if (res.code ==200) { let {unfinish, info, total} = res.data let answerId = info&&info.answerId||0; if( showResult) info.select = info.result; this.setData({unfinish, total, info, answerId}) } }) }, checkAnswer( e ){ let item = this.data.item; if( !item.select ){ app.message("还未作答", 'error') return; } let param = {answerId: item.answerId} // 多选 if( item.type == mulSelect ){ item.correct = item.select.join("") == item.result; }else{ item.correct = item.select == item.result; } param.correct = item.correct?1:0 // 打开下一题 app.formPost('Exam.EditErrorAnswer', param).then(res => { this.setData({item, next:true}) }) }, radioChange( e ){ let info = this.data.info info.select = +e.detail.value this.setData( {info} ); }, checkboxChange( e ){ let info = this.data.info info.select = +e.detail.value.sort().join("") let result = ""+info.result if (info.select == result ){ info._select = true }else{ for( let i in e.detail.value){ if(result.indexOf( e.detail.value[i] )==-1 ){ info._select = true } } } this.setData( {info} ); }, restartAnswer(){ let {groupId, type, total, showResult} = this.data let answerId=0 let unfinish = total app.formPost('Exam.finishAnswerLimit', {groupId, answerId, type}).then(res => { if (res.code ==200) { let info = res.data let answerId = info.answerId if( showResult) info.select = info.result; this.setData({info, answerId, unfinish}) } }) }, finishAnswer( e ){ let action = e.currentTarget.dataset.action; let {groupId, unfinish, type, showResult, total} = this.data let correct = this.data.info.select == this.data.info.result?1:0; let answerId = total-unfinish; if( action == "prev"){ if( total<=unfinish ) { util.showMsg("已经在第一题") return } answerId-=1 }else{ if( unfinish<1 ) { util.showMsg("已经最后一题") return; } answerId+=1 } console.log("finishAnswer", action, answerId, unfinish, total) app.formPost('Exam.finishAnswerLimit', {groupId, answerId, type, correct, action}).then(res => { if (res.code ==200) { let info = res.data let answerId = info.answerId unfinish = (action == "prev")?(unfinish+1):(unfinish-1); if( showResult) info.select = info.result; this.setData({info, answerId, unfinish}) } }) } })