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.

163 lines
3.4 KiB

// pages/course_setting/course_setting.js
import { getNowFormatDate } from "../../utils/dateutils";
const app = getApp();
Page({
/**
* 页面的初始数据
*/
initial_form_data: {
//course_module_types
shixun_homework: true,
common_homework: true,
group_homework: true,
exercise: true,
attachment: true,
course_group: true,
//course_module_types
end_date: "",
school: app.client.current_user.school
},
data: {
current_date: getNowFormatDate(),
form_data: {},
bindSource: [], //绑定到页面的数据,根据用户输入动态变化
hideScroll: true,
},
reset: function () {
this.setData({ form_data: this.initial_form_data });
},
create_course: function ({ detail: { value } }) {
console.info(value);
if (this.intent == "create") {
app.client.create_course({
data: value,
success: res => {
console.info("create course")
console.info(res);
wx.navigateTo({
url:"/pages/course/course?course_id="+res.data.course_id
})
wx.showToast({
title: "创建成功",
duration: 5000
});
},
fail: error => {
wx.showToast({
title: error.toString(),
icon: "none"
})
}
})
}
},
itemtap: function (e) {
console.log(e);
this.setData({
"form_data.school": e.currentTarget.id,
hideScroll: true
})
},
leaveSchool: function(){
},
focusSchool: function({detail:{value}}){
if(this.data.bindSource.length==0){
app.client.search_schools({ search: value })
.then(res => {
console.log(res);
const schools = res.data.school_names;
this.setData({
bindSource: schools,
});
})
}
this.setData({hideScroll: false});
},
updateSchool: function({detail:{value}}){
console.log("updateSchool");
if(!value){
this.setData({
hideScroll: true,
})
}else{
app.client.search_schools({ search: value })
.then(res => {
console.log(res);
const schools = res.data.school_names;
this.setData({
hideScroll: false,
bindSource: schools,
});
})
}
},
updateCourseListName({ detail: { value } }) {
this.setData({ "form_data.name": value });
},
updateEndDate({ detail: { value } }) {
console.log(value);
this.setData({ "form_data.end_date": value });
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.intent = options.intent;
if (this.intent == "create") this.reset();
console.log(options);
console.log(this.intent);
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})