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.

133 lines
2.9 KiB

const app = getApp()
Page({
allnavData: [
{
text: "全部",
exercise_status: "all",
course_identities: [2, 5, 6]
},
{
text: "未发布",
exercise_status: 1,
course_identities: [2]
},
{
text: '提交中',
exercise_status: 2,
course_identities: [2, 5, 6]
},
{
text: '已截止',
exercise_status: 3,
course_identities: [2, 5, 6]
},
],
data: {
loading: true,
exercises: [],
navData: [
{
text: "全部",
exercise_status: "all",
course_identities: [2, 5, 6]
},
{
text: '提交中',
exercise_status: 2,
course_identities: [2, 5, 6]
},
{
text: '已截止',
exercise_status: 3,
course_identities: [2, 5, 6]
},
],
currentTab: 0,
navScrollLeft: 0
},
pull_courses_info: function(){
app.client.get_user_info()
.then();
/**@todo */
},
pull_exercise: function(){
app.client.search_exercises({ course_id: this.course_id })
.then(res => {
console.log("pull_exercise");
console.log(res);
if(res.data.exercises){
this.setData({exercises: res.data.exercises, loading: false});
}else if(res.data.status==401){
wx.showToast({
title: '请登陆后重试',
icon: "none"
});
}
console.log(this.data)
})
.catch(error=>{
console.error(error);
wx.showToast({
title: error.toString(),
icon: "none",
duration: 5000
})
});
},
see_exercise: function ({ currentTarget: { dataset } }){
wx.navigateTo({
url: '../exercise/exercise?exercise_id=' + dataset.exercise_id,
});
},
enter_exercise: function({currentTarget:{dataset}}){
wx.showModal({
title: '确认',
content: '开始作答吗?',
success: res=>{
if(res.confirm){
wx.navigateTo({
url: '../exercise/exercise?exercise_id='+dataset.exercise_id,
});
}
}
});
},
//事件处理函数
onLoad: function (options) {
this.course_id = options.id;
},
onShow: function(){
this.pull_exercise();
},
switchNav(event) {
var cur = event.currentTarget.dataset.current;
//每个tab选项宽度占1/5
var singleNavWidth = this.data.windowWidth / 3;
//tab选项居中
this.setData({
navScrollLeft: (cur - 1) * singleNavWidth
})
if (this.data.currentTab == cur) {
return false;
} else {
this.setData({
currentTab: cur
})
}
},
switchTab(event) {
var cur = event.detail.current;
var singleNavWidth = this.data.windowWidth / 5;
this.setData({
currentTab: cur,
navScrollLeft: (cur - 1) * singleNavWidth
});
},
onPullDownRefresh: function(){
this.pull_exercise();
},
onShareAppMessage:function(){
}
})