123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- 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})
- }
- })
- }
- })
|