| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- Component({
- options: {
- styleIsolation: "apply-shared"
- },
- properties: {
- item: Object
- },
- data: {
- like: 1,
- likeEnable: true
- },
- methods: {
- getActivityInfo: function () {
- wx.navigateTo({
- url: "/pages/activity/activity?id=" + this.properties.item.id
- })
- },
- toggleLike: function () {
- 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.properties.item.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.properties.item.id
- }).remove({
- success: function() {
- this.setData({
- like: 0,
- likeEnable: true
- })
- wx.showToast({
- title: "已取消收藏",
- })
- }.bind(this),
- fail: function() {
- wx.showToast({
- title: "网络错误",
- icon: "none"
- })
- }
- })
- }
- }
- }
- })
|