let app = getApp() const util = require("../../../utils/util") Page({ data: { id:0, groupId:0, preList:["A","B","C", "D", "E", "F"], info:{}, total:0, unfinish:0, answerId:0, index:0, maxIndex:0, type:1, showResult: false, answerMap:{}, showResult: false, isConfirm: false, types:{ 1:'判断题', 2:'单选题', 3:'多选题', 4:'案例题' }, groupId:0 }, onLoad: function(options) { let id = +options.id||0; let groupId = +options.groupId||0; let type = +options.type||1; let total = +options.count ||0; let index = +options.index ||-1; let maxIndex=index; this.setData({ id, type, total, index,groupId,maxIndex}); }, 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, index:-1}) this.loadAnswer() }) }, loadAnswer( ){ let {groupId, type, showResult} = this.data; let param = {groupId, type, index: this.data.index}; app.formPost('Exam.LoadAnswerLimitNew', param).then(res => { if (res.code ==200) { let {unfinish, info, total, maxIndex, index} = res.data let answerId = info&&info.answerId||0; if( showResult) info.select = info.result; this.setData({unfinish, total, info,index, answerId, maxIndex}) wx.pageScrollTo({ scrollTop: 0 }) } }) }, radioChange( e ){ let cid=e.currentTarget.dataset.cid; let info = this.data.info if( info.child ){ info.child[cid].select = +e.detail.value }else{ info.select = +e.detail.value } this.setData( {info} ); }, checkboxChange( e ){ let cid=e.currentTarget.dataset.cid; let info = this.data.info let result = ""+info.result let select = +e.detail.value.sort().join("") if (select == result ){ info._select = true }else{ for( let i in e.detail.value){ if(result.indexOf( e.detail.value[i] )==-1 ){ info._select = true } } } if( info.child ){ info.child[cid].select = select }else{ info.select = select } this.setData( {info} ); }, restartAnswer(){ this.setData({index:0, showResult:false}) this.loadAnswer() }, prevAnswer( e ){ let {index}= this.data if( index <= 0 ) { util.showMsg("已经在第一题") return } index--; this.setData({index,isConfirm:false}) this.loadAnswer() }, nextAnswer( e ){ let {index, total}= this.data if( index >= total-1 ) { util.showMsg("已经最后一题") return; } index++; this.setData({index,isConfirm:false}) this.loadAnswer() }, confirmAnswer(){ let {id, groupId, type,answerId, index, info} = this.data let correct = 1 let result = []; if( !info.child ){ correct = info.select == info.result?1:0; result.push( info.select ) }else{ for( let i in info.child){ if( info.child[i].select != info.child[i].result ){ correct= 0 } result.push( info.child[i].select ) } } let param ={id, groupId, answerId, index, type, correct,result}; app.formPost('Exam.finishAnswerLimitNew', param).then( res=>{ if( res.code == 200){ this.setData({isConfirm:true}) } }) } })