index.js 2.9 KB

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