message.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. // pages/message/message.js
  2. const utils = require('../../utils/util.js')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. isLogin: '', //是否登陆
  9. userInfo: '', //缓存用户信息
  10. list: [],
  11. pageNum: 1,
  12. pageSize: 10,
  13. pages: '',
  14. finish: false,
  15. listNotice: [],
  16. pageNumNotice: 1,
  17. pageSizeNotice: 10,
  18. pagesNotice: '',
  19. finishNotice: false,
  20. curIndex: 0
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function (options) {
  26. this.setData({
  27. userInfo: utils.getInfo()
  28. })
  29. if (this.data.userInfo.mobile) {
  30. this.getList()
  31. this.getNotice()
  32. } else {
  33. this.setData({
  34. isLogin: false
  35. })
  36. }
  37. },
  38. switchTab(e) {
  39. const curIndex = Number(e.currentTarget.dataset.index)
  40. this.setData({
  41. curIndex
  42. })
  43. },
  44. // 公告列表
  45. getNotice() {
  46. let params = {
  47. mobile: this.data.userInfo.mobile,
  48. pageNum: this.data.pageNumNotice,
  49. pageSize: this.data.pageSizeNotice
  50. }
  51. utils.axios({
  52. method: 'get',
  53. url: '/auth/user/msg/findGlobalNotice',
  54. data: params,
  55. noLogin: () => {},
  56. complete: () => {},
  57. success: res => {
  58. console.log(12);
  59. let result = res.data
  60. let listNotice = this.data.listNotice
  61. listNotice = listNotice.concat(result.records)
  62. this.setData({
  63. listNotice,
  64. pagesNotice: result.pages
  65. })
  66. if (result.total <= this.data.pageSizeNotice) {
  67. this.setData({
  68. finishNotice: true
  69. })
  70. }
  71. }
  72. })
  73. },
  74. //消息列表
  75. getList() {
  76. let params = {
  77. mobile: this.data.userInfo.mobile,
  78. pageNum: this.data.pageNum,
  79. pageSize: this.data.pageSize
  80. }
  81. utils.axios({
  82. method: 'get',
  83. url: '/auth/user/msg/findUserMsg',
  84. data: params,
  85. sendBefore() {
  86. wx.showLoading({
  87. title: '加载中...'
  88. })
  89. },
  90. complete() {
  91. wx.hideLoading()
  92. wx.stopPullDownRefresh()
  93. },
  94. noLogin: () => {
  95. this.setData({
  96. isLogin: false
  97. })
  98. },
  99. success: res => {
  100. this.setData({
  101. isLogin: true
  102. })
  103. let result = res.data
  104. let list = this.data.list
  105. list = list.concat(result.records)
  106. this.setData({
  107. list,
  108. pages: result.pages
  109. })
  110. if (result.total <= this.data.pageSize) {
  111. this.setData({
  112. finish: true
  113. })
  114. }
  115. }
  116. })
  117. },
  118. toFresh() {
  119. if (this.data.curIndex === 0) {
  120. this.setData({
  121. list: [],
  122. pageNum: 1,
  123. pages: '',
  124. finish: false
  125. })
  126. this.getList()
  127. } else {
  128. this.setData({
  129. listNotice: [],
  130. pageNumNotice: 1,
  131. pagesNotice: '',
  132. finishNotice: false
  133. })
  134. this.getNotice()
  135. }
  136. },
  137. //公告详情
  138. toDetail(e) {
  139. let msgId = e.currentTarget.dataset.id
  140. wx.navigateTo({
  141. url: '/pages/notice/noticeDetail?msgId=' + msgId
  142. })
  143. },
  144. //去登录
  145. toLogin() {
  146. utils.toLogin()
  147. },
  148. /**
  149. * 生命周期函数--监听页面初次渲染完成
  150. */
  151. onReady: function () {
  152. },
  153. /**
  154. * 生命周期函数--监听页面显示
  155. */
  156. onShow: function () {
  157. if (typeof this.getTabBar === 'function' &&
  158. this.getTabBar()) {
  159. this.getTabBar().setData({
  160. selected: 1
  161. })
  162. }
  163. },
  164. /**
  165. * 生命周期函数--监听页面隐藏
  166. */
  167. onHide: function () {
  168. },
  169. /**
  170. * 生命周期函数--监听页面卸载
  171. */
  172. onUnload: function () {
  173. },
  174. /**
  175. * 页面相关事件处理函数--监听用户下拉动作
  176. */
  177. onPullDownRefresh: function () {
  178. this.toFresh()
  179. },
  180. /**
  181. * 页面上拉触底事件的处理函数
  182. */
  183. onReachBottom: function () {
  184. if (this.data.curIndex === 0) {
  185. let pageNum = this.data.pageNum
  186. let pages = this.data.pages
  187. pageNum++
  188. if (pageNum <= pages) {
  189. this.setData({
  190. pageNum
  191. })
  192. this.getList()
  193. } else {
  194. this.setData({
  195. finish: true
  196. })
  197. return
  198. }
  199. }else{
  200. let pageNumNotice = this.data.pageNumNotice
  201. let pagesNotice = this.data.pagesNotice
  202. pageNumNotice++
  203. if (pageNumNotice <= pagesNotice) {
  204. this.setData({
  205. pageNumNotice
  206. })
  207. this.getNotice()
  208. } else {
  209. this.setData({
  210. finishNotice: true
  211. })
  212. return
  213. }
  214. }
  215. },
  216. /**
  217. * 用户点击右上角分享
  218. */
  219. onShareAppMessage: function () {
  220. return {
  221. title: '诺信云',
  222. path: '/pages/index/index'
  223. }
  224. }
  225. })