main.js 6.1 KB

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