123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- // pages/message/message.js
- const utils = require('../../utils/util.js')
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- isLogin: '', //是否登陆
- userInfo: '', //缓存用户信息
- list: [],
- pageNum: 1,
- pageSize: 10,
- pages: '',
- finish: false,
- listNotice: [],
- pageNumNotice: 1,
- pageSizeNotice: 10,
- pagesNotice: '',
- finishNotice: false,
- curIndex: 0
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData({
- userInfo: utils.getInfo()
- })
- if (this.data.userInfo.mobile) {
- this.getList()
- this.getNotice()
- } else {
- this.setData({
- isLogin: false
- })
- }
- },
- switchTab(e) {
- const curIndex = Number(e.currentTarget.dataset.index)
- this.setData({
- curIndex
- })
- },
- // 公告列表
- getNotice() {
- let params = {
- mobile: this.data.userInfo.mobile,
- pageNum: this.data.pageNumNotice,
- pageSize: this.data.pageSizeNotice
- }
- utils.axios({
- method: 'get',
- url: '/auth/user/msg/findGlobalNotice',
- data: params,
- noLogin: () => {},
- complete: () => {},
- success: res => {
- console.log(12);
- let result = res.data
- let listNotice = this.data.listNotice
- listNotice = listNotice.concat(result.records)
- this.setData({
- listNotice,
- pagesNotice: result.pages
- })
- if (result.total <= this.data.pageSizeNotice) {
- this.setData({
- finishNotice: true
- })
- }
- }
- })
- },
- //消息列表
- getList() {
- let params = {
- mobile: this.data.userInfo.mobile,
- pageNum: this.data.pageNum,
- pageSize: this.data.pageSize
- }
- utils.axios({
- method: 'get',
- url: '/auth/user/msg/findUserMsg',
- data: params,
- sendBefore() {
- wx.showLoading({
- title: '加载中...'
- })
- },
- complete() {
- wx.hideLoading()
- wx.stopPullDownRefresh()
- },
- noLogin: () => {
- this.setData({
- isLogin: false
- })
- },
- success: res => {
- this.setData({
- isLogin: true
- })
- let result = res.data
- let list = this.data.list
- list = list.concat(result.records)
- this.setData({
- list,
- pages: result.pages
- })
- if (result.total <= this.data.pageSize) {
- this.setData({
- finish: true
- })
- }
- }
- })
- },
- toFresh() {
- if (this.data.curIndex === 0) {
- this.setData({
- list: [],
- pageNum: 1,
- pages: '',
- finish: false
- })
- this.getList()
- } else {
- this.setData({
- listNotice: [],
- pageNumNotice: 1,
- pagesNotice: '',
- finishNotice: false
- })
- this.getNotice()
- }
- },
- //公告详情
- toDetail(e) {
- let msgId = e.currentTarget.dataset.id
- wx.navigateTo({
- url: '/pages/notice/noticeDetail?msgId=' + msgId
- })
- },
- //去登录
- toLogin() {
- utils.toLogin()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- if (typeof this.getTabBar === 'function' &&
- this.getTabBar()) {
- this.getTabBar().setData({
- selected: 1
- })
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- this.toFresh()
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- if (this.data.curIndex === 0) {
- let pageNum = this.data.pageNum
- let pages = this.data.pages
- pageNum++
- if (pageNum <= pages) {
- this.setData({
- pageNum
- })
- this.getList()
- } else {
- this.setData({
- finish: true
- })
- return
- }
- }else{
- let pageNumNotice = this.data.pageNumNotice
- let pagesNotice = this.data.pagesNotice
- pageNumNotice++
- if (pageNumNotice <= pagesNotice) {
- this.setData({
- pageNumNotice
- })
- this.getNotice()
- } else {
- this.setData({
- finishNotice: true
- })
- return
- }
- }
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- return {
- title: '诺信云',
- path: '/pages/index/index'
- }
- }
- })
|