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.

103 lines
2.7 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(e.code==401&&refresh)
this.setData({tidings:[]});
if(showError)
app.showError(e);
this.setData({loading:0});
return e;
})
},
onLoad: function () {
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 () {
let index = 2;
if(this.loaded)
this.refresh({refresh:2, showError:0})
wx.hideTabBarRedDot({index});
wx.removeTabBarBadge({index});
},
onPullDownRefresh: function () {
this.refresh({refresh:2});
},
onShareAppMessage: function () {
return app.shareApp({
imageUrl:global.config.attachDir + "944406"
});
}
})