|
@@ -8,10 +8,10 @@ Page({
|
|
|
data: {
|
|
data: {
|
|
|
publisherId: '',
|
|
publisherId: '',
|
|
|
publisherInfo: {},
|
|
publisherInfo: {},
|
|
|
- pageToken: 0,
|
|
|
|
|
- mainDatas: [],
|
|
|
|
|
like: false,
|
|
like: false,
|
|
|
- likeEnable: true
|
|
|
|
|
|
|
+ likeDisabled: true,
|
|
|
|
|
+ pageToken: 0,
|
|
|
|
|
+ mainDatas: []
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
detail: function () {
|
|
detail: function () {
|
|
@@ -25,86 +25,73 @@ Page({
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
loadExtraData: function () {
|
|
loadExtraData: function () {
|
|
|
- wx.showLoading({
|
|
|
|
|
- title: '加载中'
|
|
|
|
|
- })
|
|
|
|
|
- wx.cloud.callFunction({
|
|
|
|
|
|
|
+ wx.showNavigationBarLoading()
|
|
|
|
|
+ const arr = []
|
|
|
|
|
+ arr.push(wx.cloud.callFunction({
|
|
|
name: 'listMessages',
|
|
name: 'listMessages',
|
|
|
data: {
|
|
data: {
|
|
|
pub_id: this.data.publisherId,
|
|
pub_id: this.data.publisherId,
|
|
|
page_token: this.data.pageToken,
|
|
page_token: this.data.pageToken,
|
|
|
- page_size: 25
|
|
|
|
|
|
|
+ page_size: 20
|
|
|
}
|
|
}
|
|
|
- }).then(res => {
|
|
|
|
|
- wx.hideLoading()
|
|
|
|
|
- if (res.result.status !== 'OK') {
|
|
|
|
|
|
|
+ }))
|
|
|
|
|
+ arr.push(wx.cloud.callFunction({
|
|
|
|
|
+ name: 'getFollow',
|
|
|
|
|
+ data: {
|
|
|
|
|
+ pub_id: this.data.publisherId
|
|
|
|
|
+ }
|
|
|
|
|
+ }))
|
|
|
|
|
+ Promise.all(arr).then(res => {
|
|
|
|
|
+ wx.hideNavigationBarLoading()
|
|
|
|
|
+ if (res[0].result.status !== 'OK' || res[1].result.status !== 'OK') {
|
|
|
wx.showToast({
|
|
wx.showToast({
|
|
|
- title: res.result.errMsg,
|
|
|
|
|
|
|
+ title: res[0].result.errMsg || res[1].result.errMsg,
|
|
|
icon: 'none'
|
|
icon: 'none'
|
|
|
})
|
|
})
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- for (let i = 0; i < res.result.list.length; i++) {
|
|
|
|
|
- res.result.list[i] = util.dbToMsg(res.result.list[i])
|
|
|
|
|
- res.result.list[i].publisher = this.data.publisherInfo
|
|
|
|
|
|
|
+ for (let i = 0; i < res[0].result.list.length; i++) {
|
|
|
|
|
+ res[0].result.list[i] = util.dbToMsg(res[0].result.list[i])
|
|
|
|
|
+ res[0].result.list[i].publisher = this.data.publisherInfo
|
|
|
}
|
|
}
|
|
|
this.setData({
|
|
this.setData({
|
|
|
- mainDatas: this.data.mainDatas.concat(res.result.list),
|
|
|
|
|
- pageToken: res.result.next_page_token
|
|
|
|
|
|
|
+ mainDatas: this.data.mainDatas.concat(res[0].result.list),
|
|
|
|
|
+ pageToken: res[0].result.next_page_token,
|
|
|
|
|
+ like: res[1].result.total === 1,
|
|
|
|
|
+ likeDisabled: false
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
toggleLike: function () {
|
|
toggleLike: function () {
|
|
|
- if (!this.data.likeEnable) return
|
|
|
|
|
- this.setData({
|
|
|
|
|
- likeEnable: false
|
|
|
|
|
|
|
+ if (this.data.likeDisabled) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ wx.showLoading({
|
|
|
|
|
+ title: this.data.like ? '取消关注' : '关注中'
|
|
|
})
|
|
})
|
|
|
- const db = wx.cloud.database()
|
|
|
|
|
- if (this.data.like == 0) {
|
|
|
|
|
- db.collection("likeData").add({
|
|
|
|
|
- data: {
|
|
|
|
|
- type: "publisher",
|
|
|
|
|
- id: this.data.publisherInfo._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 ? 'deleteFollow' : 'createFollow',
|
|
|
|
|
+ data: {
|
|
|
|
|
+ pub_id: this.data.publisherId
|
|
|
|
|
+ }
|
|
|
|
|
+ }).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: "publisher",
|
|
|
|
|
- id: this.data.publisherInfo._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
|
|
|
})
|
|
})
|
|
|
- }
|
|
|
|
|
|
|
+ })
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
/**
|