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.

124 lines
2.6 KiB

// pages/exercise_setting/exercise_setting.js
import { getNowFormatDate, getNowFormatTime} from "../../utils/dateutils"
const app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
exercise_id: null,
exercise: {},
exercise_questions:[],
},
start_publish: function(){
if (!this.data.exercise_id) {
console.error("请先保存试卷");
return;
}
console.log({
course_id: this.course_id, exercise_ids: [this.data.exercise_id],
end_time: getNowFormatDate() + " " + getNowFormatTime()
});
let end_time = getNowFormatDate() + " " + getNowFormatTime();
end_time = end_time.replace("-11", "-12");
app.client.publish_exercise({
course_id: this.course_id, exercise_ids: [this.data.exercise_id],
end_time: end_time
}).then(res=>{
console.log(res);
wx.navigateBack({
delta: 1
})
}
)
},
create_question: function(){
if(!this.data.exercise_id){
console.error("请先保存试卷");
return;
}
wx.navigateTo({
url: `../question_setting/question_setting?exercise_id=${this.data.exercise_id}`,
})
},
create_exercise: function({detail:{value}}){
console.log(value);
app.client.create_exercise({...value, course_id: this.course_id})
.then(res=>{
console.log(res);
this.setData({ exercise_id: res.data.data.exercise_id});
})
.catch(error=>{
console.error(error);
});
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.course_id = options.course_id;
this.intent=options.intent;
if(options.exercise_id){
this.setData({exercise_id: options.exercise_id});
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
if(this.data.exercise_id){
app.client.get_exercise_edit({exercise_id: this.data.exercise_id})
.then(res=>{
console.log(res);
this.setData(
{
exercise_questions: res.data.exercise_questions,
exercise: res.data.exercise
})
})
}
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})