main.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. // this.updateData()
  140. },
  141. filterMsgType: function (e) {
  142. this.data.filterItem[1] = e.detail.type
  143. this.setData({
  144. filterItem: this.data.filterItem
  145. })
  146. this.loadMessageData(true)
  147. // this.updateData()
  148. },
  149. filterTag: function (e) {
  150. this.data.filterItem[3] = e.detail.tag
  151. this.setData({
  152. filterItem: this.data.filterItem
  153. })
  154. this.loadMessageData(true)
  155. // this.updateData()
  156. },
  157. // updateData: function () {
  158. // for (let i = 0; i < this.data.mainDatas.length; i++) {
  159. // this.data.mainDatas[i].show = (this.data.filterItem[1] === '' || this.data.mainDatas[i].type.indexOf(this.data.filterItem[1]) !== -1) &&
  160. // (this.data.filterItem[2] === '' || this.data.filterItem[2] === this.data.mainDatas[i].publisher.type) &&
  161. // (this.data.filterItem[3] === '' || this.data.mainDatas[i].tag.indexOf(this.data.filterItem[3]) !== -1)
  162. // }
  163. // this.setData({
  164. // mainDatas: this.data.mainDatas
  165. // })
  166. // },
  167. loadMessageData: function (refresh) {
  168. this.setData({
  169. loading: true
  170. })
  171. wx.showNavigationBarLoading()
  172. wx.cloud.callFunction({
  173. name: 'listMessages',
  174. data: {
  175. filter: this.data.filterItem,
  176. page_token: refresh ? 0 : this.data.pageToken,
  177. page_size: 20
  178. }
  179. }).then(res => {
  180. wx.hideNavigationBarLoading()
  181. wx.stopPullDownRefresh()
  182. if (res.result.status !== 'OK') {
  183. wx.showToast({
  184. title: res.result.errMsg,
  185. icon: 'none'
  186. })
  187. return
  188. }
  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: refresh ? res.result.list : this.data.mainDatas.concat(res.result.list),
  194. pageToken: res.result.next_page_token,
  195. loading: false
  196. })
  197. // this.updateData()
  198. })
  199. },
  200. /**
  201. * 生命周期函数--监听页面加载
  202. */
  203. onLoad: function (options) {
  204. this.loadMessageData(true)
  205. },
  206. /**
  207. * 生命周期函数--监听页面初次渲染完成
  208. */
  209. onReady: function () {
  210. },
  211. /**
  212. * 生命周期函数--监听页面显示
  213. */
  214. onShow: function () {
  215. },
  216. /**
  217. * 生命周期函数--监听页面隐藏
  218. */
  219. onHide: function () {
  220. },
  221. /**
  222. * 生命周期函数--监听页面卸载
  223. */
  224. onUnload: function () {
  225. },
  226. /**
  227. * 页面相关事件处理函数--监听用户下拉动作
  228. */
  229. onPullDownRefresh: function () {
  230. if (this.data.loading) {
  231. return
  232. }
  233. this.loadMessageData(true)
  234. },
  235. /**
  236. * 页面上拉触底事件的处理函数
  237. */
  238. onReachBottom: function () {
  239. if (this.data.loading) {
  240. return
  241. }
  242. this.loadMessageData(false)
  243. },
  244. /**
  245. * 用户点击右上角分享
  246. */
  247. onShareAppMessage: function () {
  248. }
  249. })