文件
mashangyoujiu/Public/vip/js/onlinepay.js

196 行
7.6 KiB
JavaScript
可执行文件

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

var app = new Vue({
el: '#app',
data: function () {
return {
user_type: user_type,//用户类型 1普通会员 2plus会员
user: user,//会员信息
recharge_id: '',//充值活动id
trade_amount: '',//自定义充值金额
canInput: canInput,//是否可以自定义充值
auto_read_recharge_grade: auto_read_recharge_grade,//自定义充值是否赠送优惠
rechargeList: rechargeList,
plusRechargeList: plusRechargeList,
showMobile: false,//是否显示完整的手机号
btnDisabled: false,
out_trade_no: '',
showDetails: false, //是否显示模态框
showDetailsData: {}, //模态框数据
}
},
methods: {
//点击套餐
checkItem: function (id, money,item) {
if (this.recharge_id == id) {
this.recharge_id = '';
this.recharge_money = '';
} else {
this.trade_amount = '';
this.recharge_id = id;
this.recharge_money = money;
this.showDetailsData = item;
this.showDetails = true;
}
},
//确认充值
submit: function () {
if (!this.trade_amount && !this.recharge_id) {
this.$message({
message: '请选择充值套餐或定义充值金额',
type: 'warning'
});
return;
}
this.btnDisabled = true;
this.$loading({
lock: true,
text: '下单中...',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.4)',
customClass: 'el-loading-custom-class'
});
var that = this;
var trade_amount;
if (!this.trade_amount) {
trade_amount = this.recharge_money;
} else {
trade_amount = this.trade_amount;
}
that.sendRequest({
url: "/index.php/Pay/VipPay/submitRechargeOrder",
data: {
store_id: that.user.store_id,
merchant_id: that.user.merchant_id,
trade_amount: trade_amount,
recharge_id: that.recharge_id,
vid: that.user.vid,
},
success: function (res) {
that.$loading().close();
if (res.status == 1) {
//创建订单成功
that.out_trade_no = res.out_trade_no;
that.toWxPay(res.data);
} else {
that.btnDisabled = false;
that.$message({
message: res.msg,
type: 'error',
duration: 3000,
});
}
}
});
},
// 关闭
detailsClose() {
this.showDetails = false;
},
//调起微信支付
toWxPay: function (data) {
var that = this;
wx.chooseWXPay({
timestamp: data.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
nonceStr: data.nonceStr, // 支付签名随机串,不长于 32 位
package: data.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
signType: data.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
paySign: data.paySign, // 支付签名
success: function (result) {
// 支付成功后的回调函数
if (result.errMsg == 'chooseWXPay:ok') {
//支付成功
that.$loading({
lock: true,
text: '查询中...',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.4)',
customClass: 'el-loading-custom-class'
});
that.searchOrder(0);
} else {
that.btnDisabled = false;
}
},
fail: function (res) {
that.$loading().close();
that.btnDisabled = false;
that.$message({
message: res.errMsg ? res.errMsg : '微信支付调起失败',
type: 'warning'
})
},
cancel: function (res) {
//用户点击取消时的回调函数,仅部分有用户取消操作的api才会用到。
that.btnDisabled = false;
}
});
},
//查询订单支付状态
searchOrder: function (count) {
var that = this;
count++;
if (count > 10) {
that.btnDisabled = false;
that.$loading().close();
that.$message({
message: '充值查询失败,请稍后刷新重试',
type: 'error',
});
return;
}
that.sendRequest({
url: "/index.php/Pay/VipPay/searchWxOnlinePay",
data: {
out_trade_no: that.out_trade_no,
},
success: function (res) {
if (res.status == 1) {
that.$loading().close();
that.btnDisabled = false;
that.$message({
message: res.msg ? res.msg : '充值成功',
type: 'success',
duration: 1000,
onClose: function () {
localStorage.onlinepay = 1;
window.history.go(-1);
}
});
} else {
setTimeout(function () {
that.searchOrder(count);
}, 1000)
}
}
})
},
//封装的请求方法
sendRequest: function (options) {
$.ajax({
url: options.url,
data: options.data,
type: 'post',
success: function (res) {
options.success(res);
},
error: function () {
var res = {
status: 0,
msg: '请求发生错误',
};
options.success(res);
}
})
}
},
watch: {
trade_amount: function (n, o) {
var reg = /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d{0,2})$/;
if ((reg.test(n) == false || n < 0) && n != '') {
this.trade_amount = o;
}
if (this.trade_amount) {
this.recharge_id = '';
}
}
}
});