|
|
|
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,
|
|
|
|
require_login: false,
|
|
|
|
page_status: 0, // 0=>loading 1=>success 2=>fail
|
|
|
|
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]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: "未发布",
|
|
|
|
exercise_status: 1,
|
|
|
|
course_identities: [2]
|
|
|
|
},
|
|
|
|
],
|
|
|
|
currentTab: 0,
|
|
|
|
navScrollLeft: 0
|
|
|
|
},
|
|
|
|
exercise_result: function ({ currentTarget: { dataset } }){
|
|
|
|
wx.navigateTo({
|
|
|
|
url: `../exercise_result/exercise_result?exercise_id=${dataset.exercise_id}`,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
see_grade: function({currentTarget:{dataset}}){
|
|
|
|
wx.navigateTo({
|
|
|
|
url: `../exercise_grade/exercise_grade?exercise_id=${dataset.exercise_id}`,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
edit_exercise: function({currentTarget:{dataset}}){
|
|
|
|
wx.navigateTo({
|
|
|
|
url: `../exercise_setting/exercise_setting?course_id=${this.course_id}&exercise_id=${dataset.exercise_id}`,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
create_exercise: function(){
|
|
|
|
wx.navigateTo({
|
|
|
|
url: `../exercise_setting/exercise_setting?course_id=${this.course_id}`,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
pull_exercise: function(){
|
|
|
|
app.api("courses.exercises")({ course_id: this.course_id })
|
|
|
|
.then(res => {
|
|
|
|
console.log("pull_exercise");
|
|
|
|
console.log(res);
|
|
|
|
if(res.exercises){
|
|
|
|
this.setData({exercises: res.exercises, loading: false});
|
|
|
|
}else if(res.status==401){
|
|
|
|
this.setData({require_login: true});
|
|
|
|
wx.showToast({
|
|
|
|
title: '请登陆后重试',
|
|
|
|
icon: "none"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
console.log(this.data)
|
|
|
|
})
|
|
|
|
.catch(e=>{
|
|
|
|
console.error(e);
|
|
|
|
app.showError(e)
|
|
|
|
});
|
|
|
|
},
|
|
|
|
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;
|
|
|
|
app.api("courses.top_banner")({course_id: this.course_id})
|
|
|
|
.then(res=>{
|
|
|
|
this.setData({course:res})
|
|
|
|
console.log(res)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
onShow: function(){
|
|
|
|
this.setData({require_login: false});
|
|
|
|
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(){
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|