123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- import {
- formatSeconds
- } from '../../../utils/util.js'
- let app = getApp()
- let mulSelect = 3
- Page({
- data: {
- list: [],
- redo: false,
- preList:["A","B","C", "D","E","F"],
- info:{},
- id:0,
- timer: null,
- doTime: 0,
- remainTime: 0,
- remainTimeStr: '',
- modalShow: false,
- isFinish: false,
- result: {},
- startTime: "",
- timeOutShow: false
- },
- onLoad: function(options) {
- let groupId = +options.id||3
- let redo = !!options.redo;
- this.setData({redo})
- let method = redo?'Exam.examreStart':'Exam.examStartLimit';
- let _this = this
- let oindex = [2,3,1]
- app.formPost(method, {groupId}).then(res => {
- if (res.code ==200) {
- let {startTime, info, list} = res.data;
- let duration = info.duration
- list = list.map(item=>{
- delete( item["select"])
- return item
- })
- wx.setNavigationBarTitle({
- title: info.title+'-模拟考试'
- })
- _this.setData({
- list: list,
- info: info,
- startTime: startTime,
- remainTime: duration
- });
- _this.timeReduce()
- }
- })
- },
- timeReduce() {
- let _this = this
- let timer = setInterval(function() {
- let remainTime = _this.data.remainTime
- if (remainTime <= 0) {
- _this.timeOut()
- } else {
- _this.setData({
- remainTime: remainTime - 1,
- remainTimeStr: formatSeconds(remainTime),
- doTime: _this.data.doTime + 1
- });
- }
- }, 1000)
- _this.setData({
- timer: timer
- });
- },
- onUnload() {
- clearInterval(this.data.timer)
- },
- returnRecord() {
- this.setData({isFinish: true, modalShow:false})
- },
- timeOut() {
- clearInterval(this.data.timer)
- this.setData({
- timeOutShow: true
- });
- },
- radioChange( e ){
- let index = e.currentTarget.dataset.index;
- let list = this.data.list
- list[index].select = +e.detail.value
- console.log("select", index, list[index].select )
- this.setData( {list} );
- },
- checkboxChange( e ){
- let index = e.currentTarget.dataset.index;
- let list = this.data.list
- list[index].select = +e.detail.value.sort().join("")
- let result = ""+list[index].result
- if (list[index].select == result ){
- list[index]._select = true
- }
- for( let i in e.detail.value){
- if(result.indexOf( e.detail.value[i] )==-1 ){
- list[index]._select = true
- }
- }
- this.setData( {list} );
- },
- formSubmit: function(e) {
- let _this = this
- let force = this.data.remainTime < 3;
- let isFinish = true;
- wx.showLoading({
- title: '提交中',
- mask: true
- })
- let info = this.data.info;
- let param ={};
- param.groupId = info.groupId;
- param.paperId = info.paperId;
- param.answers = [];
- param.result = [];
- param.correct = 0;
- param.counter = this.data.list.length
- param.groupName = info.title;
- param.useTime = this.data.doTime
- param.duration = info.duration
- param.startTime = this.data.startTime;
- let errIds = [];
- for( let i=0; i< this.data.list.length; i++){
- let item = this.data.list[i];
- param.answers.push( item.answerId );
- param.result.push( item.select || 0);
- if( item.select == item.result){
- param.correct += (item.result>5?2:1);
- }else{
- if( item.select ) errIds.push( item.answerId)
- }
- if( !item.select ) isFinish = false
- }
- param.result = param.result.join(",")
- param.answers = param.answers.join(",")
- param.errors = errIds.join(",")
- param.isRedo = this.data.redo?1:0;
- app.formPost('Exam.ExamSubmit', param).then(res => {
- if (res.code === 200) {
- _this.setData({
- id: res.data.id,
- modalShow: true,
- result:param,
- });
- if (this.data.timer) {
- clearInterval(this.data.timer)
- }
- } else {
- app.message(res.msg, 'error')
- }
- wx.hideLoading()
- })
- }
- })
|