index.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // pages/create-order/index.js
  2. import http from '../../utils/http'
  3. import util from '../../utils/util'
  4. import api from '../../utils/api'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. tabs: ['未读', '已读'],
  11. tabIndex: 0,
  12. list: [[], []],
  13. is_read: [2, 1],
  14. touchBottom: [false, false],
  15. pages: [1, 1],
  16. stat: [0, 0]
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad: function (options) {
  22. api.getByName(this, 'notifications/getStat', 'stat');
  23. this.getList();
  24. },
  25. switchTab: function (e) {
  26. var index = e.currentTarget.dataset.index
  27. this.setData({
  28. tabIndex: index
  29. })
  30. wx.pageScrollTo({
  31. scrollTop: 0,
  32. duration: 300
  33. })
  34. this.search()
  35. },
  36. search() {
  37. this.setData({
  38. list: [
  39. [],
  40. []
  41. ],
  42. pages: [1, 1],
  43. touchBottom: [false, false]
  44. })
  45. this.getList()
  46. },
  47. getList: function () {
  48. var that = this
  49. var index = this.data.tabIndex
  50. var is_read = this.data.is_read[index]
  51. http({
  52. url: 'notifications/get',
  53. data: {
  54. is_read: is_read
  55. },
  56. success: function (res) {
  57. if (res.code == 0) {
  58. var list = that.data.list
  59. var touchBottom = that.data.touchBottom
  60. list[index] = list[index].concat(res.data);
  61. if (res.data.length <= 0) {
  62. touchBottom[index] = true;
  63. }
  64. that.setData({
  65. touchBottom,
  66. list
  67. })
  68. }
  69. }
  70. })
  71. },
  72. doAction: function(e) {
  73. var type = e.currentTarget.dataset.type
  74. var that = this
  75. http({
  76. url: 'notifications/change',
  77. data: {
  78. type: type
  79. },
  80. success: function (res) {
  81. if (res.code == 0) {
  82. that.search()
  83. that.getStat()
  84. }
  85. }
  86. })
  87. },
  88. /**
  89. * 生命周期函数--监听页面初次渲染完成
  90. */
  91. onReady: function () {
  92. },
  93. /**
  94. * 生命周期函数--监听页面显示
  95. */
  96. onShow: function () {
  97. },
  98. /**
  99. * 生命周期函数--监听页面隐藏
  100. */
  101. onHide: function () {
  102. },
  103. /**
  104. * 生命周期函数--监听页面卸载
  105. */
  106. onUnload: function () {
  107. },
  108. /**
  109. * 页面相关事件处理函数--监听用户下拉动作
  110. */
  111. onPullDownRefresh: function () {
  112. },
  113. /**
  114. * 页面上拉触底事件的处理函数
  115. */
  116. onReachBottom: function () {
  117. var index = this.data.tabIndex
  118. if(!this.data.isSearch && !this.data.touchBottom[index]) {
  119. var pages = this.data.pages
  120. pages[index] = pages[index] + 1;
  121. this.setData({
  122. pages
  123. })
  124. this.getList()
  125. }
  126. if(this.data.touchBottom[index]) {
  127. util.error('没有更多数据了')
  128. }
  129. },
  130. /**
  131. * 用户点击右上角分享
  132. */
  133. onShareAppMessage: function () {
  134. }
  135. })