Selaa lähdekoodia

fix:用户绑定接口放到登录回调

zhanghui 2 vuotta sitten
vanhempi
sitoutus
6e8ab4c0db
2 muutettua tiedostoa jossa 79 lisäystä ja 84 poistoa
  1. 49 15
      App.vue
  2. 30 69
      pages/index/index.vue

+ 49 - 15
App.vue

@@ -3,28 +3,62 @@
     @import "uview-ui/index.scss";
 </style>
 <script>
-	export default {
-		onLaunch: function() {
+    export default {
+        onLaunch: function () {
             let that = this;
             wx.login({
                 success(re) {
-                    that.$api.wxLogin({code:re.code}).then(res=>{
-                        uni.setStorageSync('userInfo',res.data.data.userInfo)
-                        uni.setStorageSync('accessToken',res.data.data.access_token)
+                    that.$api.wxLogin({code: re.code}).then(res => {
+                        console.log('++++++++++登录返回了++++++++++++++++', res)
+                        uni.setStorageSync('userInfo', res.data.data.userInfo)
+                        uni.setStorageSync('accessToken', res.data.data.access_token)
                         uni.removeStorageSync('parent_member_id');
-                    })
 
+
+                        //用户分享用户绑定
+                        let shareUserId = uni.getStorageSync('shareUserId')
+                        if (shareUserId) {
+                            that.$api.scanCode({
+                                openId: res.data.data.userInfo.otherId,
+                                memberId: shareUserId
+                            }).then(res => {
+                                console.log('用户分享用户绑定成功', res)
+                                uni.removeStorageSync('shareUserId');
+                            })
+                        }
+
+
+                        //拓客端或者技师端扫码用户绑定
+                        let expandParam = uni.getStorageSync('expandParam')
+                        if (expandParam) {
+                            //用户扫码拓客端进入小程序
+                            that.$api.userBindMember(
+                                {
+                                    ...expandParam,
+                                    memberId: res.data.data.userInfo.id
+                                }
+                            ).then(res1 => {
+                                console.log('拓客端推广用户绑定成功!')
+                                uni.removeStorageSync('expandParam');
+                            })
+                        }
+
+                        //用户扫码技师端进入小程序 暂无操作
+                        let promotionParam = uni.getStorageSync('promotionParam')
+
+
+                    })
                 },
             })
-			console.log('App Launch')
-		},
-		onShow: function() {
-			console.log('App Show')
-		},
-		onHide: function() {
-			console.log('App Hide')
-		}
-	}
+            console.log('App Launch')
+        },
+        onShow: function () {
+            console.log('App Show')
+        },
+        onHide: function () {
+            console.log('App Hide')
+        }
+    }
 </script>
 
 

+ 30 - 69
pages/index/index.vue

@@ -279,11 +279,11 @@ export default {
 
     if (e.shareUserId){
       //用户点击分享到好友或者朋友圈传递过来的参数
-      console.log('shareUserId===============>',e.shareUserId)
-      setTimeout(()=>{
-        this.userInfo = uni.getStorageSync('userInfo');
-        this.scanCode(this.userInfo.otherId,e.shareUserId);
-      },5000)
+      uni.setStorageSync('shareUserId',e.shareUserId)
+    }
+    if (e.scene){
+      //用户扫用户的会员吗进入小程序
+      uni.setStorageSync('shareUserId',e.scene)
     }
 
     if(e.q){
@@ -296,41 +296,14 @@ export default {
         param[b[i].split('=')[0]] = b[i].split('=')[1]
       }
       if (param.expandUserId){ //从拓客端进来的用户
-        setTimeout(()=>{
-          this.userBindMember({
-            ...param,
-            memberId:this.userInfo.id
-          })
-        },5000)
+        uni.setStorageSync('expandParam',param)
       }else { //从技师端进来的用户
         uni.setStorageSync('promotionParam',param)
-
       }
-      console.log('param==============>',param)
-      console.log('++++++++++param.expandUserId+++++++++++',param.expandUserId)
-    }
 
-    // uni.hideTabBar({
-    //   animation: false
-    // })
-
-    if (e.scene){
-      let scene = e.scene
-      setTimeout(()=>{
-        this.userInfo = uni.getStorageSync('userInfo');
-        this.scanCode(this.userInfo.otherId,scene);
-      },5000)
     }
 
-    // 获取经纬度信息
-    // uni.getLocation({
-    //   success: (e) => {
-    //     console.log('++++++++++getLocation++success+++++++++++',e.longitude,e.latitude)
-    //   },
-    //   fail:(err) =>{
-    //     console.log('++++++++++getLocation++fail+++++++++++',err)
-    //   }
-    // })
+    this.getLocation();
 
     //公告信息
     this.getNoticeListData();
@@ -391,25 +364,6 @@ export default {
 
   methods: {
 
-    userBindMember(param){
-      console.log('绑定开始param=>', param)
-      this.$api.userBindMember(param).then(res=>{
-        console.log('用户绑定成功',res)
-      })
-    },
-
-    scanCode(otherId,memberId){
-      console.log('绑定开始memberId=>'+memberId)
-        this.$api.scanCode({
-          openId:otherId,
-          memberId:memberId
-        }).then(res=>{
-          console.log('用户绑定成功',res)
-          console.log('绑定结束memberId=>'+memberId)
-        })
-    },
-
-
     goQrCode(){
       uni.navigateTo({
         url: '/pages/qrCode/index'
@@ -513,22 +467,29 @@ export default {
 
     },
     // 获取经纬度信息
-    // getLocation() {
-    //
-    //   uni.getLocation({
-    //     type: 'gcj02',
-    //     success: function (res) {
-    //       var latitude = res.latitude; // 纬度
-    //       var longitude = res.longitude; // 经度
-    //       var speed = res.speed; // 速度
-    //       var accuracy = res.accuracy; // 精确度
-    //       // 在这里可以对位置信息进行处理
-    //       console.log("纬度:" + latitude + ";经度" + longitude)
-    //       this.reqParm.latitude = latitude
-    //       this.reqParm.longitude = longitude
-    //     }
-    //   });
-    // },
+    getLocation() {
+
+      uni.getLocation({
+        type: 'gcj02',
+        success: function (res) {
+          console.log(res)
+          let latitude = res.latitude; // 纬度
+          let longitude = res.longitude; // 经度
+          let speed = res.speed; // 速度
+          let accuracy = res.accuracy; // 精确度
+          // 在这里可以对位置信息进行处理
+          console.log("纬度:" + latitude + ";经度" + longitude)
+          this.reqParm.latitude = latitude
+          this.reqParm.longitude = longitude
+        },
+        fail:function (fail) {
+          console.log('获取用户地址失败==》',fail)
+        },
+        complete:function () {
+
+        }
+      });
+    },
 
     // 去选择门店
     gotoStoreChoose() {