123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- let app = getApp()
- const util = require("../../../utils/util")
- Page({
- data: {
- preList:["A","B","C", "D", "E", "F"],
- info:{},
- total:0,
- unfinish:0,
- answerId:0,
- index:0,
- type:1,
- answerMap:{},
- 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.LoadAnswerNew', {groupId, type}).then(res => {
- if (res.code ==200) {
- let {unfinish, info, total} = res.data;
- let index = total- unfinish;
- if(showResult) info.select = info.result;
- this.setData({unfinish, total, info, index})
- }
- })
- },
- checkAnswer( e ){
- let {showResult, info, answerMap, groupId} = this.data;
- let answerId= info.answerId||0;
- if( showResult ) return;
- if(!answerId) return;
- let param = {answerId, groupId}
- // 多选
- if( info.type == 3 ){
- info.correct = info.select == info.result;
- }else{
- info.correct = info.select == info.result;
- }
- param.correct = info.correct?1:0;
- let result = answerMap[answerId];
- if( result === param.correct) return;
- answerMap[answerId] = param.correct;
- // 打开下一题
- app.formPost('Exam.EditErrorAnswer', param).then(res => {
- this.setData({info, next:true, answerMap})
- })
- },
- 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, showResult} = this.data
- app.formPost('Exam.resetAnswerNew', {groupId, type}).then(res => {
- if (res.code ==200) {
- let {total, unfinish,info} = res.data
- let index = total - unfinish;
- if(showResult) info.select = info.result;
- this.setData({info, index, total, unfinish})
- }
- })
- },
- finishAnswer( e ){
- this.checkAnswer()
- let action = e.currentTarget.dataset.action;
- let {groupId, unfinish, type, showResult, total, index} = this.data
- let correct = this.data.info.select == this.data.info.result?1:0;
- if( action == "prev"){
- if( total <= unfinish ) {
- util.showMsg("已经在第一题")
- return
- }
- unfinish+=1
- }else{
- if( unfinish < 1 ) {
- util.showMsg("已经最后一题")
- return;
- }
- unfinish-=1
- }
- app.formPost('Exam.finishAnswerNew', {groupId, index, type, correct, action}).then(res => {
- if (res.code ==200) {
- let info = res.data
- let index = total-unfinish;
- if( showResult) info.select = info.result;
- this.setData({info, unfinish, index})
- }
- })
- }
- })
|