You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
133 lines
2.9 KiB
133 lines
2.9 KiB
5 years ago
|
// pages/exercise_setting/exercise_setting.js
|
||
5 years ago
|
import { getNowFormatDate, getNowFormatTime, getNextWeekFormatDate} from "../../../js/utils"
|
||
5 years ago
|
const app = getApp();
|
||
|
Page({
|
||
|
|
||
|
/**
|
||
|
* 页面的初始数据
|
||
|
*/
|
||
|
data: {
|
||
|
exercise: {},
|
||
|
exercise_questions:[],
|
||
|
},
|
||
|
start_publish: function(){
|
||
5 years ago
|
if (!this.exercise_id) {
|
||
5 years ago
|
console.error("请先保存试卷");
|
||
|
return;
|
||
|
}
|
||
|
console.log({
|
||
5 years ago
|
course_id: this.course_id, exercise_ids: [this.exercise_id],
|
||
|
end_time: getNextWeekFormatDate() + " " + getNowFormatTime()
|
||
5 years ago
|
});
|
||
5 years ago
|
let end_time = getNextWeekFormatDate() + " " + getNowFormatTime();
|
||
|
//end_time = end_time.replace("-11", "-12");
|
||
5 years ago
|
app.api("courses.exercises.publish")({
|
||
5 years ago
|
course_id: this.course_id, exercise_ids: [this.exercise_id],
|
||
5 years ago
|
end_time: end_time
|
||
|
}).then(res=>{
|
||
|
console.log(res);
|
||
|
wx.navigateBack({
|
||
|
delta: 1
|
||
|
})
|
||
|
}
|
||
|
)
|
||
|
},
|
||
|
create_question: function(){
|
||
5 years ago
|
if(!this.exercise_id){
|
||
5 years ago
|
console.error("请先保存试卷");
|
||
5 years ago
|
wx.showToast({
|
||
|
title: '请先保存试卷',
|
||
|
icon:"none"
|
||
|
})
|
||
5 years ago
|
return;
|
||
|
}
|
||
|
wx.navigateTo({
|
||
5 years ago
|
url: `../question_setting/question_setting?exercise_id=${this.exercise_id}`,
|
||
5 years ago
|
})
|
||
|
},
|
||
|
create_exercise: function({detail:{value}}){
|
||
|
console.log(value);
|
||
5 years ago
|
if(this.exercise_id){
|
||
5 years ago
|
app.api("exercises")({...value, exercise_id: this.exercise_id})
|
||
5 years ago
|
.then(res => {
|
||
|
console.log(res);
|
||
|
wx.showToast({
|
||
5 years ago
|
title: res.message,
|
||
5 years ago
|
})
|
||
|
})
|
||
|
.catch(error => {
|
||
|
console.error(error);
|
||
|
wx.showToast({
|
||
5 years ago
|
title: error.message,
|
||
5 years ago
|
icon: "none"
|
||
|
})
|
||
|
});
|
||
|
}else{
|
||
5 years ago
|
app.api("courses.exercises",{method:"POST"})({ ...value, course_id: this.course_id })
|
||
5 years ago
|
.then(res => {
|
||
|
console.log(res);
|
||
5 years ago
|
this.exercise_id = res.exercise_id
|
||
5 years ago
|
wx.showToast({
|
||
|
title: '创建成功',
|
||
|
})
|
||
|
})
|
||
5 years ago
|
.catch(e => {
|
||
|
console.error(e);
|
||
|
app.showError(e);
|
||
5 years ago
|
});
|
||
|
}
|
||
|
|
||
5 years ago
|
},
|
||
5 years ago
|
|
||
5 years ago
|
onLoad: function (options) {
|
||
5 years ago
|
this.intent = options.intent;
|
||
5 years ago
|
this.course_id = options.course_id;
|
||
5 years ago
|
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(
|
||
|
{
|
||
5 years ago
|
exercise_questions: res.exercise_questions,
|
||
|
exercise: res.exercise
|
||
5 years ago
|
})
|
||
|
})
|
||
5 years ago
|
}
|
||
5 years ago
|
|
||
5 years ago
|
},
|
||
|
|
||
|
onShow: function () {
|
||
5 years ago
|
|
||
5 years ago
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面隐藏
|
||
|
*/
|
||
|
onHide: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面卸载
|
||
|
*/
|
||
|
onUnload: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 页面相关事件处理函数--监听用户下拉动作
|
||
|
*/
|
||
|
onPullDownRefresh: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 页面上拉触底事件的处理函数
|
||
|
*/
|
||
|
onReachBottom: function () {
|
||
|
|
||
|
},
|
||
|
|
||
5 years ago
|
|
||
5 years ago
|
})
|