index.js 2.9 KB

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