| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- const util = require('../../utils/util.js')
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- mainDatas: [],
- toggleEnable: true,
- filterList: 0,
- filterItem: ["", "", "", ""],
- filterName: [{},
- {
- type: "信息类型",
- list: [{
- sub: "通知",
- item: [{
- secondSub: "生活通知",
- subitem: ["水电通知", "缴费通知", "假期通知", "后勤通知", "图书馆通知"]
- },
- {
- secondSub: "学业通知",
- subitem: ["选课通知", "竞赛通知", "考试通知"]
- },
- {
- secondSub: "其他通知",
- subitem: ["其他通知"]
- }
- ]
- },
- {
- sub: "活动",
- item: ["志愿活动", "文艺活动", "体育活动", "学术活动", "素质拓展", "精品课程", "其他活动"]
- },
- {
- sub: "纳新",
- item: ["社团纳新", "组织纳新"]
- }
- ]
- },
- {
- type: "发布来源",
- item: ["我关注的", "社团", "组织", "权服侠", "学校部门"]
- },
- {
- type: "我的需求",
- item: ["二课分", "三课分", "四课分", "勤工助学", "志愿者小时数", "综素/活动纪实"]
- }
- ],
- activity: null,
- inform: null,
- recruit: null
- },
- showList: function (id) {
- this.data.toggleEnable = false
- this.setData({
- filterList: id
- })
- this.animate("#arrow" + id, [{
- rotate: 0
- },
- {
- rotate: 180
- },
- ], 150)
- this.animate("#list" + id, [{
- opacity: 0
- },
- {
- opacity: 1
- },
- ], 150)
- setTimeout(function () {
- this.setData({
- toggleEnable: true
- })
- }.bind(this), 200)
- },
- hideList: function (id) {
- this.data.toggleEnable = false
- this.animate("#arrow" + id, [{
- rotate: 180
- },
- {
- rotate: 360
- },
- ], 150)
- this.animate("#list" + id, [{
- opacity: 1
- },
- {
- opacity: 0
- },
- ], 150, function () {
- this.setData({
- filterList: 0
- })
- }.bind(this))
- setTimeout(function () {
- this.setData({
- toggleEnable: true
- })
- }.bind(this), 200)
- },
- toggleFilterList: function (e) {
- if (!this.data.toggleEnable) return
- var list = e.currentTarget.dataset.filterList
- if (this.data.filterList == list) {
- if (this.data.filterList != 0) {
- this.hideList(this.data.filterList)
- }
- } else {
- if (this.data.filterList != 0) {
- this.hideList(this.data.filterList)
- }
- if (list != 0) {
- this.showList(list)
- }
- }
- },
- toggleFilterItem: function (e) {
- if (!this.data.toggleEnable) return
- if (this.data.filterList != 0 && this.data.filterList == e.currentTarget.dataset.filterList) {
- var item = e.currentTarget.dataset.filterItem
- var arr = this.data.filterItem
- arr[this.data.filterList] = arr[this.data.filterList] == item ? "" : item;
- this.setData({
- filterItem: arr
- })
- this.hideList(this.data.filterList)
- }
- },
- filterMsgType: function (e) {
- var arr = this.data.filterItem
- arr[1] = e.detail.attr
- this.setData({
- filterItem: arr
- })
- },
- processData: function (start, arr) {
- const db = wx.cloud.database()
- for (let i = start; i < arr.length; i++) {
- arr[i].time = util.handleDate(arr[i].time)
- db.collection("publisherInfoData").where({
- publisherName: arr[i].publisherName
- }).get({
- success: function (res) {
- arr[i].publisherAttribute = res.data[0].publisherAttribute
- if (i == 0) {
- arr[i].tag = ['紫金港', '管控', '保卫处']
- } else if (i == 1) {
- arr[i].tag = ['公益', '丹青']
- } else if (i == 2) {
- arr[i].tag = ['玉泉', '停电']
- }
- this.setData({
- mainDatas: arr
- })
- wx.hideNavigationBarLoading()
- }.bind(this)
- })
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- wx.showNavigationBarLoading()
- const db = wx.cloud.database()
- db.collection("mainData").orderBy("time", "desc").limit(20).get({
- success: function (res) {
- this.processData(0, res.data)
- }.bind(this)
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- wx.showNavigationBarLoading()
- const db = wx.cloud.database()
- db.collection("mainData").orderBy("time", "desc").limit(20).get({
- success: function (res) {
- this.processData(0, res.data)
- wx.stopPullDownRefresh()
- }.bind(this)
- })
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- wx.showNavigationBarLoading()
- const db = wx.cloud.database()
- db.collection("mainData").orderBy("time", "desc").skip(this.data.mainDatas.length).limit(20).get({
- success: function (res) {
- if (res.data.length == 0) {
- wx.hideNavigationBarLoading()
- return
- }
- res.data = this.data.mainDatas.concat(res.data)
- this.processData(this.data.mainDatas.length, res.data)
- }.bind(this)
- })
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|