index.js 3.0 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. console.log(wx.getStorageSync('user')+"是建档立卡绝对是卢卡斯")
  28. if (wx.getStorageSync('user') == ""){
  29. wx.redirectTo({
  30. url: '/pages/login/index'
  31. })
  32. }else{
  33. var that = this;
  34. that.searchInfo('正在加载数据...')
  35. }
  36. },
  37. // 列表查询
  38. searchInfo: function (message) {
  39. wx.showLoading({
  40. title: message,
  41. })
  42. var that = this;
  43. wx.request({
  44. url: 'http://124.235.209.122:88/api/financial/viewnews/select', //真是接口
  45. method: 'post',
  46. data: {
  47. qyid: wx.getStorageSync('user')._id,//wx.getStorageSync('user')._id '5e903455d72a944fd899c59c'
  48. skip: that.data.skip,
  49. limit: that.data.limit
  50. },
  51. header: {
  52. 'content-type': 'application/json', // 默认值
  53. },
  54. success(res) {
  55. console.log(res)
  56. if (res.data.errcode == '0') {
  57. if (res.data.res.length !== 0) {
  58. if (that.data.messageList.isEmpty) {
  59. that.setData({ // 设置页面列表的内容
  60. messageList: res.data.res,
  61. })
  62. } else {
  63. that.setData({ // 设置页面列表的内容
  64. messageList: that.data.messageList.concat(res.data.res),
  65. total: res.data.total
  66. })
  67. }
  68. } else {
  69. wx.showToast({
  70. title: "没有更多数据了",
  71. duration: 1000,
  72. icon: 'none',
  73. mask: true
  74. })
  75. }
  76. }
  77. },
  78. complete: function () {
  79. wx.hideLoading();
  80. // complete
  81. wx.hideNavigationBarLoading() //完成停止加载
  82. wx.stopPullDownRefresh() //停止下拉刷新
  83. }
  84. })
  85. },
  86. /**
  87. * 页面相关事件处理函数--监听用户下拉动作
  88. */
  89. onPullDownRefresh: function () {
  90. wx.showNavigationBarLoading() //在标题栏中显示加载
  91. this.data.skip = 1
  92. this.data.messageList=[]
  93. this.searchInfo('正在刷新数据')
  94. },
  95. /**
  96. * 页面上拉触底事件的处理函数
  97. */
  98. onReachBottom: function () {
  99. const pageNum = this.data.skip;
  100. const _pagenum = Math.ceil(this.data.total / this.data.limit);
  101. if (pageNum < _pagenum) {
  102. this.setData({
  103. skip: pageNum + 1 //设置下一页
  104. })
  105. this.searchInfo('正在刷新数据'); //查询数据
  106. } else {
  107. wx.showToast({
  108. title: '没有更多数据',
  109. })
  110. }
  111. },
  112. })