vue-微信支付or支付寶支付片段


 

 

<ulclass="way_list">
 <li v-if="!isWeixinBrowser"
  class="group alipay"
  @click="selete_payway=1">支付寶支付
  <i class="fr" :class="selete_payway? 'mCheck':'mCheckNo'"></i>
 </li>
 <li class="group wechat"
  @click="selete_payway=0">微信支付
  <i class="fr" :class="selete_payway? 'mCheckNo':'mCheck'"></i>
 </li>
</ul>
 

<!-- 支付寶支付必須 -->
<div class="goalipay_box" style="display:none" v-html="goalipayHtml"></div>
 
<div class="mFooter mBorderBox">
  <div class="mBtn_hole" @click="realPay()">確認支付</div>
</div>

 

data() {
  return {
    isloading:true,
    selete_payway:window.localStorage.DSQS_PAY_WAY == 0 ? 0 : 1,
    serve_item:false,
    showPay:false,//支付中間彈窗
    showNonet:false,//支付失敗
    'goalipayHtml':'',
    'allowClickStu':true,//允許點擊
  }

}, 
methods: {

    // 判斷是否完成支付流程
   is_pay(){
    // 完成彈出是否支付彈框
    if(this.$route.query.is_payed){
      this.showPay=true;
    }
   },
    //支付寶支付selete_payway:1  微信支付selete_payway:0
    realPay(){
      if(this.axiosData.createtime!=0){
        window.localStorage.DSQS_PAY_WAY=this.selete_payway;
        if(this.selete_payway==1){//支付寶
          this.goaliPay();
        }else{
          this.wxjsPay();
        }
      }else{
        this.$api.post( '/v1/Order/cancelOrder' , {'ordercode':this.$route.query.ordercode}, res => {
          if(res.code==0){
             that.$Glb.PlMessage(res.msg,800)
          }
        })
        return false;
      }
    }, 
    noPay(){//點擊未支付
       this.showPay=false;
      //  this.$Glb.PlMessage('支付失敗',800)
    },
    hasPay(){//點擊已支付
      this.showPay=false;
      // 點擊已支付查詢是否支付, 若支付跳轉,未支付停留於本頁面
      this.$api.post( '/v1/Order/queryOrder' , {'ordercode':this.$route.query.ordercode}, res => {
        if(res.code==1){
          if(res.data.pay_status=='success'){
            window.location.href=this.$route.query.success_url;
          }else{
            this.$Glb.PlMessage('未支付',800)
          }
        }
      });    
    },
    noNet(){
      this.showNonet=false;
    },
    // 處理重復點擊
    allowClick(ts){
        const that = this ;
        if(this.allowClickStu===true){
            this.allowClickStu = false;
             this.$Glb.PlMessage('正在加載中...',ts||10000,function(){
                that.$Glb.PlMessage('請求超時,請重試',800)
                that.allowClickStu = true
            });
            return true
        }
        if(this.allowClickStu === false){
            return false
        }
    },
    // 微信支付
    wxjsPay(){
        // 處理重復點擊
        if(!this.allowClick())return false;
        let that = this;
        if(window.navigator.userAgent.match(/micromessenger/i)){
            this.$api.post( 'https://xxxxxxxx/pay/wxjspay' , {'ordercode':this.$route.query.ordercode}, res => {
                if(res.code===2){
                    window.location.href=res.data.url
                }
                if(res.code===1){
                  // 成功
                }
                if(res.code===0){
                    alert(res.msg)
                }
            })
        }else{
         this.$api.post( 'https://xxxxxx/pay/gowxpay' , {'ordercode':this.$route.query.ordercode}, res => {
              if(res.code==1){
                this.axiosWxH5payData=res;
                window.location.href = res.data.url;//微信支付頁。
              }
            })           
        }
 



    },
    // 支付寶
    goaliPay(){
        // 處理重復點擊
        if(!this.allowClick())return false;
        this.$api.post( 'https://pay.xxxx.cn/pay/goalipay' , {'ordercode':this.$route.query.ordercode}, res => {
            this.goalipayHtml = res
            setTimeout(function(){
                window.document.forms['alipaysubmit'].submit();
            },50)
        })
    }
} 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM