index.js 2.9 KB

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