Browse Source

立即兑换、立即购买按钮,添加授权获取用户信息

wangxin 6 years ago
parent
commit
42f234ac9c

+ 2 - 1
components/cashdialog/index.js

@@ -36,7 +36,8 @@ Component({
     //展示弹框
     showDialog() {
       this.setData({
-        isShow: !this.data.isShow
+        isShow: !this.data.isShow,
+        cashCode: ''
       })
     },
     cashCodeInput(e){

+ 1 - 1
components/cashdialog/index.wxml

@@ -1,7 +1,7 @@
 <view class='dialog-container' hidden="{{!isShow}}">
     <view class='dialog-mask' bindtap='hideDialog'></view>
     <view class='dialog-info'>
-        <input class='dialog-content' placeholder-class='dialog-hint' placeholder='输入兑换码' type='text' bindinput ="cashCodeInput"></input>
+        <input class='dialog-content' placeholder-class='dialog-hint' placeholder='输入兑换码' type='text' bindinput ="cashCodeInput" value='{{cashCode}}'></input>
         <view class='dialog-errmsg'>{{errMsg}}</view>
         <button class='dialog-footer' catchtap='confirmEvent'>{{confirmText}}</button>
     </view>

+ 1 - 0
template/carts/index.js

@@ -99,6 +99,7 @@ Page({
     var list = this.data.list;
     var count=0;
     this.product_ids = '';
+    this.product_num = '';
     for(var i=0; i<list.length; i++){
       var product_id = list[i].product_id;
       var pay_price = list[i].product.pay_price;

+ 20 - 3
template/home/index.js

@@ -77,14 +77,25 @@ Page({
     app.location('view/index?id=' + id);
   },
 
+  /**
+    * 微信授权回调, 用于礼品卡兑换按钮
+    */
+  bindGetUserInfo: function (e) {
+    if (e.detail.userInfo) {
+      this.cash();
+    } else {
+      //TODO 用户拒绝了授权
+    }
+  },
+
   /**
    * 礼品卡兑换
    */
-  cash: function(e){
-    if(app.isLogin()){
+  cash: function(){
+    if (app.isLogin()) {
       this.cashdialog.setErrMsg('');
       this.cashdialog.showDialog();
-    }else{
+    } else {
       app.location('login/index');
     }
   },
@@ -142,6 +153,12 @@ Page({
         console.log('wx.showShareMenu fail', res.data);
       }
     })
+
+    return {
+      title: '',
+      desc: '',
+      path: '/template/home/index'
+    }
   }
 
 })

+ 1 - 1
template/home/index.wxml

@@ -11,7 +11,7 @@
     </view>
     <view class='cash'>
       <button class='nxh__button nxh__button3' open-type="contact">在线客服</button>
-      <button class='nxh__button nxh__button3' bindtap='cash'>礼品卡兑换</button>
+      <button class='nxh__button nxh__button3' open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo" lang="zh_CN">礼品卡兑换</button>
     </view>
 </view>
 

+ 11 - 0
template/view/index.js

@@ -27,6 +27,17 @@ Page({
     }
   },
 
+  /**
+     * 微信授权回调
+     */
+  bindGetUserInfo: function (e) {
+    if (e.detail.userInfo) {
+      this.doBuy();
+    } else {
+      //TODO 用户拒绝了授权
+    }
+  },
+
   /**
    * 立即购买
    */

+ 1 - 1
template/view/index.wxml

@@ -7,5 +7,5 @@
 </view>
 <view class='bottom'>
   <button class='nxh__button' bindtap='toShare'>分享给好友</button>
-  <button class='nxh__button' bindtap='doBuy'>立即购买</button>
+  <button class='nxh__button' open-type="getUserInfo" lang="zh_CN" bindgetuserinfo="bindGetUserInfo">立即购买</button>
 </view>