main.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. const util = require('../../utils/util.js')
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. pageToken: 0,
  8. mainDatas: [],
  9. loading: true,
  10. toggleEnable: true,
  11. filterList: 0,
  12. tempFilterList: 0,
  13. filterItem: ['', '', '', ''],
  14. filterName: [{},
  15. {
  16. title: '信息类型',
  17. children: [{
  18. title: '通知',
  19. children: [{
  20. title: '生活通知',
  21. children: ['水电通知', '缴费通知', '假期通知', '后勤通知', '图书馆通知']
  22. },
  23. {
  24. title: '学业通知',
  25. children: ['选课通知', '竞赛通知', '考试通知']
  26. },
  27. {
  28. title: '其他通知',
  29. children: ['其他通知']
  30. }
  31. ]
  32. },
  33. {
  34. title: '活动',
  35. children: ['志愿活动', '文艺活动', '体育活动', '学术活动', '素质拓展', '精品课程', '其他活动']
  36. },
  37. {
  38. title: '纳新',
  39. children: ['社团纳新', '组织纳新']
  40. }
  41. ]
  42. },
  43. {
  44. title: '发布来源',
  45. children: ['我关注的', '社团', '组织', '权服侠', '学校部门']
  46. },
  47. {
  48. title: '我的需求',
  49. children: ['二课分', '三课分', '四课分', '勤工助学', '志愿者小时数', '综素']
  50. }
  51. ]
  52. },
  53. showList: function (id) {
  54. this.setData({
  55. toggleEnable: false,
  56. filterList: id
  57. })
  58. this.animate('#arrow' + id, [{
  59. rotate: 0
  60. },
  61. {
  62. rotate: 180
  63. },
  64. ], 150)
  65. this.animate('#list' + id, [{
  66. opacity: 0
  67. },
  68. {
  69. opacity: 1
  70. },
  71. ], 150)
  72. setTimeout(function () {
  73. this.setData({
  74. toggleEnable: true
  75. })
  76. }.bind(this), 200)
  77. },
  78. hideList: function (id) {
  79. this.setData({
  80. toggleEnable: false,
  81. filterList: 0,
  82. tempFilterList: id
  83. })
  84. this.animate('#arrow' + id, [{
  85. rotate: 180
  86. },
  87. {
  88. rotate: 360
  89. },
  90. ], 150)
  91. this.animate('#list' + id, [{
  92. opacity: 1
  93. },
  94. {
  95. opacity: 0
  96. },
  97. ], 150)
  98. setTimeout(function () {
  99. this.setData({
  100. toggleEnable: true,
  101. tempFilterList: 0
  102. })
  103. }.bind(this), 200)
  104. },
  105. toggleFilterList: function (e) {
  106. if (!this.data.toggleEnable) {
  107. return
  108. }
  109. const currentList = this.data.filterList
  110. const list = e.currentTarget.dataset.filterList
  111. if (currentList !== 0) {
  112. this.hideList(currentList)
  113. }
  114. if (currentList !== list) {
  115. this.showList(list)
  116. }
  117. },
  118. toggleEmpty: function (e) {
  119. if (!this.data.toggleEnable) {
  120. return
  121. }
  122. const currentList = this.data.filterList
  123. if (currentList !== 0) {
  124. this.hideList(currentList)
  125. }
  126. },
  127. toggleFilterItem: function (e) {
  128. if (!this.data.toggleEnable) {
  129. return
  130. }
  131. const currentList = this.data.filterList
  132. const item = e.currentTarget.dataset.filterItem
  133. this.hideList(currentList)
  134. this.data.filterItem[currentList] = this.data.filterItem[currentList] === item ? '' : item;
  135. this.setData({
  136. filterItem: this.data.filterItem
  137. })
  138. this.loadMessageData(true)
  139. },
  140. filterMsgType: function (e) {
  141. this.data.filterItem[1] = e.detail.type
  142. this.setData({
  143. filterItem: this.data.filterItem
  144. })
  145. this.loadMessageData(true)
  146. },
  147. filterTag: function (e) {
  148. this.data.filterItem[3] = e.detail.tag
  149. this.setData({
  150. filterItem: this.data.filterItem
  151. })
  152. this.loadMessageData(true)
  153. },
  154. loadMessageData: function (refresh) {
  155. this.setData({
  156. loading: true
  157. })
  158. wx.showNavigationBarLoading()
  159. wx.cloud.callFunction({
  160. name: 'listMessages',
  161. data: {
  162. filter: this.data.filterItem,
  163. page_token: refresh ? 0 : this.data.pageToken,
  164. page_size: 20
  165. }
  166. }).then(res => {
  167. wx.hideNavigationBarLoading()
  168. wx.stopPullDownRefresh()
  169. if (res.result.status !== 'OK') {
  170. wx.showToast({
  171. title: res.result.errMsg,
  172. icon: 'none'
  173. })
  174. return
  175. }
  176. for (let i = 0; i < res.result.list.length; i++) {
  177. res.result.list[i] = util.dbToMsg(res.result.list[i])
  178. }
  179. this.setData({
  180. mainDatas: refresh ? res.result.list : this.data.mainDatas.concat(res.result.list),
  181. pageToken: res.result.next_page_token,
  182. loading: false
  183. })
  184. })
  185. },
  186. /**
  187. * 生命周期函数--监听页面加载
  188. */
  189. onLoad: function (options) {
  190. this.loadMessageData(true)
  191. },
  192. /**
  193. * 生命周期函数--监听页面初次渲染完成
  194. */
  195. onReady: function () {
  196. },
  197. /**
  198. * 生命周期函数--监听页面显示
  199. */
  200. onShow: function () {
  201. },
  202. /**
  203. * 生命周期函数--监听页面隐藏
  204. */
  205. onHide: function () {
  206. },
  207. /**
  208. * 生命周期函数--监听页面卸载
  209. */
  210. onUnload: function () {
  211. },
  212. /**
  213. * 页面相关事件处理函数--监听用户下拉动作
  214. */
  215. onPullDownRefresh: function () {
  216. if (this.data.loading) {
  217. return
  218. }
  219. this.loadMessageData(true)
  220. },
  221. /**
  222. * 页面上拉触底事件的处理函数
  223. */
  224. onReachBottom: function () {
  225. if (this.data.loading) {
  226. return
  227. }
  228. this.loadMessageData(false)
  229. },
  230. /**
  231. * 用户点击右上角分享
  232. */
  233. onShareAppMessage: function () {
  234. }
  235. })