|
|
@@ -6,51 +6,60 @@ Page({
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
+ pageToken: 0,
|
|
|
mainDatas: [],
|
|
|
toggleEnable: true,
|
|
|
filterList: 0,
|
|
|
- filterItem: ["", "", "", ""],
|
|
|
+ filterItem: ['', '', '', ''],
|
|
|
filterName: [{},
|
|
|
{
|
|
|
- title: "信息类型",
|
|
|
+ title: '信息类型',
|
|
|
children: [{
|
|
|
- title: "通知",
|
|
|
+ title: '通知',
|
|
|
children: [{
|
|
|
- title: "生活通知",
|
|
|
- children: ["水电通知", "缴费通知", "假期通知", "后勤通知", "图书馆通知"]
|
|
|
+ title: '生活通知',
|
|
|
+ children: ['水电通知', '缴费通知', '假期通知', '后勤通知', '图书馆通知']
|
|
|
},
|
|
|
{
|
|
|
- title: "学业通知",
|
|
|
- children: ["选课通知", "竞赛通知", "考试通知"]
|
|
|
+ title: '学业通知',
|
|
|
+ children: ['选课通知', '竞赛通知', '考试通知']
|
|
|
},
|
|
|
{
|
|
|
- title: "其他通知",
|
|
|
- children: ["其他通知"]
|
|
|
+ title: '其他通知',
|
|
|
+ children: ['其他通知']
|
|
|
}
|
|
|
]
|
|
|
},
|
|
|
{
|
|
|
- title: "活动",
|
|
|
- children: ["志愿活动", "文艺活动", "体育活动", "学术活动", "素质拓展", "精品课程", "其他活动"]
|
|
|
+ title: '活动',
|
|
|
+ children: ['志愿活动', '文艺活动', '体育活动', '学术活动', '素质拓展', '精品课程', '其他活动']
|
|
|
},
|
|
|
{
|
|
|
- title: "纳新",
|
|
|
- children: ["社团纳新", "组织纳新"]
|
|
|
+ title: '纳新',
|
|
|
+ children: ['社团纳新', '组织纳新']
|
|
|
}
|
|
|
]
|
|
|
},
|
|
|
{
|
|
|
- title: "发布来源",
|
|
|
- children: ["我关注的", "社团", "组织", "权服侠", "学校部门"]
|
|
|
+ title: '发布来源',
|
|
|
+ children: ['我关注的', '社团', '组织', '权服侠', '学校部门']
|
|
|
},
|
|
|
{
|
|
|
- title: "我的需求",
|
|
|
- children: ["二课分", "三课分", "四课分", "勤工助学", "志愿者小时数", "综素/活动纪实"]
|
|
|
+ title: '我的需求',
|
|
|
+ children: ['二课分', '三课分', '四课分', '勤工助学', '志愿者小时数', '综素/活动纪实']
|
|
|
}
|
|
|
- ],
|
|
|
- activity: null,
|
|
|
- inform: null,
|
|
|
- recruit: null
|
|
|
+ ]
|
|
|
+ },
|
|
|
+
|
|
|
+ updateData: function () {
|
|
|
+ for (let i = 0; i < this.data.mainDatas.length; i++) {
|
|
|
+ this.data.mainDatas[i].show = (this.data.filterItem[1] === '' || this.data.filterItem[1] === this.data.mainDatas[i].type) &&
|
|
|
+ (this.data.filterItem[2] === '' || this.data.filterItem[2] === this.data.mainDatas[i].publisher[0].type) &&
|
|
|
+ (this.data.filterItem[3] === '' || this.data.mainDatas[i].tag.indexOf(this.data.filterItem[3]) !== -1)
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ mainDatas: this.data.mainDatas
|
|
|
+ })
|
|
|
},
|
|
|
|
|
|
showList: function (id) {
|
|
|
@@ -58,14 +67,14 @@ Page({
|
|
|
this.setData({
|
|
|
filterList: id
|
|
|
})
|
|
|
- this.animate("#arrow" + id, [{
|
|
|
+ this.animate('#arrow' + id, [{
|
|
|
rotate: 0
|
|
|
},
|
|
|
{
|
|
|
rotate: 180
|
|
|
},
|
|
|
], 150)
|
|
|
- this.animate("#list" + id, [{
|
|
|
+ this.animate('#list' + id, [{
|
|
|
opacity: 0
|
|
|
},
|
|
|
{
|
|
|
@@ -81,14 +90,14 @@ Page({
|
|
|
|
|
|
hideList: function (id) {
|
|
|
this.data.toggleEnable = false
|
|
|
- this.animate("#arrow" + id, [{
|
|
|
+ this.animate('#arrow' + id, [{
|
|
|
rotate: 180
|
|
|
},
|
|
|
{
|
|
|
rotate: 360
|
|
|
},
|
|
|
], 150)
|
|
|
- this.animate("#list" + id, [{
|
|
|
+ this.animate('#list' + id, [{
|
|
|
opacity: 1
|
|
|
},
|
|
|
{
|
|
|
@@ -108,16 +117,16 @@ Page({
|
|
|
|
|
|
toggleFilterList: function (e) {
|
|
|
if (!this.data.toggleEnable) return
|
|
|
- var list = e.currentTarget.dataset.filterList
|
|
|
- if (this.data.filterList == list) {
|
|
|
- if (this.data.filterList != 0) {
|
|
|
+ const 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) {
|
|
|
+ if (this.data.filterList !== 0) {
|
|
|
this.hideList(this.data.filterList)
|
|
|
}
|
|
|
- if (list != 0) {
|
|
|
+ if (list !== 0) {
|
|
|
this.showList(list)
|
|
|
}
|
|
|
}
|
|
|
@@ -125,61 +134,94 @@ Page({
|
|
|
|
|
|
toggleFilterItem: function (e) {
|
|
|
if (!this.data.toggleEnable) return
|
|
|
- if (this.data.filterList != 0 && this.data.filterList == e.currentTarget.dataset.filterList) {
|
|
|
+ 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;
|
|
|
+ arr[this.data.filterList] = arr[this.data.filterList] === item ? '' : item;
|
|
|
this.setData({
|
|
|
filterItem: arr
|
|
|
})
|
|
|
+ this.updateData()
|
|
|
this.hideList(this.data.filterList)
|
|
|
}
|
|
|
},
|
|
|
|
|
|
filterMsgType: function (e) {
|
|
|
- var arr = this.data.filterItem
|
|
|
- arr[1] = e.detail.attr
|
|
|
+ this.data.filterItem[1] = e.detail.type
|
|
|
this.setData({
|
|
|
- filterItem: arr
|
|
|
+ filterItem: this.data.filterItem
|
|
|
})
|
|
|
+ this.updateData()
|
|
|
},
|
|
|
|
|
|
- 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)
|
|
|
+ filterTag: function (e) {
|
|
|
+ this.data.filterItem[3] = e.detail.tag
|
|
|
+ this.setData({
|
|
|
+ filterItem: this.data.filterItem
|
|
|
+ })
|
|
|
+ this.updateData()
|
|
|
+ },
|
|
|
+
|
|
|
+ // 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)
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+ // },
|
|
|
+
|
|
|
+ loadMessageData: function () {
|
|
|
+ wx.showNavigationBarLoading()
|
|
|
+ wx.cloud.callFunction({
|
|
|
+ name: 'listMessages',
|
|
|
+ data: {
|
|
|
+ page_token: this.data.pageToken,
|
|
|
+ page_size: 25
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ wx.hideNavigationBarLoading()
|
|
|
+ for (let i = 0; i < res.result.list.length; i++) {
|
|
|
+ res.result.list[i].photo = res.result.list[i].photo.split(',')
|
|
|
+ res.result.list[i].tag = res.result.list[i].tag.split(',')
|
|
|
+ res.result.list[i].publish_time = util.handleDate(res.result.list[i].publish_time)
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ mainDatas: this.data.mainDatas.concat(res.result.list),
|
|
|
+ pageToken: this.data.pageToken + res.result.list.length
|
|
|
})
|
|
|
- }
|
|
|
+ this.updateData()
|
|
|
+ })
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
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)
|
|
|
- })
|
|
|
+ this.loadMessageData()
|
|
|
+
|
|
|
+ // const db = wx.cloud.database()
|
|
|
+ // db.collection('mainData').orderBy('time', 'desc').limit(20).get({
|
|
|
+ // success: function (res) {
|
|
|
+ // this.processData(0, res.data)
|
|
|
+ // }.bind(this)
|
|
|
+ // })
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
@@ -214,32 +256,18 @@ Page({
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
*/
|
|
|
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)
|
|
|
+ this.setData({
|
|
|
+ mainDatas: [],
|
|
|
+ pageToken: 0
|
|
|
})
|
|
|
+ this.loadMessageData()
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
*/
|
|
|
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)
|
|
|
- })
|
|
|
+ this.loadMessageData()
|
|
|
},
|
|
|
|
|
|
/**
|