| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- const app = getApp()
- const util = require('../../utils/util.js')
- Page({
- data: {
- 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
- })
- })
- },
- onShow: function () {
- if (!this.data.hasUserInfo && app.globalData.hasUserInfo) {
- this.loadNotificationData(true)
- } else {
- this.setData({
- loading: false
- })
- }
- this.setData({
- hasUserInfo: app.globalData.hasUserInfo
- })
- },
- 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)
- }
- },
- })
|