zjh 5 anos atrás
pai
commit
f06c4a6ce3
2 arquivos alterados com 38 adições e 21 exclusões
  1. 28 16
      pages/item/item.js
  2. 10 5
      utils/api.js

+ 28 - 16
pages/item/item.js

@@ -378,29 +378,41 @@ Page({
   },
   postfollow:function(){
     var that = this;
-
     var data={
       plateId: this.data.object.plateId,
       plateName: this.data.object.Name,
       userId: wx.getStorageSync('openid'),
       userName: app.globalData.userInfo.nickName,
     }
-  
     var postfollow = wxRequest.postRequest(Api.postfollow(),data);
-    postfollow.then((res)=>{
-   
-      if(res.statusCode==200){
-        that.setData({
-          follow:res.data.data==1? "已关注":"关注"
-         })
-        wx.showToast({
-          title: res.data.message,
-          icon: 'success',
-          duration: 2000
-        })
-      }
-      
-    })
+    var postfollowcancel=wxRequest.postRequest(Api.postfollowcancel(),data);
+    if(this.data.follow=="关注"){
+      postfollow.then((res)=>{
+        if(res.statusCode==200){
+          that.setData({
+            follow:res.data.data==1? "已关注":"关注"
+           })
+          wx.showToast({
+            title: res.data.message,
+            icon: 'success',
+            duration: 2000
+          })
+        }
+      })
+    }else{
+      postfollowcancel.then((res)=>{
+        if(res.statusCode==200){
+          that.setData({
+            follow:res.data.data==1? "关注":"已关注"
+           })
+          wx.showToast({
+            title: res.data.message,
+            icon: 'success',
+            duration: 2000
+          })
+        }
+      })
+    }
   },
     //获取数据
     posthisfind:function(row){

+ 10 - 5
utils/api.js

@@ -46,9 +46,14 @@ module.exports = {
       var url =HOST_URI + '/api/user/openId';
       return url;
     },
-        // 关注接口
-        postfollow: function (obj) {
-          var url =HOST_URI + '/api/follow';
-          return url;
-        },
+  // 关注接口
+  postfollow: function (obj) {
+    var url =HOST_URI + '/api/follow';
+    return url;
+  },
+    // 取消关注接口
+    postfollowcancel: function (obj) {
+      var url =HOST_URI + '/api/follow/cancel';
+      return url;
+    },
 }