|
|
|
import { getNowFormatDate } from "../../../js/utils";
|
|
|
|
|
|
|
|
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.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 } }) {
|
|
|
|
if (this.intent == "create") {
|
|
|
|
app.callApi({
|
|
|
|
name:"courses",
|
|
|
|
config:{method:"POST"},
|
|
|
|
data:value,
|
|
|
|
success: res => {
|
|
|
|
if(!res.course_id){
|
|
|
|
wx.showToast({
|
|
|
|
title: '创建失败,请先登录',
|
|
|
|
icon:"none"
|
|
|
|
})
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
app.redirectTo({
|
|
|
|
url:"{course}?course_id="+res.course_id
|
|
|
|
})
|
|
|
|
wx.showToast({
|
|
|
|
title: "创建成功",
|
|
|
|
duration: 5000
|
|
|
|
});
|
|
|
|
},
|
|
|
|
fail: app.showError
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
itemtap: function (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 => {
|
|
|
|
;
|
|
|
|
const schools = res.school_names;
|
|
|
|
this.setData({
|
|
|
|
bindSource: schools,
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
this.setData({hideScroll: false});
|
|
|
|
},
|
|
|
|
updateSchool: function({detail:{value}}){
|
|
|
|
;
|
|
|
|
if(!value){
|
|
|
|
this.setData({
|
|
|
|
hideScroll: true,
|
|
|
|
})
|
|
|
|
}else{
|
|
|
|
app.api("schools.school_list")({ search: value })
|
|
|
|
.then(res => {
|
|
|
|
;
|
|
|
|
const schools = res.school_names;
|
|
|
|
this.setData({
|
|
|
|
hideScroll: false,
|
|
|
|
bindSource: schools,
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
updateCourseListName({ detail: { value } }) {
|
|
|
|
this.setData({ "form_data.name": value });
|
|
|
|
},
|
|
|
|
updateEndDate({ detail: { value } }) {
|
|
|
|
;
|
|
|
|
this.setData({ "form_data.end_date": value });
|
|
|
|
},
|
|
|
|
|
|
|
|
onLoad: function (options) {
|
|
|
|
this.intent = options.intent;
|
|
|
|
if (this.intent == "create") this.reset();
|
|
|
|
;
|
|
|
|
;
|
|
|
|
},
|
|
|
|
|
|
|
|
onShow: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
})
|