|
@@ -9,11 +9,10 @@ Page({
|
|
|
data: {
|
|
data: {
|
|
|
messageId: '',
|
|
messageId: '',
|
|
|
activityInfo: {},
|
|
activityInfo: {},
|
|
|
|
|
+ like: false,
|
|
|
showEdit: false,
|
|
showEdit: false,
|
|
|
pageToken: 0,
|
|
pageToken: 0,
|
|
|
activityComment: [],
|
|
activityComment: [],
|
|
|
- like: -1,
|
|
|
|
|
- likeEnable: true,
|
|
|
|
|
commentText: ''
|
|
commentText: ''
|
|
|
},
|
|
},
|
|
|
|
|
|
|
@@ -26,63 +25,90 @@ Page({
|
|
|
editActivity: function () {
|
|
editActivity: function () {
|
|
|
wx.navigateTo({
|
|
wx.navigateTo({
|
|
|
url: '/pages/activityPublish/activityPublish?id=' + this.data.activityInfo.pub_id +
|
|
url: '/pages/activityPublish/activityPublish?id=' + this.data.activityInfo.pub_id +
|
|
|
- '&msg_id=' + this.data.activityInfo._id
|
|
|
|
|
|
|
+ '&msg_id=' + this.data.messageId
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
toggleLike: function () {
|
|
toggleLike: function () {
|
|
|
- if (!this.data.likeEnable) return
|
|
|
|
|
- this.setData({
|
|
|
|
|
- likeEnable: false
|
|
|
|
|
|
|
+ wx.showLoading({
|
|
|
|
|
+ title: this.data.like ? '取消收藏' : '收藏中'
|
|
|
})
|
|
})
|
|
|
- const db = wx.cloud.database()
|
|
|
|
|
- if (this.data.like == 0) {
|
|
|
|
|
- db.collection('likeData').add({
|
|
|
|
|
- data: {
|
|
|
|
|
- type: 'message',
|
|
|
|
|
- id: this.data.activityInfo._id
|
|
|
|
|
- },
|
|
|
|
|
- success: function () {
|
|
|
|
|
- this.setData({
|
|
|
|
|
- like: 1,
|
|
|
|
|
- likeEnable: true
|
|
|
|
|
- })
|
|
|
|
|
- wx.showToast({
|
|
|
|
|
- title: '已收藏',
|
|
|
|
|
- })
|
|
|
|
|
- }.bind(this),
|
|
|
|
|
- fail: function () {
|
|
|
|
|
- wx.showToast({
|
|
|
|
|
- title: '网络错误',
|
|
|
|
|
- icon: 'none'
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ wx.cloud.callFunction({
|
|
|
|
|
+ name: this.data.like ? 'deleteFavorite' : 'createFavorite',
|
|
|
|
|
+ data: {
|
|
|
|
|
+ msg_id: this.data.messageId
|
|
|
|
|
+ }
|
|
|
|
|
+ }).then(res => {
|
|
|
|
|
+ wx.hideLoading()
|
|
|
|
|
+ if (res.result.status !== 'OK') {
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: res.result.errMsg,
|
|
|
|
|
+ icon: 'none'
|
|
|
|
|
+ })
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: this.data.like ? '取消收藏成功' : '收藏成功',
|
|
|
|
|
+ icon: 'none'
|
|
|
})
|
|
})
|
|
|
- } else {
|
|
|
|
|
- db.collection('likeData').where({
|
|
|
|
|
- type: 'message',
|
|
|
|
|
- id: this.data.activityInfo._id
|
|
|
|
|
- }).remove({
|
|
|
|
|
- success: function () {
|
|
|
|
|
- this.setData({
|
|
|
|
|
- like: 0,
|
|
|
|
|
- likeEnable: true
|
|
|
|
|
- })
|
|
|
|
|
- wx.showToast({
|
|
|
|
|
- title: '已取消收藏',
|
|
|
|
|
- })
|
|
|
|
|
- }.bind(this),
|
|
|
|
|
- fail: function () {
|
|
|
|
|
- wx.showToast({
|
|
|
|
|
- title: '网络错误',
|
|
|
|
|
- icon: 'none'
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ this.setData({
|
|
|
|
|
+ like: !this.data.like
|
|
|
})
|
|
})
|
|
|
- }
|
|
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ // if (!this.data.likeEnable) return
|
|
|
|
|
+ // this.setData({
|
|
|
|
|
+ // likeEnable: false
|
|
|
|
|
+ // })
|
|
|
|
|
+ // const db = wx.cloud.database()
|
|
|
|
|
+ // if (this.data.like == 0) {
|
|
|
|
|
+ // db.collection('likeData').add({
|
|
|
|
|
+ // data: {
|
|
|
|
|
+ // type: 'message',
|
|
|
|
|
+ // id: this.data.activityInfo._id
|
|
|
|
|
+ // },
|
|
|
|
|
+ // success: function () {
|
|
|
|
|
+ // this.setData({
|
|
|
|
|
+ // like: 1,
|
|
|
|
|
+ // likeEnable: true
|
|
|
|
|
+ // })
|
|
|
|
|
+ // wx.showToast({
|
|
|
|
|
+ // title: '已收藏',
|
|
|
|
|
+ // })
|
|
|
|
|
+ // }.bind(this),
|
|
|
|
|
+ // fail: function () {
|
|
|
|
|
+ // wx.showToast({
|
|
|
|
|
+ // title: '网络错误',
|
|
|
|
|
+ // icon: 'none'
|
|
|
|
|
+ // })
|
|
|
|
|
+ // }
|
|
|
|
|
+ // })
|
|
|
|
|
+ // } else {
|
|
|
|
|
+ // db.collection('likeData').where({
|
|
|
|
|
+ // type: 'message',
|
|
|
|
|
+ // id: this.data.activityInfo._id
|
|
|
|
|
+ // }).remove({
|
|
|
|
|
+ // success: function () {
|
|
|
|
|
+ // this.setData({
|
|
|
|
|
+ // like: 0,
|
|
|
|
|
+ // likeEnable: true
|
|
|
|
|
+ // })
|
|
|
|
|
+ // wx.showToast({
|
|
|
|
|
+ // title: '已取消收藏',
|
|
|
|
|
+ // })
|
|
|
|
|
+ // }.bind(this),
|
|
|
|
|
+ // fail: function () {
|
|
|
|
|
+ // wx.showToast({
|
|
|
|
|
+ // title: '网络错误',
|
|
|
|
|
+ // icon: 'none'
|
|
|
|
|
+ // })
|
|
|
|
|
+ // }
|
|
|
|
|
+ // })
|
|
|
|
|
+ // }
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
loadQuestionData: function () {
|
|
loadQuestionData: function () {
|
|
|
|
|
+ wx.showNavigationBarLoading()
|
|
|
wx.cloud.callFunction({
|
|
wx.cloud.callFunction({
|
|
|
name: 'listQuestions',
|
|
name: 'listQuestions',
|
|
|
data: {
|
|
data: {
|
|
@@ -91,12 +117,20 @@ Page({
|
|
|
page_size: 25
|
|
page_size: 25
|
|
|
}
|
|
}
|
|
|
}).then(res => {
|
|
}).then(res => {
|
|
|
|
|
+ wx.hideNavigationBarLoading()
|
|
|
|
|
+ if (res.result.status !== 'OK') {
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: res.result.errMsg,
|
|
|
|
|
+ icon: 'none'
|
|
|
|
|
+ })
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
for (let i = 0; i < res.result.list.length; i++) {
|
|
for (let i = 0; i < res.result.list.length; i++) {
|
|
|
res.result.list[i].a_time = util.handleDate(res.result.list[i].a_time)
|
|
res.result.list[i].a_time = util.handleDate(res.result.list[i].a_time)
|
|
|
}
|
|
}
|
|
|
this.setData({
|
|
this.setData({
|
|
|
activityComment: this.data.activityComment.concat(res.result.list),
|
|
activityComment: this.data.activityComment.concat(res.result.list),
|
|
|
- pageToken: this.data.pageToken + res.result.list.length
|
|
|
|
|
|
|
+ pageToken: res.result.next_page_token
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
@@ -114,11 +148,18 @@ Page({
|
|
|
wx.cloud.callFunction({
|
|
wx.cloud.callFunction({
|
|
|
name: 'createQuestion',
|
|
name: 'createQuestion',
|
|
|
data: {
|
|
data: {
|
|
|
- msg_id: this.data.activityInfo._id,
|
|
|
|
|
|
|
+ msg_id: this.data.messageId,
|
|
|
question: this.data.commentText
|
|
question: this.data.commentText
|
|
|
}
|
|
}
|
|
|
}).then(res => {
|
|
}).then(res => {
|
|
|
wx.hideLoading()
|
|
wx.hideLoading()
|
|
|
|
|
+ if (res.result.status !== 'OK') {
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: res.result.errMsg,
|
|
|
|
|
+ icon: 'none'
|
|
|
|
|
+ })
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
wx.showToast({
|
|
wx.showToast({
|
|
|
title: '发送成功,请等待发布者回复',
|
|
title: '发送成功,请等待发布者回复',
|
|
|
icon: 'none'
|
|
icon: 'none'
|
|
@@ -127,42 +168,6 @@ Page({
|
|
|
commentText: ''
|
|
commentText: ''
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
-
|
|
|
|
|
- // const db = wx.cloud.database()
|
|
|
|
|
- // db.collection('qaData').where({
|
|
|
|
|
- // _openid: app.globalData.openId,
|
|
|
|
|
- // activityId: this.data.activityInfo._id
|
|
|
|
|
- // }).get({
|
|
|
|
|
- // success: function (res) {
|
|
|
|
|
- // console.log(res)
|
|
|
|
|
- // if (res.data.length >= 10) {
|
|
|
|
|
- // wx.showToast({
|
|
|
|
|
- // title: '为防止刷屏,每人每消息至多提问10条',
|
|
|
|
|
- // icon: 'none'
|
|
|
|
|
- // })
|
|
|
|
|
- // } else {
|
|
|
|
|
- // db.collection('qaData').add({
|
|
|
|
|
- // data: {
|
|
|
|
|
- // activityId: this.data.activityInfo._id,
|
|
|
|
|
- // publisherId: this.data.activityInfo.publisherId,
|
|
|
|
|
- // answer: '',
|
|
|
|
|
- // answerTime: '',
|
|
|
|
|
- // question: this.data.commentText,
|
|
|
|
|
- // questionTime: new Date(),
|
|
|
|
|
- // rank: ''
|
|
|
|
|
- // },
|
|
|
|
|
- // success: function () {
|
|
|
|
|
- // this.setData({
|
|
|
|
|
- // commentText: ''
|
|
|
|
|
- // })
|
|
|
|
|
- // wx.showToast({
|
|
|
|
|
- // title: '提问成功'
|
|
|
|
|
- // })
|
|
|
|
|
- // }.bind(this)
|
|
|
|
|
- // })
|
|
|
|
|
- // }
|
|
|
|
|
- // }.bind(this)
|
|
|
|
|
- // })
|
|
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
|
|
|
|
@@ -184,58 +189,27 @@ Page({
|
|
|
}
|
|
}
|
|
|
}).then(res => {
|
|
}).then(res => {
|
|
|
wx.hideLoading()
|
|
wx.hideLoading()
|
|
|
- res.result.list[0] = util.dbToMsg(res.result.list[0])
|
|
|
|
|
|
|
+ if (res.result.status !== 'OK') {
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: res.result.errMsg,
|
|
|
|
|
+ icon: 'none'
|
|
|
|
|
+ })
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ res.result.data = util.dbToMsg(res.result.data)
|
|
|
let edit = false
|
|
let edit = false
|
|
|
for (let i = 0; i < app.globalData.pubInfo.length; i++) {
|
|
for (let i = 0; i < app.globalData.pubInfo.length; i++) {
|
|
|
- if (res.result.list[0].pub_id === app.globalData.pubInfo[i].pub_id) {
|
|
|
|
|
|
|
+ if (res.result.data.pub_id === app.globalData.pubInfo[i].pub_id) {
|
|
|
edit = true
|
|
edit = true
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
this.setData({
|
|
this.setData({
|
|
|
- activityInfo: res.result.list[0],
|
|
|
|
|
|
|
+ activityInfo: res.result.data,
|
|
|
|
|
+ like: res.result.data.favorite,
|
|
|
showEdit: edit
|
|
showEdit: edit
|
|
|
})
|
|
})
|
|
|
this.loadQuestionData()
|
|
this.loadQuestionData()
|
|
|
})
|
|
})
|
|
|
-
|
|
|
|
|
- // const db = wx.cloud.database()
|
|
|
|
|
- // const _ = db.command
|
|
|
|
|
- // db.collection('mainData').doc(options.id).get({
|
|
|
|
|
- // success: function (res) {
|
|
|
|
|
- // res.data.time = util.handleDate(res.data.time)
|
|
|
|
|
- // this.setData({
|
|
|
|
|
- // activityInfo: res.data
|
|
|
|
|
- // })
|
|
|
|
|
- // wx.hideLoading()
|
|
|
|
|
- // }.bind(this)
|
|
|
|
|
- // })
|
|
|
|
|
- // db.collection('qaData').where({
|
|
|
|
|
- // activityId: options.id,
|
|
|
|
|
- // answer: _.neq('')
|
|
|
|
|
- // }).get({
|
|
|
|
|
- // success: function (res) {
|
|
|
|
|
- // for (let i = 0; i < res.data.length; i++) {
|
|
|
|
|
- // if (res.data[i].answerTime !== '') {
|
|
|
|
|
- // res.data[i].time = util.handleDate(res.data[i].answerTime)
|
|
|
|
|
- // } else {
|
|
|
|
|
- // res.data[i].time = ''
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- // this.setData({
|
|
|
|
|
- // activityComment: res.data
|
|
|
|
|
- // })
|
|
|
|
|
- // }.bind(this)
|
|
|
|
|
- // })
|
|
|
|
|
- // db.collection('likeData').where({
|
|
|
|
|
- // type: 'message',
|
|
|
|
|
- // id: options.id
|
|
|
|
|
- // }).get({
|
|
|
|
|
- // success: function (res) {
|
|
|
|
|
- // this.setData({
|
|
|
|
|
- // like: res.data.length
|
|
|
|
|
- // })
|
|
|
|
|
- // }.bind(this)
|
|
|
|
|
- // })
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
/**
|