|
@@ -93,6 +93,15 @@ Page({
|
|
|
|
|
|
// 立即缴费
|
|
|
payNow: function() {
|
|
|
+ if (this.data.amount <= 0) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '请输入缴费金额',
|
|
|
+ icon: 'none',
|
|
|
+ duration: 2000
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
wx.showLoading({
|
|
|
title: '处理中',
|
|
|
});
|
|
@@ -111,28 +120,40 @@ Page({
|
|
|
dskey: app.globalData.currentAccountInfo.dsKey
|
|
|
},
|
|
|
success: res => {
|
|
|
- wx.hideLoading();
|
|
|
- console.log('预下单', res);
|
|
|
- let orderNo=res.data.data.orderNo;
|
|
|
- wx.requestPayment({
|
|
|
- timeStamp: res.data.data.paymentSign.timeStamp,
|
|
|
- nonceStr: res.data.data.paymentSign.nonceStr,
|
|
|
- package: res.data.data.paymentSign.packageVal,
|
|
|
- signType: 'RSA',
|
|
|
- paySign: res.data.data.paymentSign.paySign,
|
|
|
- success: res => {
|
|
|
- console.log('支付结果', res);
|
|
|
- this.createWeChatPayMentRecord(orderNo,this.data.amount);
|
|
|
- },
|
|
|
- fail (res) {
|
|
|
- console.log("fail",res);
|
|
|
- },
|
|
|
- complete: () => {
|
|
|
+ debugger
|
|
|
+ if(res.data.code === '200'){
|
|
|
+ wx.hideLoading();
|
|
|
+ console.log('预下单', res);
|
|
|
+ let orderNo=res.data.data.orderNo;
|
|
|
+ wx.requestPayment({
|
|
|
+ timeStamp: res.data.data.paymentSign.timeStamp,
|
|
|
+ nonceStr: res.data.data.paymentSign.nonceStr,
|
|
|
+ package: res.data.data.paymentSign.packageVal,
|
|
|
+ signType: 'RSA',
|
|
|
+ paySign: res.data.data.paymentSign.paySign,
|
|
|
+ success: res => {
|
|
|
+ console.log('支付结果', res);
|
|
|
+ this.createWeChatPayMentRecord(orderNo,this.data.amount);
|
|
|
+ },
|
|
|
+ fail (res) {
|
|
|
+ console.log("fail",res);
|
|
|
+ },
|
|
|
+ complete: () => {
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }else if(res.data.code === '500'){
|
|
|
+ // 支付失败处理
|
|
|
+ if (res.data.msg && res.data.msg.includes("系统维护中,请稍后缴费")) {
|
|
|
+ const parts = res.data.msg.split("|");
|
|
|
+ const errorMessage = parts[0]; // "不允许在线缴费"
|
|
|
+ // const payStatus = parts[1];
|
|
|
+ wx.showToast({
|
|
|
+ title: errorMessage,
|
|
|
+ icon: 'none', // 不显示图标
|
|
|
+ duration: 2000 // 持续2秒
|
|
|
+ });
|
|
|
}
|
|
|
- })
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ }
|
|
|
}
|
|
|
})
|
|
|
// 模拟支付
|
|
@@ -219,34 +240,45 @@ Page({
|
|
|
// 输入数字
|
|
|
inputNumber: function(e) {
|
|
|
const number = e.currentTarget.dataset.number;
|
|
|
- let amount = this.data.amount;
|
|
|
+ let customAmount = this.data.customAmount;
|
|
|
|
|
|
// 处理小数点
|
|
|
- if (number === '.' && amount.includes('.')) {
|
|
|
+ if (number === '.' && customAmount.includes('.')) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// 限制小数点后两位
|
|
|
- if (amount.includes('.') && amount.split('.')[1].length >= 2 && number !== '.') {
|
|
|
+ if (customAmount.includes('.') && customAmount.split('.')[1].length >= 2 && number !== '.') {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ // 处理首位为0的情况
|
|
|
+ if (customAmount === '0' && number !== '.') {
|
|
|
+ customAmount = number;
|
|
|
+ } else {
|
|
|
+ customAmount += number;
|
|
|
+ }
|
|
|
+
|
|
|
// 更新金额
|
|
|
this.setData({
|
|
|
- amount: amount === '0' ? number : amount + number
|
|
|
+ customAmount: customAmount,
|
|
|
+ amount: parseFloat(customAmount) || 0
|
|
|
});
|
|
|
},
|
|
|
|
|
|
// 删除数字
|
|
|
deleteNumber: function() {
|
|
|
- let amount = this.data.amount;
|
|
|
- if (amount.length <= 1) {
|
|
|
+ let customAmount = this.data.customAmount;
|
|
|
+ if (customAmount.length <= 1) {
|
|
|
this.setData({
|
|
|
- amount: '0'
|
|
|
+ customAmount: '',
|
|
|
+ amount: 0
|
|
|
});
|
|
|
} else {
|
|
|
+ customAmount = customAmount.substring(0, customAmount.length - 1);
|
|
|
this.setData({
|
|
|
- amount: amount.substring(0, amount.length - 1)
|
|
|
+ customAmount: customAmount,
|
|
|
+ amount: parseFloat(customAmount) || 0
|
|
|
});
|
|
|
}
|
|
|
},
|
|
@@ -254,7 +286,8 @@ Page({
|
|
|
// 确认输入
|
|
|
confirmInput: function() {
|
|
|
this.setData({
|
|
|
- showKeyboard: false
|
|
|
+ showKeyboard: false,
|
|
|
+ inputFocus: false
|
|
|
});
|
|
|
},
|
|
|
|
|
@@ -273,11 +306,19 @@ Page({
|
|
|
value = parts[0] + '.' + parts.slice(1).join('');
|
|
|
}
|
|
|
|
|
|
+ // 处理前导零
|
|
|
+ if (parts[0]) {
|
|
|
+ parts[0] = parts[0].replace(/^0+/, '') || '0';
|
|
|
+ }
|
|
|
+
|
|
|
// 限制小数点后最多两位
|
|
|
if (parts.length === 2 && parts[1].length > 2) {
|
|
|
- value = parts[0] + '.' + parts[1].substring(0, 2);
|
|
|
+ parts[1] = parts[1].substring(0, 2);
|
|
|
}
|
|
|
|
|
|
+ // 重新组合数字
|
|
|
+ value = parts.join('.');
|
|
|
+
|
|
|
// 限制总长度小于8位(包含小数点)
|
|
|
if (value.length > 7) {
|
|
|
value = value.substring(0, 7);
|