|
|
|
@ -1,10 +1,18 @@
|
|
|
|
|
import {throttle} from "../../../js/utils";
|
|
|
|
|
|
|
|
|
|
const app = getApp();
|
|
|
|
|
Page({
|
|
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
exercise_questions: [],
|
|
|
|
|
loading: true,
|
|
|
|
|
exercise: {}
|
|
|
|
|
exercise: {},
|
|
|
|
|
count_down:'试卷不限时'
|
|
|
|
|
},
|
|
|
|
|
scrollToAnswerSheet(){
|
|
|
|
|
wx.pageScrollTo({
|
|
|
|
|
selector:".exercise-status"
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
scrollToQues(e){
|
|
|
|
|
let {target: {dataset:{ques_id}}} = e;
|
|
|
|
@ -19,6 +27,71 @@ Page({
|
|
|
|
|
let {detail:{q_position,answered}} = e;
|
|
|
|
|
let key = "question_status[" + (q_position - 1) +"].ques_status"
|
|
|
|
|
this.setData({[key]: answered});
|
|
|
|
|
this.refreshAnsweredCount();
|
|
|
|
|
},
|
|
|
|
|
startCountDown({left_time}){
|
|
|
|
|
var left = left_time;
|
|
|
|
|
var setCountDown = (time)=>{
|
|
|
|
|
let s = time%60;
|
|
|
|
|
let m = parseInt(time/60)%60;
|
|
|
|
|
let h = parseInt(time/3600);
|
|
|
|
|
if(s<10)
|
|
|
|
|
s = '0' +s;
|
|
|
|
|
if(m<10)
|
|
|
|
|
m = '0' + m;
|
|
|
|
|
if(h<10)
|
|
|
|
|
h = '0' + h;
|
|
|
|
|
let count_down = h + ":" + m + ":" + s;
|
|
|
|
|
this.setData({count_down});
|
|
|
|
|
}
|
|
|
|
|
setCountDown(--left);
|
|
|
|
|
var id = setInterval(()=>{
|
|
|
|
|
if(left<=1){
|
|
|
|
|
return this.stopCountDown(id);
|
|
|
|
|
}
|
|
|
|
|
setCountDown(--left);
|
|
|
|
|
},1000);
|
|
|
|
|
},
|
|
|
|
|
stopCountDown(id){
|
|
|
|
|
clearInterval(id);
|
|
|
|
|
var showToast = throttle(wx.showToast, 800, {});//延时Toast
|
|
|
|
|
showToast({
|
|
|
|
|
title: '时间已到,系统自动为你提交中',icon:"none"
|
|
|
|
|
})
|
|
|
|
|
app.api("exercises.commit_exercise")({exercise_id:this.exercise_id, commit_method:2})
|
|
|
|
|
.then(res=>{
|
|
|
|
|
showToast({
|
|
|
|
|
title: "试卷提交成功!"
|
|
|
|
|
});
|
|
|
|
|
//this.pull_questions();
|
|
|
|
|
}).catch(e=>{
|
|
|
|
|
//app.showError(e);
|
|
|
|
|
var title = '提交失败';
|
|
|
|
|
//if(e.code==-2)
|
|
|
|
|
// title = '您未作答任何题';
|
|
|
|
|
showToast({
|
|
|
|
|
title,
|
|
|
|
|
icon:"none"
|
|
|
|
|
});
|
|
|
|
|
let db = wx.cloud.database();
|
|
|
|
|
db.collection("data").add({
|
|
|
|
|
data: {
|
|
|
|
|
name: "exercises.commit_exercise",
|
|
|
|
|
e,
|
|
|
|
|
createdAt: db.serverDate()
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
this.setData({count_down: '考试时间已截止'});
|
|
|
|
|
},
|
|
|
|
|
refreshAnsweredCount(){
|
|
|
|
|
if(!this.data.question_status)
|
|
|
|
|
return;
|
|
|
|
|
let answered_count = 0;
|
|
|
|
|
this.data.question_status.map(i=>{
|
|
|
|
|
answered_count += i.ques_status;
|
|
|
|
|
});
|
|
|
|
|
this.setData({answered_count});
|
|
|
|
|
},
|
|
|
|
|
pull_questions: function(){
|
|
|
|
|
app.api("exercises.start_answer")({exercise_id: this.exercise_id})
|
|
|
|
@ -26,10 +99,14 @@ Page({
|
|
|
|
|
console.log("pull questions");
|
|
|
|
|
this.setData(res);
|
|
|
|
|
this.setData({loading: false});
|
|
|
|
|
}).catch(e => {
|
|
|
|
|
this.setData({status:e.code});
|
|
|
|
|
app.showError(e);
|
|
|
|
|
});
|
|
|
|
|
if(this.data.question_status)
|
|
|
|
|
this.refreshAnsweredCount();
|
|
|
|
|
if(res.exercise.left_time)
|
|
|
|
|
this.startCountDown({left_time: res.exercise.left_time});
|
|
|
|
|
}).catch(e => {
|
|
|
|
|
this.setData({status:e.code});
|
|
|
|
|
app.showError(e);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
save_exercise: function({show_loading=true}={}){
|
|
|
|
|
if(show_loading){
|
|
|
|
@ -51,44 +128,49 @@ Page({
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
commit_exercise: function(){
|
|
|
|
|
let { question_status} = this.data;
|
|
|
|
|
var answered = 1;
|
|
|
|
|
for(var ques of question_status){
|
|
|
|
|
if (!ques.ques_status){
|
|
|
|
|
answered = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var content = answered?'交卷后不能更改答案,确认交卷吗':'您还有题目未作答,交卷后无法更改,确认吗';
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title: '确认',
|
|
|
|
|
content,
|
|
|
|
|
success: res=>{
|
|
|
|
|
if(res.confirm){
|
|
|
|
|
app.api("exercises.begin_commit")({ exercise_id: this.exercise_id})
|
|
|
|
|
.then(
|
|
|
|
|
()=>{
|
|
|
|
|
//wx.showLoading({title: '检查作答情况中'});
|
|
|
|
|
app.api("exercises.begin_commit")({ exercise_id: this.exercise_id})
|
|
|
|
|
.then(resp=>{
|
|
|
|
|
let {question_undo, shixun_undo} = resp;
|
|
|
|
|
if(question_undo==0)
|
|
|
|
|
var content = "交卷后无法更改作答,是否确认?"
|
|
|
|
|
else {
|
|
|
|
|
var content = "您还有"+question_undo+"题未作答";
|
|
|
|
|
if(shixun_undo>0)
|
|
|
|
|
content += ",包含"+shixun_undo+"道实训题";
|
|
|
|
|
content +=",是否现在交卷呢?";
|
|
|
|
|
}
|
|
|
|
|
//wx.hideLoading();
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title:"提示",
|
|
|
|
|
content,
|
|
|
|
|
success:res=>{
|
|
|
|
|
if(res.confirm){
|
|
|
|
|
app.api("exercises.commit_exercise")({exercise_id: this.exercise_id})
|
|
|
|
|
.then(res=>{
|
|
|
|
|
console.log("交卷");
|
|
|
|
|
console.log(res);
|
|
|
|
|
app.showMsg(res);
|
|
|
|
|
setTimeout(()=>{
|
|
|
|
|
wx.navigateBack({
|
|
|
|
|
delta:1
|
|
|
|
|
})
|
|
|
|
|
}, 800);
|
|
|
|
|
}).catch(e=>{
|
|
|
|
|
app.showError(e);
|
|
|
|
|
console.error(e);
|
|
|
|
|
});
|
|
|
|
|
}).catch(e=>{
|
|
|
|
|
.then(res=>{
|
|
|
|
|
console.log("交卷");
|
|
|
|
|
console.log(res);
|
|
|
|
|
app.showMsg(res);
|
|
|
|
|
setTimeout(()=>{
|
|
|
|
|
wx.navigateBack({
|
|
|
|
|
delta:1
|
|
|
|
|
})
|
|
|
|
|
}, 800);
|
|
|
|
|
})
|
|
|
|
|
.catch(e=>{
|
|
|
|
|
app.showError(e);
|
|
|
|
|
console.error(e);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
.catch(e=>{
|
|
|
|
|
app.showError(e);
|
|
|
|
|
console.error(e);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
onLoad: function (options) {
|
|
|
|
|
this.exercise_id = options.exercise_id;
|
|
|
|
|