|
@@ -1,171 +0,0 @@
|
|
|
-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.examStart';
|
|
|
- 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
|
|
|
- })
|
|
|
- // .sort( (i,j) =>{
|
|
|
- // return oindex.indexOf(i.type) > oindex.indexOf(j.type)?1:-1;
|
|
|
- // })
|
|
|
- console.log( list.map( item=>{ return item.type}) )
|
|
|
- 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() {
|
|
|
- // let id = this.data.id;
|
|
|
- this.setData({isFinish: true, modalShow:false})
|
|
|
- // wx.navigateTo({
|
|
|
- // url: `/pages/exam/read/index?id=${id}`
|
|
|
- // })
|
|
|
- },
|
|
|
- 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 += 1
|
|
|
- }else{
|
|
|
- if( item.select ) errIds.push( item.answerId)
|
|
|
- }
|
|
|
- if( !item.select ) isFinish = false
|
|
|
- }
|
|
|
- // if( !isFinish && !force){
|
|
|
- // app.message("还未完成", 'error')
|
|
|
- // wx.hideLoading()
|
|
|
- // return
|
|
|
- // }
|
|
|
- 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()
|
|
|
- })
|
|
|
- }
|
|
|
-})
|