main.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. const util = require('../../utils/util.js')
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. mainDatas: [],
  8. toggleEnable: true,
  9. filterList: 0,
  10. filterItem: ["", "", "", ""],
  11. filterName: [{},
  12. {
  13. type: "信息类型",
  14. list: [{
  15. sub: "通知",
  16. item: [{
  17. secondSub: "生活通知",
  18. subitem: ["水电通知", "缴费通知", "假期通知", "后勤通知", "图书馆通知"]
  19. },
  20. {
  21. secondSub: "学业通知",
  22. subitem: ["选课通知", "竞赛通知", "考试通知"]
  23. },
  24. {
  25. secondSub: "其他通知",
  26. subitem: ["其他通知"]
  27. }
  28. ]
  29. },
  30. {
  31. sub: "活动",
  32. item: ["志愿活动", "文艺活动", "体育活动", "学术活动", "素质拓展", "精品课程", "其他活动"]
  33. },
  34. {
  35. sub: "纳新",
  36. item: ["社团纳新", "组织纳新"]
  37. }
  38. ]
  39. },
  40. {
  41. type: "发布来源",
  42. item: ["我关注的", "社团", "组织", "权服侠", "学校部门"]
  43. },
  44. {
  45. type: "我的需求",
  46. item: ["二课分", "三课分", "四课分", "勤工助学", "志愿者小时数", "综素/活动纪实"]
  47. }
  48. ],
  49. activity: null,
  50. inform: null,
  51. recruit: null
  52. },
  53. showList: function (id) {
  54. this.data.toggleEnable = false
  55. this.setData({
  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.data.toggleEnable = false
  80. this.animate("#arrow" + id, [{
  81. rotate: 180
  82. },
  83. {
  84. rotate: 360
  85. },
  86. ], 150)
  87. this.animate("#list" + id, [{
  88. opacity: 1
  89. },
  90. {
  91. opacity: 0
  92. },
  93. ], 150, function () {
  94. this.setData({
  95. filterList: 0
  96. })
  97. }.bind(this))
  98. setTimeout(function () {
  99. this.setData({
  100. toggleEnable: true
  101. })
  102. }.bind(this), 200)
  103. },
  104. toggleFilterList: function (e) {
  105. if (!this.data.toggleEnable) return
  106. var list = e.currentTarget.dataset.filterList
  107. if (this.data.filterList == list) {
  108. if (this.data.filterList != 0) {
  109. this.hideList(this.data.filterList)
  110. }
  111. } else {
  112. if (this.data.filterList != 0) {
  113. this.hideList(this.data.filterList)
  114. }
  115. if (list != 0) {
  116. this.showList(list)
  117. }
  118. }
  119. },
  120. toggleFilterItem: function (e) {
  121. if (!this.data.toggleEnable) return
  122. if (this.data.filterList != 0 && this.data.filterList == e.currentTarget.dataset.filterList) {
  123. var item = e.currentTarget.dataset.filterItem
  124. var arr = this.data.filterItem
  125. arr[this.data.filterList] = arr[this.data.filterList] == item ? "" : item;
  126. this.setData({
  127. filterItem: arr
  128. })
  129. this.hideList(this.data.filterList)
  130. }
  131. },
  132. filterMsgType: function (e) {
  133. var arr = this.data.filterItem
  134. arr[1] = e.detail.attr
  135. this.setData({
  136. filterItem: arr
  137. })
  138. },
  139. processData: function (start, arr) {
  140. const db = wx.cloud.database()
  141. for (let i = start; i < arr.length; i++) {
  142. arr[i].time = util.handleDate(arr[i].time)
  143. db.collection("publisherInfoData").where({
  144. publisherName: arr[i].publisherName
  145. }).get({
  146. success: function (res) {
  147. arr[i].publisherAttribute = res.data[0].publisherAttribute
  148. if (i == 0) {
  149. arr[i].tag = ['紫金港', '管控', '保卫处']
  150. } else if (i == 1) {
  151. arr[i].tag = ['公益', '丹青']
  152. } else if (i == 2) {
  153. arr[i].tag = ['玉泉', '停电']
  154. }
  155. this.setData({
  156. mainDatas: arr
  157. })
  158. wx.hideNavigationBarLoading()
  159. }.bind(this)
  160. })
  161. }
  162. },
  163. /**
  164. * 生命周期函数--监听页面加载
  165. */
  166. onLoad: function (options) {
  167. wx.showNavigationBarLoading()
  168. const db = wx.cloud.database()
  169. db.collection("mainData").orderBy("time", "desc").limit(20).get({
  170. success: function (res) {
  171. this.processData(0, res.data)
  172. }.bind(this)
  173. })
  174. },
  175. /**
  176. * 生命周期函数--监听页面初次渲染完成
  177. */
  178. onReady: function () {
  179. },
  180. /**
  181. * 生命周期函数--监听页面显示
  182. */
  183. onShow: function () {
  184. },
  185. /**
  186. * 生命周期函数--监听页面隐藏
  187. */
  188. onHide: function () {
  189. },
  190. /**
  191. * 生命周期函数--监听页面卸载
  192. */
  193. onUnload: function () {
  194. },
  195. /**
  196. * 页面相关事件处理函数--监听用户下拉动作
  197. */
  198. onPullDownRefresh: function () {
  199. wx.showNavigationBarLoading()
  200. const db = wx.cloud.database()
  201. db.collection("mainData").orderBy("time", "desc").limit(20).get({
  202. success: function (res) {
  203. this.processData(0, res.data)
  204. wx.stopPullDownRefresh()
  205. }.bind(this)
  206. })
  207. },
  208. /**
  209. * 页面上拉触底事件的处理函数
  210. */
  211. onReachBottom: function () {
  212. wx.showNavigationBarLoading()
  213. const db = wx.cloud.database()
  214. db.collection("mainData").orderBy("time", "desc").skip(this.data.mainDatas.length).limit(20).get({
  215. success: function (res) {
  216. if (res.data.length == 0) {
  217. wx.hideNavigationBarLoading()
  218. return
  219. }
  220. res.data = this.data.mainDatas.concat(res.data)
  221. this.processData(this.data.mainDatas.length, res.data)
  222. }.bind(this)
  223. })
  224. },
  225. /**
  226. * 用户点击右上角分享
  227. */
  228. onShareAppMessage: function () {
  229. }
  230. })