main.js 6.1 KB

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