|
|
|
// 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) {
|
|
|
|
console.error("请先保存试卷");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
console.log({
|
|
|
|
course_id: this.course_id, exercise_ids: [this.exercise_id],
|
|
|
|
end_time: getNextWeekFormatDate() + " " + getNowFormatTime()
|
|
|
|
});
|
|
|
|
let end_time = getNextWeekFormatDate() + " " + getNowFormatTime();
|
|
|
|
//end_time = end_time.replace("-11", "-12");
|
|
|
|
app.api("courses.exercises.publish")({
|
|
|
|
course_id: this.course_id, exercise_ids: [this.exercise_id],
|
|
|
|
end_time: end_time
|
|
|
|
}).then(res=>{
|
|
|
|
console.log(res);
|
|
|
|
wx.navigateBack({
|
|
|
|
delta: 1
|
|
|
|
})
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
create_question: function(){
|
|
|
|
if(!this.exercise_id){
|
|
|
|
console.error("请先保存试卷");
|
|
|
|
wx.showToast({
|
|
|
|
title: '请先保存试卷',
|
|
|
|
icon:"none"
|
|
|
|
})
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wx.navigateTo({
|
|
|
|
url: `../question_setting/question_setting?exercise_id=${this.exercise_id}`,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
create_exercise: function({detail:{value}}){
|
|
|
|
console.log(value);
|
|
|
|
if(this.exercise_id){
|
|
|
|
app.api("exercises")({...value, exercise_id: this.exercise_id})
|
|
|
|
.then(res => {
|
|
|
|
console.log(res);
|
|
|
|
wx.showToast({
|
|
|
|
title: res.message,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.error(error);
|
|
|
|
wx.showToast({
|
|
|
|
title: error.message,
|
|
|
|
icon: "none"
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}else{
|
|
|
|
app.api("courses.exercises")({ ...value, course_id: this.course_id })
|
|
|
|
.then(res => {
|
|
|
|
console.log(res);
|
|
|
|
this.exercise_id = res.data.exercise_id
|
|
|
|
wx.showToast({
|
|
|
|
title: '创建成功',
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
console.error(e);
|
|
|
|
app.showError(e);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
onLoad: function (options) {
|
|
|
|
this.intent = options.intent;
|
|
|
|
this.course_id = options.course_id;
|
|
|
|
this.exercise_id = options.exercise_id;
|
|
|
|
if (this.exercise_id) {
|
|
|
|
app.api("exercises.edit")({ exercise_id: this.exercise_id })
|
|
|
|
.then(res => {
|
|
|
|
console.log(res);
|
|
|
|
this.setData(
|
|
|
|
{
|
|
|
|
exercise_questions: res.data.exercise_questions,
|
|
|
|
exercise: res.data.exercise
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
onShow: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
|
*/
|
|
|
|
onHide: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
|
*/
|
|
|
|
onUnload: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
*/
|
|
|
|
onPullDownRefresh: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
*/
|
|
|
|
onReachBottom: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
})
|