var app = getApp();
var appEv = app.$vm.$options;

class ToPayOpre {
    // 支付
    toPay(info = appEv.parameter("info"), callback) {
        var that = this;
		console.log('info',info)
        uni.requestPayment({
            ...info,
            success: function (res) {
                that.payReturn(false, callback);
            },
            fail: function (res) {
				console.log(res,"报错信息")
                that.payReturn(true, callback);
            }
        })
    }
    payReturn(isFail, callback) {
        uni.hideLoading();
        // 支付失败
        if (isFail) {
            appEv.errTips('支付失败', 3000);
        } else {
            // 支付成功
            uni.showToast({
                title: '支付成功',
                icon: 'success',
                duration: 1200,
                mask: true
            })
        }
        
        // 跳转订单列表
        setTimeout(function () {
            if (callback) {
                callback(isFail);
            } else {
                uni.redirectTo({
                    url: '/pages/chengbei-order-list/index'
                })
            }
        }, 1200);
    }
}

export {
    ToPayOpre
}