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.

167 lines
3.4 KiB

5 years ago
// pages/course_setting/course_setting.js
import { getNowFormatDate } from "../../js/utils";
const app = getApp();
5 years ago
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.user().school
},
5 years ago
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.callApi({
name:"courses",
config:{method:"POST"},
data:value,
success: res => {
console.info("create course")
console.info(res);
if(!res.course_id){
wx.showToast({
title: '创建失败,请先登陆',
icon:"none"
})
return;
}
wx.redirectTo({
url:"/pages/course/course?course_id="+res.course_id
})
wx.showToast({
title: "创建成功",
duration: 5000
});
},
fail: app.showError
})
}
},
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.api("schools.school_list")({ search: value })
.then(res => {
console.log(res);
const schools = res.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.api("schools.school_list")({ search: value })
.then(res => {
console.log(res);
const schools = res.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 });
5 years ago
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.intent = options.intent;
if (this.intent == "create") this.reset();
5 years ago
console.log(options);
console.log(this.intent);
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})