|
|
|
// pages/exercise_setting/exercise_setting.js
|
|
|
|
import { getNowFormatDate, getNowFormatTime, getNextWeekFormatDate} from "../../../js/utils"
|
|
|
|
const app = getApp();
|
|
|
|
Page({
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面的初始数据
|
|
|
|
*/
|
|
|
|
data: {
|
|
|
|
exercise: {},
|
|
|
|
exercise_questions:[],
|
|
|
|
},
|
|
|
|
start_publish: function(){
|
|
|
|
if (!this.exercise_id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let end_time = getNextWeekFormatDate() + " " + getNowFormatTime();
|
|
|
|
//end_time = end_time.replace("-11", "-12");
|
|
|
|
app.api("courses.exercises.publish")({
|
|
|
|
course_id: this.course_id, check_ids: [this.exercise_id],
|
|
|
|
end_time: end_time
|
|
|
|
}).then(res=>{
|
|
|
|
;
|
|
|
|
app.showMsg(res);
|
|
|
|
wx.navigateBack({
|
|
|
|
delta: 1
|
|
|
|
});
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
create_question: function(){
|
|
|
|
if(!this.exercise_id){
|
|
|
|
wx.showToast({
|
|
|
|
title: '请先保存试卷',
|
|
|
|
icon:"none"
|
|
|
|
})
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
app.navigateTo({
|
|
|
|
url: `{question_setting}?exercise_id=${this.exercise_id}`,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
create_exercise: function({detail:{value}}){
|
|
|
|
;
|
|
|
|
if(this.exercise_id){
|
|
|
|
app.api("exercises")({...value, exercise_id: this.exercise_id})
|
|
|
|
.then(res => {
|
|
|
|
;
|
|
|
|
wx.showToast({
|
|
|
|
title: res.message,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
app.showError(e)
|
|
|
|
});
|
|
|
|
}else{
|
|
|
|
app.api("courses.exercises",{method:"POST"})({ ...value, course_id: this.course_id })
|
|
|
|
.then(res => {
|
|
|
|
;
|
|
|
|
this.exercise_id = res.exercise_id
|
|
|
|
wx.showToast({
|
|
|
|
title: '创建成功',
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
app.showError(e);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
onLoad: function (options) {
|
|
|
|
this.intent = options.intent;
|
|
|
|
this.course_id = options.course_id;
|
|
|
|
this.exercise_id = options.exercise_id;
|
|
|
|
},
|
|
|
|
|
|
|
|
onShow: function () {
|
|
|
|
if (this.exercise_id) {
|
|
|
|
app.api("exercises.edit")({ exercise_id: this.exercise_id })
|
|
|
|
.then(res => {
|
|
|
|
;
|
|
|
|
this.setData(
|
|
|
|
{
|
|
|
|
exercise_questions: res.exercise_questions,
|
|
|
|
exercise: res.exercise
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onReachBottom: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
onShareAppMessage(){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|