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.

116 lines
2.7 KiB

const app = getApp();
let KEY = "no-nav-to-course-after-send";
Component({
properties: {
shixun_ids:Array,
subject_id:{
type:Number,
value:0
},
open_type:{
type:String,
value:"navigateTo"
},
show: {
type:Boolean,
value:false,
observer:function(v){
if(v){
if(this.data.status!=200||this.user_id!=app.user().user_id){
this.pullCourse({refresh:1});
this.user_id = app.user().user_id;
}
this.setData({auto_nav: !wx.getStorageSync(KEY)})
}
}
}
},
data: {
courses:[],
auto_nav: !wx.getStorageSync(KEY)
},
created(){
this.options = {page:1, limit:10};
},
methods: {
onClose(){
this.setData({checked: false});
this.setData({show:false});
this.course_id = null;
},
changeOption(e){
//console.log(e);
this.setData({auto_nav: !this.data.auto_nav});
wx.setStorageSync(KEY, !this.data.auto_nav);
},
send(){
let {course_id} = this;
let {shixun_ids, subject_id} = this.data;
if(shixun_ids.length==0){
return wx.showToast({
title: '请选择实训',
icon:"none"
})
}
if(!course_id){
return wx.showToast({
title: '请选择课堂',
icon:"none"
})
}
//console.log(shixun_ids, course_id);
if(subject_id>0){
var api_name = 'paths.send_to_course';
wx.showLoading({
title: '发送中',
})
}else{
var api_name = "shixuns.batch_send_to_course";
}
app.api(api_name)({subject_id, course_id, shixun_ids})
.then(res=>{
this.triggerEvent("success",{});
wx.hideLoading();
//console.log(res);
app.showMsg(res);
this.onClose();
if(this.data.auto_nav)
setTimeout(()=>{
app[this.data.open_type]({
url:`{course}?course_id=${course_id}&module_type=shixun_homework`
})
},420);
}).catch(e=>{
app.showError(e);
});
},
onChange(e){
let {detail:{value}} = e;
this.course_id = parseInt(value);
//console.log(e, value);
},
onReachBottom(){
this.pullCourse();
},
pullCourse({refresh=0}={}){
if(refresh){
this.options.page=1;
}else{
this.options.page++;
}
app.api("courses.search_slim")(this.options)
.then(res=>{
let {courses} = res;
if(!refresh)
courses = this.data.courses.concat(courses);
this.setData({courses, status:200});
}).catch(e=>{
global.realTimeLog.error(e, "courses.search_slim fail");
})
}
}
})