wangxin 6 years ago
parent
commit
539417bb06
6 changed files with 29 additions and 23 deletions
  1. 0 8
      app.js
  2. 21 7
      template/carts/index.js
  3. 1 1
      template/cash/index.js
  4. 3 5
      template/pay/index.js
  5. 1 1
      template/poster/index.js
  6. 3 1
      template/view/index.js

+ 0 - 8
app.js

@@ -152,14 +152,6 @@ App({
     wx.hideLoading();
   },
 
-  /**
-   * 海报分享,路径附带的参数 encodeURIComponent(uid,product_id)
-   */
-  getSceneArray: function(scene){
-    let str = decodeURIComponent(scene);
-    return str.split(',');//[0] = uid [1] = product_id
-  },
-
   /**
    * http请求
    * url 请求路径 

+ 21 - 7
template/carts/index.js

@@ -133,13 +133,27 @@ Page({
       invite_uid: app.getInviteUid()
     },{
       success:function(data, res){
-        app.saveInviteUid('');
-        var id = that.product_ids;
-        let idx = ids.indexOf(',');
-        if (idx > -1) {
-          id = id.substring(0, idx);
-        }
-        app.redirect('pay/index?id='+id);
+        var pay = data.pay;
+        wx.requestPayment({
+          timeStamp: pay.time,
+          nonceStr: pay.nonce_str,
+          package: pay.prepay_id,
+          signType: pay.sign_type,
+          paySign: pay.sign,
+          success: function(){//微信支付成功
+            app.saveInviteUid('');
+            var id = that.product_ids;
+            let idx = id.indexOf(',');
+            if (idx > -1) {
+              id = id.substring(0, idx);
+            }
+            //跳转支付结果页
+            app.redirect('pay/index?id=' + id);
+          },
+          fail: function(){//微信支付失败
+            app.toast('支付失败!');
+          }
+        })
       },
       fail: function(res){
         app.toast('支付失败!');

+ 1 - 1
template/cash/index.js

@@ -65,7 +65,7 @@ Page({
       success:function(data, res){
         app.saveInviteUid('');
         var id = that.product_ids;
-        let idx = ids.indexOf(',');
+        let idx = id.indexOf(',');
         if (idx > -1) {
           id = id.substring(0, idx);
         }

+ 3 - 5
template/pay/index.js

@@ -1,17 +1,15 @@
 const app = getApp();
 Page({
-  data: {
-    
-  },
+  pid: '',
 
   onLoad: function (options) {
-    //invite_uid
+    this.pid = options.id;
   },
 
   /**
    * 跳转海报分享页面,分享海报
    */
   toShare: function(){
-    app.redirect('poster/index');
+    app.redirect('poster/index?id=' + this.pid);
   }
 })

+ 1 - 1
template/poster/index.js

@@ -53,7 +53,7 @@ Page({
     return {
       title: '',
       desc: '',
-      path: '/template/home/index?scene=' + encodeURIComponent(scene)
+      path: '/template/view/index?scene=' + encodeURIComponent(scene)
     };
 
   }

+ 3 - 1
template/view/index.js

@@ -9,7 +9,9 @@ Page({
     if (typeof options.scene == 'undefined') {//来源首页商品浏览
       this.pid = options.id;
     } else {//来源于分享
-      let arr = app.getSceneArray(options.scene);
+      //海报分享,路径附带的参数 encodeURIComponent(uid, product_id)
+      let str = decodeURIComponent(options.scene);
+      let arr = str.split(',');
       let uid = arr[0];
       this.pid = arr[1];
       app.saveInviteUid(uid);