main.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. updateData: function () {
  52. for (let i = 0; i < this.data.mainDatas.length; i++) {
  53. this.data.mainDatas[i].show = (this.data.filterItem[1] === '' || this.data.mainDatas[i].type.indexOf(this.data.filterItem[1]) !== -1) &&
  54. (this.data.filterItem[2] === '' || this.data.filterItem[2] === this.data.mainDatas[i].publisher[0].type) &&
  55. (this.data.filterItem[3] === '' || this.data.mainDatas[i].tag.indexOf(this.data.filterItem[3]) !== -1)
  56. }
  57. this.setData({
  58. mainDatas: this.data.mainDatas
  59. })
  60. },
  61. showList: function (id) {
  62. this.data.toggleEnable = false
  63. this.setData({
  64. filterList: id
  65. })
  66. this.animate('#arrow' + id, [{
  67. rotate: 0
  68. },
  69. {
  70. rotate: 180
  71. },
  72. ], 150)
  73. this.animate('#list' + id, [{
  74. opacity: 0
  75. },
  76. {
  77. opacity: 1
  78. },
  79. ], 150)
  80. setTimeout(function () {
  81. this.setData({
  82. toggleEnable: true
  83. })
  84. }.bind(this), 200)
  85. },
  86. hideList: function (id) {
  87. this.data.toggleEnable = false
  88. this.animate('#arrow' + id, [{
  89. rotate: 180
  90. },
  91. {
  92. rotate: 360
  93. },
  94. ], 150)
  95. this.animate('#list' + id, [{
  96. opacity: 1
  97. },
  98. {
  99. opacity: 0
  100. },
  101. ], 150, function () {
  102. this.setData({
  103. filterList: 0
  104. })
  105. }.bind(this))
  106. setTimeout(function () {
  107. this.setData({
  108. toggleEnable: true
  109. })
  110. }.bind(this), 200)
  111. },
  112. toggleFilterList: function (e) {
  113. if (!this.data.toggleEnable) return
  114. const list = e.currentTarget.dataset.filterList
  115. if (this.data.filterList === list) {
  116. if (this.data.filterList !== 0) {
  117. this.hideList(this.data.filterList)
  118. }
  119. } else {
  120. if (this.data.filterList !== 0) {
  121. this.hideList(this.data.filterList)
  122. }
  123. if (list !== 0) {
  124. this.showList(list)
  125. }
  126. }
  127. },
  128. toggleFilterItem: function (e) {
  129. if (!this.data.toggleEnable) return
  130. if (this.data.filterList !== 0 && this.data.filterList === e.currentTarget.dataset.filterList) {
  131. var item = e.currentTarget.dataset.filterItem
  132. var arr = this.data.filterItem
  133. arr[this.data.filterList] = arr[this.data.filterList] === item ? '' : item;
  134. this.setData({
  135. filterItem: arr
  136. })
  137. this.updateData()
  138. this.hideList(this.data.filterList)
  139. }
  140. },
  141. filterMsgType: function (e) {
  142. this.data.filterItem[1] = e.detail.type
  143. this.setData({
  144. filterItem: this.data.filterItem
  145. })
  146. this.updateData()
  147. },
  148. filterTag: function (e) {
  149. this.data.filterItem[3] = e.detail.tag
  150. this.setData({
  151. filterItem: this.data.filterItem
  152. })
  153. this.updateData()
  154. },
  155. // processData: function (start, arr) {
  156. // const db = wx.cloud.database()
  157. // for (let i = start; i < arr.length; i++) {
  158. // arr[i].time = util.handleDate(arr[i].time)
  159. // db.collection('publisherInfoData').where({
  160. // publisherName: arr[i].publisherName
  161. // }).get({
  162. // success: function (res) {
  163. // arr[i].publisherAttribute = res.data[0].publisherAttribute
  164. // if (i == 0) {
  165. // arr[i].tag = ['紫金港', '管控', '保卫处']
  166. // } else if (i == 1) {
  167. // arr[i].tag = ['玉泉', '停电']
  168. // } else if (i == 2) {
  169. // arr[i].tag = ['公益', '画展']
  170. // }
  171. // this.setData({
  172. // mainDatas: arr
  173. // })
  174. // wx.hideNavigationBarLoading()
  175. // }.bind(this)
  176. // })
  177. // }
  178. // },
  179. loadMessageData: function () {
  180. wx.showNavigationBarLoading()
  181. wx.cloud.callFunction({
  182. name: 'listMessages',
  183. data: {
  184. page_token: this.data.pageToken,
  185. page_size: 25
  186. }
  187. }).then(res => {
  188. wx.hideNavigationBarLoading()
  189. for (let i = 0; i < res.result.list.length; i++) {
  190. res.result.list[i] = util.dbToMsg(res.result.list[i])
  191. }
  192. this.setData({
  193. mainDatas: this.data.mainDatas.concat(res.result.list),
  194. pageToken: this.data.pageToken + res.result.list.length
  195. })
  196. this.updateData()
  197. })
  198. },
  199. /**
  200. * 生命周期函数--监听页面加载
  201. */
  202. onLoad: function (options) {
  203. this.loadMessageData()
  204. // const db = wx.cloud.database()
  205. // db.collection('mainData').orderBy('time', 'desc').limit(20).get({
  206. // success: function (res) {
  207. // this.processData(0, res.data)
  208. // }.bind(this)
  209. // })
  210. },
  211. /**
  212. * 生命周期函数--监听页面初次渲染完成
  213. */
  214. onReady: function () {
  215. },
  216. /**
  217. * 生命周期函数--监听页面显示
  218. */
  219. onShow: function () {
  220. },
  221. /**
  222. * 生命周期函数--监听页面隐藏
  223. */
  224. onHide: function () {
  225. },
  226. /**
  227. * 生命周期函数--监听页面卸载
  228. */
  229. onUnload: function () {
  230. },
  231. /**
  232. * 页面相关事件处理函数--监听用户下拉动作
  233. */
  234. onPullDownRefresh: function () {
  235. this.setData({
  236. mainDatas: [],
  237. pageToken: 0
  238. })
  239. this.loadMessageData()
  240. },
  241. /**
  242. * 页面上拉触底事件的处理函数
  243. */
  244. onReachBottom: function () {
  245. this.loadMessageData()
  246. },
  247. /**
  248. * 用户点击右上角分享
  249. */
  250. onShareAppMessage: function () {
  251. }
  252. })