index.js 3.3 KB

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