| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- Component({
- options: {
- styleIsolation: "apply-shared"
- },
- properties: {
- item: Object
- },
- data: {
- like: 1,
- likeEnable: true
- },
- methods: {
- getPublisherInfo: function () {
- wx.navigateTo({
- url: "/pages/publisher/publisher?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: "publisher",
- 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: "publisher",
- 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"
- })
- }
- })
- }
- }
- }
- })
|