pay.js 2.95 KB
import WxConfig from '@u/WxConfig'
import {commodity} from "@r/api";
const WX = new WxConfig(['chooseWXPay']);
// import { commodity } from '@r/api.js'
export default {
    data() {
        return {
        }
    },
    mounted() {
    },
    methods: {
        async chooseWXPay() {
            if(this.appearance == 2 && !/^[a-zA-Z0-9]+$/.test(this.rechargeNumber)){
                this.showToast('请输入正确的充值账号')
                return
            }
            this.orderPay();
            // let message;
            // if(this.appearance === 1) {
            //     message = `是否确认为${this.mobile}进行充值`
            // }
            // this.dialog({
            //     title: '提示',
            //     message: message,
            // })
            // .then(() => {
            //     WX.chooseWXPay().then(res => {
            //         console.log(res)
            //     })
            // })
            // .catch(() => {
            //     this.showToast('取消成功')
            // });

        },
        async orderPay() {
            this.showLoading();
            let {sessionId} = JSON.parse(sessionStorage.getItem('GL_EQUITY_USER_INFO'));
            let orderCode =  await commodity.getOrderCode({
                sessionId,
                supplier: this.supplier,
                brandId: this.brandId
            }).then(res => {
                let { code, data, message } = res
                if (code == 0) {
                    return data;
                } else {
                    this.showToast(message)
                }
            })
            let para = {
                orderCode,
                goodsId: this.selectData?this.selectData.id:this.denomination.id,
                goodsQuality: 1,
                rechargeNumber: this.rechargeNumber,
                payMannerId: 11,
                sessionId,
            }
            let payData = await commodity.payOrder(para).then(res => {
                this.hideLoading()
                let { code, data, message } = res
                if (code == 0) {
                    return data;
                } else {
                    this.showToast(message)
                }
            })
            const { timeStamp,nonceStr, packages, signType, paySign } = payData;
            WX.chooseWXPay(timeStamp,nonceStr, packages, signType, paySign).then(res => {
                console.log(res)
                if(this.appearance == 2){
                    let productName = this.businessList[this.typeSno].productName + this.denomination.denomination
                    window.vm.$router.replace({ name: 'cardRoll.process',query: {
                            rechargeNumber: this.rechargeNumber,
                            productName
                        }
                    })
                }else {
                    window.vm.$router.replace({ name: 'cardRoll.success',query:{price: this.denomination.salesPrice} })
                }
            })
        }
    },

}