index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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('uid') == ""){
  28. wx.redirectTo({
  29. url: '/pages/login/index'
  30. })
  31. }else{
  32. var that = this;
  33. that.searchInfo('正在加载数据...')
  34. }
  35. },
  36. /**
  37. * 生命周期函数--监听页面初次渲染完成
  38. */
  39. onReady: function () {
  40. },
  41. /**
  42. * 生命周期函数--监听页面显示
  43. */
  44. onShow: function () {
  45. },
  46. /**
  47. * 生命周期函数--监听页面隐藏
  48. */
  49. onHide: function () {
  50. },
  51. /**
  52. * 生命周期函数--监听页面卸载
  53. */
  54. onUnload: function () {
  55. },
  56. /**
  57. * 用户点击右上角分享
  58. */
  59. onShareAppMessage: function () {
  60. },
  61. // 列表查询
  62. searchInfo: function (message) {
  63. wx.showLoading({
  64. title: message,
  65. })
  66. var that = this;
  67. wx.request({
  68. url: 'http://124.235.209.122:88/api/financial/viewnews/select', //真是接口
  69. method: 'post',
  70. data: {
  71. qyid: '5e903455d72a944fd899c59c',//wx.getStorageSync('uid')
  72. skip: that.data.skip,
  73. limit: that.data.limit
  74. },
  75. header: {
  76. 'content-type': 'application/json', // 默认值
  77. },
  78. success(res) {
  79. console.log(res)
  80. if (res.data.errcode == '0') {
  81. if (res.data.res.length !== 0) {
  82. if (that.data.messageList.isEmpty) {
  83. that.setData({ // 设置页面列表的内容
  84. messageList: res.data.res,
  85. })
  86. } else {
  87. that.setData({ // 设置页面列表的内容
  88. messageList: that.data.messageList.concat(res.data.res),
  89. total: res.data.total
  90. })
  91. }
  92. } else {
  93. wx.showToast({
  94. title: "没有更多数据了",
  95. duration: 1000,
  96. icon: 'none',
  97. mask: true
  98. })
  99. }
  100. }
  101. },
  102. complete: function () {
  103. wx.hideLoading();
  104. // complete
  105. wx.hideNavigationBarLoading() //完成停止加载
  106. wx.stopPullDownRefresh() //停止下拉刷新
  107. }
  108. })
  109. },
  110. /**
  111. * 页面相关事件处理函数--监听用户下拉动作
  112. */
  113. onPullDownRefresh: function () {
  114. wx.showNavigationBarLoading() //在标题栏中显示加载
  115. this.data.skip = 1
  116. this.data.messageList=[]
  117. this.searchInfo('正在刷新数据')
  118. },
  119. /**
  120. * 页面上拉触底事件的处理函数
  121. */
  122. onReachBottom: function () {
  123. const pageNum = this.data.skip;
  124. const _pagenum = Math.ceil(this.data.total / this.data.limit);
  125. console.log(pageNum + "哈哈哈哈" + _pagenum)
  126. if (pageNum < _pagenum) {
  127. this.setData({
  128. skip: pageNum + 1 //设置下一页
  129. })
  130. this.searchInfo('正在刷新数据'); //查询数据
  131. } else {
  132. wx.showToast({
  133. title: '没有更多数据',
  134. })
  135. }
  136. },
  137. })