|
|
@@ -1,20 +1,80 @@
|
|
|
-var newNews = require("../../data/newNewsData.js");
|
|
|
-Component({
|
|
|
+const app = getApp()
|
|
|
+const util = require('../../utils/util.js')
|
|
|
+
|
|
|
+Page({
|
|
|
data: {
|
|
|
- newNews:{
|
|
|
+ hasUserInfo: false,
|
|
|
+ pageToken: 0,
|
|
|
+ notificationDatas: [],
|
|
|
+ loading: true
|
|
|
+ },
|
|
|
|
|
|
- }
|
|
|
+ loadNotificationData: function (refresh) {
|
|
|
+ this.setData({
|
|
|
+ loading: true
|
|
|
+ })
|
|
|
+ wx.showNavigationBarLoading()
|
|
|
+ wx.cloud.callFunction({
|
|
|
+ name: 'listNotifications',
|
|
|
+ data: {
|
|
|
+ page_token: refresh ? 0 : this.data.pageToken,
|
|
|
+ page_size: 20
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ wx.hideNavigationBarLoading()
|
|
|
+ wx.stopPullDownRefresh()
|
|
|
+ if (res.result.status !== 'OK') {
|
|
|
+ wx.showToast({
|
|
|
+ title: res.result.errMsg,
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for (let i = 0; i < res.result.list.length; i++) {
|
|
|
+ res.result.list[i].message = util.dbToMsg(res.result.list[i].message)
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ notificationDatas: refresh ? res.result.list : this.data.notificationDatas.concat(res.result.list),
|
|
|
+ pageToken: res.result.next_page_token,
|
|
|
+ loading: false
|
|
|
+ })
|
|
|
+ })
|
|
|
},
|
|
|
|
|
|
- lifetimes: {
|
|
|
- ready: function() {
|
|
|
+ onShow: function () {
|
|
|
+ if (!this.data.hasUserInfo && app.globalData.hasUserInfo) {
|
|
|
+ this.loadNotificationData(true)
|
|
|
+ } else {
|
|
|
this.setData({
|
|
|
- newNews:newNews.newNews
|
|
|
+ loading: false
|
|
|
})
|
|
|
}
|
|
|
+ this.setData({
|
|
|
+ hasUserInfo: app.globalData.hasUserInfo
|
|
|
+ })
|
|
|
},
|
|
|
|
|
|
- methods: {
|
|
|
+ onPullDownRefresh: function () {
|
|
|
+ if (this.data.loading) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ hasUserInfo: app.globalData.hasUserInfo
|
|
|
+ })
|
|
|
+ if (this.data.hasUserInfo) {
|
|
|
+ this.loadNotificationData(true)
|
|
|
+ }
|
|
|
+ },
|
|
|
|
|
|
- }
|
|
|
+ onReachBottom: function () {
|
|
|
+ if (this.data.loading) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ hasUserInfo: app.globalData.hasUserInfo
|
|
|
+ })
|
|
|
+ if (this.data.hasUserInfo) {
|
|
|
+ this.loadNotificationData(false)
|
|
|
+ }
|
|
|
+ },
|
|
|
})
|