Browse Source

app微信支付

shish 2 years ago
parent
commit
31fe3414ee
1 changed files with 61 additions and 19 deletions
  1. 61 19
      hdApp/src/pagesPurchase/wechatPay.vue

+ 61 - 19
hdApp/src/pagesPurchase/wechatPay.vue

@@ -22,24 +22,27 @@
           <div v-else class="order-num app-color-3" style="margin-top:12upx;font-size:26upx;">订单已失效</div>
         </block>
         <block>
-<!-- #ifdef MP-WEIXIN -->
-          <div class="call-one-btn">
-            <view v-if="Number(balance) >= Number(realPrice)">
-              <button v-if="getPayType == 1" class="button-com pay-wx" :class="[remainPayTime >0 ? 'green':'default']" :disabled="remainPayTime >0 ? false : true" @click="wxPayFn">微信支付</button>
-              <button v-else class="button-com pay-wx" :class="[remainPayTime >0 ? 'green':'default']" :disabled="remainPayTime >0 ? false : true" @click="wxPayFnOld">微信支付</button>
-            </view>
-            <view v-else>
-              <button v-if="getPayType == 1" class="button-com pay-wx" :class="[remainPayTime >0 ? 'green':'default']" :disabled="remainPayTime >0 ? false : true" @click="wxPayFn">微信支付</button>
-              <button v-else class="button-com pay-wx" :class="[remainPayTime >0 ? 'green':'default']" :disabled="remainPayTime >0 ? false : true" @click="wxPayFnOld">微信支付</button>
-            </view>
-            <button class="button-com pay-wx" :class="[remainPayTime >0 ? 'green':'default']" :disabled="remainPayTime >0 ? false : true" @click="debtPay" v-if="hasDebtPay === '1'">赊账</button>
-          </div>
-<!-- #endif -->
-<!-- #ifdef APP-PLUS -->
-          <div class="call-one-btn">
-            <button class="button-com pay-wx green" @click="debtPay">赊账</button>
-          </div>
-<!-- #endif -->
+        <!-- #ifdef MP-WEIXIN -->
+        <div class="call-one-btn">
+          <view v-if="Number(balance) >= Number(realPrice)">
+            <button v-if="getPayType == 1" class="button-com pay-wx" :class="[remainPayTime >0 ? 'green':'default']" :disabled="remainPayTime >0 ? false : true" @click="wxPayFn">微信支付</button>
+            <button v-else class="button-com pay-wx" :class="[remainPayTime >0 ? 'green':'default']" :disabled="remainPayTime >0 ? false : true" @click="wxPayFnOld">微信支付</button>
+          </view>
+          <view v-else>
+            <button v-if="getPayType == 1" class="button-com pay-wx" :class="[remainPayTime >0 ? 'green':'default']" :disabled="remainPayTime >0 ? false : true" @click="wxPayFn">微信支付</button>
+            <button v-else class="button-com pay-wx" :class="[remainPayTime >0 ? 'green':'default']" :disabled="remainPayTime >0 ? false : true" @click="wxPayFnOld">微信支付</button>
+          </view>
+          <button class="button-com pay-wx" :class="[remainPayTime >0 ? 'green':'default']" :disabled="remainPayTime >0 ? false : true" @click="debtPay" v-if="hasDebtPay === '1'">赊账</button>
+        </div>
+        <!-- #endif -->
+        <!-- #ifdef APP-PLUS -->
+        <div class="call-one-btn">
+          <view>
+            <button class="button-com pay-wx" :class="[remainPayTime >0 ? 'green':'default']" :disabled="remainPayTime >0 ? false : true" @click="appWxPayFn">微信支付</button>
+          </view>
+          <button class="button-com pay-wx green" @click="debtPay">赊账</button>
+        </div>
+        <!-- #endif -->
 
         </block>
       </div>
@@ -90,7 +93,8 @@ export default {
     this.id = options.id
   },
   computed: {
-    ...mapGetters(["getLoginInfo", 'getDictionariesInfo']),
+    ...mapGetters(["getLoginInfo"]),
+    ...mapGetters({ dictInfo:"getDictionariesInfo" }),
   },
   mounted () {
   },
@@ -137,6 +141,44 @@ export default {
         })
       })      
     },
+    appWxPayFn(){
+        let that = this
+        // #ifdef APP-PLUS
+        let id = this.option.id ? this.option.id : 0
+        let realPrice = this.option.realPrice ? this.option.realPrice : 0
+        let orderSn = this.option.orderSn ? this.option.orderSn : ''
+        if(plus.runtime.isApplicationExist({pname:'com.tencent.mm',action:'weixin://'})){
+          plus.share.getServices(function(s){
+            var sweixin
+            for (var i = 0; i < s.length; i++) {
+              var t = s[i];
+              if (t.id == 'weixin') {
+                  sweixin = t;
+              }
+            }
+            let miniOriginalId = that.dictInfo.miniOriginalId && that.dictInfo.miniOriginalId.current && that.dictInfo.miniOriginalId.current.hd ? that.dictInfo.miniOriginalId.current.hd : ''
+            if (sweixin && sweixin.nativeClient) {
+              sweixin.launchMiniProgram({
+                id: miniOriginalId,
+                path: '/pagesPurchase/wechatPay?id='+id+'&realPrice='+realPrice+'&orderSn='+orderSn,
+                type: 0
+              });
+            } else {
+              that.$msg("没有找到微信服务")
+              //that.$msg("获取微信失败:" + e.message)
+              //console.log(JSON.stringify(e));
+            }
+          }, function(e){
+              that.$msg("没有找到微信服务哦")
+              //that.$msg("获取微信失败:" + e.message)
+              //console.log(JSON.stringify(e));
+          });
+        } else {
+          that.$msg("请安装微信,再打开小程序")
+          return false
+        }
+        // #endif
+    },
     wxPayFn () {
       let that = this