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.
162 lines
3.4 KiB
162 lines
3.4 KiB
5 years ago
|
import { getNowFormatDate } from "../../../js/utils";
|
||
5 years ago
|
|
||
|
const app = getApp();
|
||
|
|
||
5 years ago
|
Page({
|
||
5 years ago
|
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: "",
|
||
5 years ago
|
school: app.user().school
|
||
5 years ago
|
},
|
||
5 years ago
|
data: {
|
||
5 years ago
|
current_date: getNowFormatDate(),
|
||
5 years ago
|
form_data: {},
|
||
|
bindSource: [], //绑定到页面的数据,根据用户输入动态变化
|
||
|
hideScroll: true,
|
||
5 years ago
|
},
|
||
|
reset: function () {
|
||
|
this.setData({ form_data: this.initial_form_data });
|
||
|
},
|
||
|
create_course: function ({ detail: { value } }) {
|
||
|
console.info(value);
|
||
|
if (this.intent == "create") {
|
||
5 years ago
|
app.callApi({
|
||
|
name:"courses",
|
||
|
config:{method:"POST"},
|
||
|
data:value,
|
||
5 years ago
|
success: res => {
|
||
|
console.info("create course")
|
||
|
console.info(res);
|
||
5 years ago
|
if(!res.course_id){
|
||
5 years ago
|
wx.showToast({
|
||
|
title: '创建失败,请先登陆',
|
||
|
icon:"none"
|
||
|
})
|
||
|
return;
|
||
|
}
|
||
5 years ago
|
wx.redirectTo({
|
||
|
url:"/pages/course/course?course_id="+res.course_id
|
||
5 years ago
|
})
|
||
|
wx.showToast({
|
||
|
title: "创建成功",
|
||
|
duration: 5000
|
||
|
});
|
||
|
},
|
||
5 years ago
|
fail: app.showError
|
||
5 years ago
|
})
|
||
|
}
|
||
|
},
|
||
5 years ago
|
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){
|
||
5 years ago
|
app.api("schools.school_list")({ search: value })
|
||
5 years ago
|
.then(res => {
|
||
|
console.log(res);
|
||
5 years ago
|
const schools = res.school_names;
|
||
5 years ago
|
this.setData({
|
||
|
bindSource: schools,
|
||
|
});
|
||
|
})
|
||
|
}
|
||
|
this.setData({hideScroll: false});
|
||
|
},
|
||
|
updateSchool: function({detail:{value}}){
|
||
|
console.log("updateSchool");
|
||
|
if(!value){
|
||
|
this.setData({
|
||
|
hideScroll: true,
|
||
|
})
|
||
|
}else{
|
||
5 years ago
|
app.api("schools.school_list")({ search: value })
|
||
5 years ago
|
.then(res => {
|
||
|
console.log(res);
|
||
5 years ago
|
const schools = res.school_names;
|
||
5 years ago
|
this.setData({
|
||
|
hideScroll: false,
|
||
|
bindSource: schools,
|
||
|
});
|
||
|
})
|
||
|
}
|
||
|
},
|
||
5 years ago
|
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;
|
||
5 years ago
|
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 () {
|
||
|
|
||
|
}
|
||
|
})
|