index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // pages/messageInfo/index.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. nvabarData: {
  9. showCapsule: 0, //是否显示左上角图标,消息中心 1表示显示 0表示不显示
  10. showBack: 1, //返回
  11. title: '消息中心', //导航栏 中间的标题
  12. // 此页面 页面内容距最顶部的距离
  13. height: app.globalData.height * 2 + 20,
  14. },
  15. messageList: [],
  16. skip: 1,
  17. limit: 10,
  18. total: 0,
  19. listshow: 1,
  20. // 是否到底
  21. hasMoreData: true
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function (options) {
  27. if (wx.getStorageSync('user')._id == ""){
  28. wx.redirectTo({
  29. url: '/pages/login/index'
  30. })
  31. }else{
  32. var that = this;
  33. that.searchInfo('正在加载数据...')
  34. }
  35. },
  36. // 列表查询
  37. searchInfo: function (message) {
  38. wx.showLoading({
  39. title: message,
  40. })
  41. var that = this;
  42. wx.request({
  43. url: 'http://124.235.209.122:88/api/financial/viewnews/select', //真是接口
  44. method: 'post',
  45. data: {
  46. qyid: '5e903455d72a944fd899c59c',//wx.getStorageSync('user')._id
  47. skip: that.data.skip,
  48. limit: that.data.limit
  49. },
  50. header: {
  51. 'content-type': 'application/json', // 默认值
  52. },
  53. success(res) {
  54. console.log(res)
  55. if (res.data.errcode == '0') {
  56. if (res.data.res.length !== 0) {
  57. if (that.data.messageList.isEmpty) {
  58. that.setData({ // 设置页面列表的内容
  59. messageList: res.data.res,
  60. })
  61. } else {
  62. that.setData({ // 设置页面列表的内容
  63. messageList: that.data.messageList.concat(res.data.res),
  64. total: res.data.total
  65. })
  66. }
  67. } else {
  68. wx.showToast({
  69. title: "没有更多数据了",
  70. duration: 1000,
  71. icon: 'none',
  72. mask: true
  73. })
  74. }
  75. }
  76. },
  77. complete: function () {
  78. wx.hideLoading();
  79. // complete
  80. wx.hideNavigationBarLoading() //完成停止加载
  81. wx.stopPullDownRefresh() //停止下拉刷新
  82. }
  83. })
  84. },
  85. /**
  86. * 页面相关事件处理函数--监听用户下拉动作
  87. */
  88. onPullDownRefresh: function () {
  89. wx.showNavigationBarLoading() //在标题栏中显示加载
  90. this.data.skip = 1
  91. this.data.messageList=[]
  92. this.searchInfo('正在刷新数据')
  93. },
  94. /**
  95. * 页面上拉触底事件的处理函数
  96. */
  97. onReachBottom: function () {
  98. const pageNum = this.data.skip;
  99. const _pagenum = Math.ceil(this.data.total / this.data.limit);
  100. if (pageNum < _pagenum) {
  101. this.setData({
  102. skip: pageNum + 1 //设置下一页
  103. })
  104. this.searchInfo('正在刷新数据'); //查询数据
  105. } else {
  106. wx.showToast({
  107. title: '没有更多数据',
  108. })
  109. }
  110. },
  111. })