|
|
|
const app = getApp();
|
|
|
|
/*
|
|
|
|
statuses:[]
|
|
|
|
*/
|
|
|
|
|
|
|
|
const getDataForRender = class_ => ({
|
|
|
|
name: class_.get('name'),
|
|
|
|
objectId: class_.get('objectId')
|
|
|
|
});
|
|
|
|
const categories = [{ text: "我学习的", value: "study" }, { text: "我管理的", value: "manage" }];
|
|
|
|
Component({
|
|
|
|
data: {
|
|
|
|
imgDir: global.config.imgDir,
|
|
|
|
attachDir: global.config.attachDir,
|
|
|
|
categories,
|
|
|
|
statuses: [{ text: "正在进行", value: "processing" }, { text: "已结束", value: "end" }],
|
|
|
|
courses: [],
|
|
|
|
status: 0,
|
|
|
|
user: {},
|
|
|
|
loading: true,
|
|
|
|
current_cate: -1
|
|
|
|
},
|
|
|
|
attached() {
|
|
|
|
this.options = { page: 1, limit: 15 };
|
|
|
|
if (app.user().is_teacher)
|
|
|
|
var current_cate = 1;
|
|
|
|
else
|
|
|
|
var current_cate = 0;
|
|
|
|
this.setData({ current_cate });
|
|
|
|
},
|
|
|
|
pageLifetimes: {
|
|
|
|
show: function () {
|
|
|
|
if (this.data.current_cate >= 0) {
|
|
|
|
this.pullCourses({ refresh: 2 });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onCategoryChange: function ({ detail: { current, value } }) {
|
|
|
|
console.log("category change", current);
|
|
|
|
this.options["category"] = value.value;
|
|
|
|
this.pullCourses({ refresh: 1 });
|
|
|
|
this.setData({ category: value.value });
|
|
|
|
},
|
|
|
|
onStatusChange: function ({ detail: { value } }) {
|
|
|
|
this.options["status"] = value.value;
|
|
|
|
this.pullCourses({ refresh: 1 });
|
|
|
|
},
|
|
|
|
addCourse() {
|
|
|
|
return this.setData({ showModal: 1 });
|
|
|
|
/*
|
|
|
|
if (app.user().user_identity == "学生") {
|
|
|
|
this.setData({ showModal: 1 });
|
|
|
|
} else {
|
|
|
|
wx.showActionSheet({
|
|
|
|
itemList: ["加入课堂", '创建课堂'],
|
|
|
|
success: res => {
|
|
|
|
if (res.tapIndex == 0) {
|
|
|
|
this.setData({ showModal: 1 });
|
|
|
|
} else {
|
|
|
|
app.navigateTo({ url: "{course_setting}?intent=create" });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
},
|
|
|
|
enter_course: function (event) {
|
|
|
|
console.log(event);
|
|
|
|
let { id, course_name } = event.currentTarget.dataset;
|
|
|
|
wx.navigateTo({
|
|
|
|
url: "/course/pages/course/course?course_id=" + id + "&course_name=" + course_name,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
pullCourses: function ({ refresh = 0 } = {}) {
|
|
|
|
if (refresh) {
|
|
|
|
if (refresh == 1) {
|
|
|
|
this.options.page = 1;
|
|
|
|
var { options: data } = this;
|
|
|
|
} else if (refresh == 2) {
|
|
|
|
var { limit, page, status, category } = this.options;
|
|
|
|
var data = { limit: page * limit, page: 1, status, category };
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.options.page++;
|
|
|
|
var { options: data } = this;
|
|
|
|
}
|
|
|
|
return app.callApi({
|
|
|
|
name: "weapps.home", data
|
|
|
|
})
|
|
|
|
.then(res => {
|
|
|
|
let { courses } = res;
|
|
|
|
if (data.status)
|
|
|
|
courses = courses.filter(i => {
|
|
|
|
return i.is_end == (data.status == "end")
|
|
|
|
});
|
|
|
|
if (!refresh)
|
|
|
|
courses = this.data.courses.concat(courses);
|
|
|
|
this.setData({ courses, loading: false });
|
|
|
|
}).catch(e => {
|
|
|
|
this.setData({ courses: [], loading: false });
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onReachBottom() {
|
|
|
|
this.pullCourses();
|
|
|
|
},
|
|
|
|
onPullDownRefresh: function () {
|
|
|
|
//console.log("pulldownrefresh");
|
|
|
|
this.pullCourses({ refresh: 2 });
|
|
|
|
},
|
|
|
|
}
|
|
|
|
})
|