let app = getApp() Page({ data: { preList:["A","B","C", "D", "E", "F"], info:{}, total:0, unfinish:0, answerId:0, type:1, 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 }); }, onShow: function(){ app.checkLogin( userInfo =>{ this.setData({userInfo, from:0}) this.loadAnswer() }) }, loadAnswer( ){ let {groupId, type} = this.data app.formPost('Exam.LoadAnswer', {groupId, type}).then(res => { if (res.code ==200) { let {unfinish, info} = res.data let answerId = info&&info.answerId||0; this.setData({unfinish, 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} = this.data let answerId=0 let unfinish = total app.formPost('Exam.finishAnswer', {groupId, answerId, type}).then(res => { if (res.code ==200) { let info = res.data let answerId = info.answerId this.setData({info, answerId, unfinish}) } }) }, finishAnswer( ){ let {groupId, answerId, unfinish, type} = this.data let correct = this.data.info.select == this.data.info.result?1:0; app.formPost('Exam.finishAnswer', {groupId, answerId, type, correct}).then(res => { if (res.code ==200) { let info = res.data let answerId = info.answerId unfinish = unfinish-1 this.setData({info, answerId, unfinish}) } }) } })