加继续支付功能

2022-05-09 11:20:04 阅读:1 编辑
choosePay: {
            type: [{
                    name: '微信支付',
                    pic: "/zhy/resource/images/pay/wx.png",
                    id: 1,
                    hide: 0,
                },
                {
                    name: '余额支付',
                    pic: "/zhy/resource/images/pay/local.png",
                    id: 2,
                    hide: 0,
                }
            ],
            curr: 1,
            alert: false
        },
onLoad加代码
this.setIntegralSetting(() => {

        })
toPayReserveOrder() {
        this.toggleAlertPay();
    },
    changePayType(e) {
        let idx = e.currentTarget.dataset.index;

        //console.log(fee)
        if (idx == 2 && this.data.user.balance - this.data.info.order_amount < 0) {
            app.tips('余额不足!');
            return;
        } else {
            this.setData({
                ['choosePay.curr']: idx
            })
        }
    },
    toggleAlertPay() {

        this.setData({
            ['choosePay.alert']: !this.data.choosePay.alert
        })
    },
    onBuyMoneyTab(e) {
        let key = this.data.choosePay.curr - 0;
        if(key  == 2){
            this.onBalancePay(e);
        }else{
            this.onWxPay();
        }
    },
    onWxPay(){
        const _this = this;

        let param = {
          prepay_id: this.data.formId,
          order_id: this.data.order_id,
          pay_type: 1,
        }
        app.api.apiOfflinepingreserveorderGetwxparambyorderid(param).then(res => {
          this.wxpayAjax(res.data);
        }).catch(res => {
          app.tips(res);
        })
    },
    onBalancePay(e) {
        const _this = this;

        let param = {
          prepay_id: this.data.formId,
          order_id: this.data.order_id,
          pay_type: 2,
        }
        app.api.apiOfflinepingreserveorderGetwxparambyorderid(param).then(res => {
          wx.showLoading({
            title: '支付成功!',
          })

          app.timePass(1000).then(() => {
            wx.navigateBack({})
            wx.hideLoading();
          })
        }).catch(res => {
          app.tips(res);
        })
      },
    wxpayAjax(payStamp) {
        let data = payStamp;
        let _this = this;
        wx.requestPayment({
            appId: data.appId,
            nonceStr: data.nonceStr,
            package: data.package,
            paySign: data.paySign,
            prepay_id: data.prepay_id,
            signType: data.signType,
            timeStamp: data.timeStamp,
            success: function (res) {
                _this.setData({
                    ['choosePay.alert']: false
                })
                _this.setData({
                    ajax: false,
                })
              /*   app.timePass(100).then(() => {
                    app.reTo("/plugin/offlineping/orderinfo/orderinfo?order_id=" + _this.data.order_id);
                }) */
                wx.navigateBack({})

            },
            fail: () => {

            }
        })
    },
 <van-popup-gray show="{{choosePay.alert}}" position="bottom" bind:click-overlay="toggleAlertPay">
    <view class='choicepayTit'>请选择支付方式</view>
    <view class='webChat' wx:for="{{choosePay.type}}" wx:key="choose" bindtap='changePayType' data-index="{{item.id}}" wx:if="{{!item.hide}}">
      <image src='{{item.pic}}' class='payIcon'></image>
      <view>{{item.id == 2 ? integraSetting.recharge.name+'支付' : item.name}}</view>
      <view>{{item.id == 2? integraSetting.recharge.name+':' + user.balance : ''}}</view>
      <image src='/zhy/resource/images/pay/right.png' class='iconRight' wx:if="{{choosePay.curr == item.id}}"></image>
    </view>
    <view class="pay-footer">
      <button bindtap="onBuyMoneyTab">确定支付</button>
    </view>
    <!-- <view style="height: 100rpx;"></view> -->
  </van-popup-gray>
"usingComponents": {
    "van-popup-gray": "/zhy/vant/popup-gray/index"
  }