// pages/lianxi/main.js const api = require("../../utils/request.js"); var util = require('../../utils/util.js') Page({ /** * 页面的初始数据 */ data: { tms:[], tm_index: 0, ctms:[], domain:getApp().globalData.mediahost, }, radioChange: function (e) { var that = this that.data.tm_current['user_answer'] = e.detail.value that.data.tms[that.data.tm_index] = that.data.tm_current }, checkboxChange: function (e) { var that = this that.data.tm_current['user_answer'] = e.detail.value that.data.tms[that.data.tm_index] = that.data.tm_current }, /** * 生命周期函数--监听页面加载 */ onLoad: function () { var that = this try { var value = wx.getStorageSync('examtest') console.log(value) if (value) { for(var i=0;i' if (tm_current.user_answer) { if (key == tm_current.user_answer || tm_current.user_answer.indexOf(key) != -1) { option.checked = true } } else { option.checked = false } options.push(option) } this.setData({ options: options }) }, sheet: function () { wx.navigateTo({ url: 'sheet', }) }, hand: function () { var that = this for (var i = 0, len = that.data.tms.length; i < len; i++) { let tm = that.data.tms[i] if (tm.user_answer == undefined || tm.length == 0){ wx.showModal({ title: '警告', content: '答卷未完成,可点击答题卡复查!', confirmText: "仍旧提交", cancelText: "取消", success: function (res) { if (res.confirm) { that.handTest() } } }) return } } wx.showModal({ content: '确定提交?', confirmText: "确定", cancelText: "取消", success: function (res) { if (res.confirm) { that.handTest() } } }) }, handTest: function (){ var that = this clearInterval(getApp().globalData.timer) wx.showLoading({ title: '正在判卷中...', mask:true }) let score = 0; for (var i = 0, len = that.data.tms.length; i < len; i++) { let tm_result = that.panTi(that.data.tms[i]) that.data.tms[i].is_right = tm_result.is_right if (tm_result.is_right == false && that.data.tms[i].user_answer){ that.data.ctms.unshift(that.data.tms[i]) if (that.data.ctms.length > 40) { that.data.ctms.length = 40 } } that.data.tms[i].score = tm_result.score score = score + tm_result.score } that.data.examtest.score = score if (score >= that.data.examtest.pass_score){ that.data.examtest.is_pass = true }else{ that.data.examtest.is_pass = false } that.data.examtest.questions = that.data.tms that.data.examtest.start_time = util.formatTime(new Date(that.data.starttimes)) that.data.examtest.end_time = util.formatTime(new Date()) that.data.examtest.took = Math.floor(((new Date()).getTime() - this.data.starttimes) / 1000) api.request('/examtest/examtest/', 'POST', that.data.examtest).then(res => { wx.hideLoading() getApp().globalData.testData = res.data try { wx.removeStorageSync('examtest') } catch (e) { } wx.redirectTo({ url: 'result', }) }) } })