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.

99 lines
2.5 KiB

const app = getApp();
Page({
data: {
tidings:[],
current: 0,
list:[
{text:"全部", type:""},
{text:"课堂提醒",type:"course"},
{text:"审核",type:"apply"},
{text:"通知", type:"notice"},
{text:"互动提醒", type:"interaction"},
]
},
onTapMessage(){
let tidings = this.data.tidings.filter(i=>{
return i.tiding_type =='Apply'&&i.status==0
});
if(this.data.course_apply_count==tidings.length){
var flag = true;
var course_id = tidings[0].belong_container_id;
for(var k=1;k<tidings.length;k++){
flag = flag&&(course_id == tidings[k].belong_container_id);
}
if(flag){
app.navigateTo({
url:`{teacher_apply}?course_id=${course_id}`
})
}
else
this.setData({current:2});
}else
this.setData({current: 2});
},
changeType({detail:{current, value}}){
this.options.type=value.type;
this.refresh({refresh:1})
.then(res=>{
this.setData({scrollTop:0});
});
},
refresh({refresh=0, showError=1}={}){
if(refresh){
this.setData({ loading: 1 });
if(refresh==1){
this.options.page=1;
var { options } = this;
}else if(refresh==2){
var { per_page, page, type} = this.options;
var options = {per_page:per_page*page, page:1, type};
}
}else{
this.options.page++;
var {options} = this;
}
return app.api("users.tidings")(options).then(res => {
let {tidings, course_apply_count} = res;
if(!refresh)
tidings = this.data.tidings.concat(tidings);
this.setData({ tidings,course_apply_count ,loading:0});
return res;
}).catch(e=>{
if(showError)
app.showError(e);
this.setData({loading:0});
return e;
})
},
onLoad: function (options) {
let key = `cache-users.tidings-${app.user().user_id}`;
let cache_tidings = wx.getStorageSync(key);
if(cache_tidings)
this.setData({tidings: cache_tidings});
this.options = { page: 1, per_page: 10 };
this.refresh({refresh:1}).then(res=>{
console.log("pull", res);
this.loaded = 1;
if(res.tidings)
wx.setStorageSync(key, res.tidings);
})
},
_onReachBottom(){
this.refresh();
},
onShow: function () {
5 years ago
let index = 2;
if(this.loaded)
this.refresh({refresh:2, showError:0})
5 years ago
wx.hideTabBarRedDot({index});
wx.removeTabBarBadge({index});
},
onPullDownRefresh: function () {
this.refresh({refresh:2});
},
onShareAppMessage: function () {
}
})