Bladeren bron

feature 缴费功能关闭代码提交

xiahan 3 weken geleden
bovenliggende
commit
244f72d056
1 gewijzigde bestanden met toevoegingen van 56 en 59 verwijderingen
  1. 56 59
      pages/lijijiaofei/lijijiaofei.js

+ 56 - 59
pages/lijijiaofei/lijijiaofei.js

@@ -22,16 +22,16 @@ Page({
     selectedAmount: 0,
     customAmount: '',
     inputFocus: false,
-    zdId:"",
+    zdId: "",
     amount: 0,
     actualAmount: 0,
     balance: 0
   },
   onLoad(options) {
-    const _this=this;
+    const _this = this;
     // 更新用户信息
     this.updateUserInfo();
-    
+
 
     wx.request({
       url: app.globalData.interfaceUrls.pendingBill + app.globalData.currentAccountInfo.usernumber,
@@ -65,14 +65,14 @@ Page({
 
     this.setData({
       images: {
-        logo:'/static_file/logo.png',
-        background:'/static_file/background.png',
-        card:'/static_file/card.png',
-        tzd:'/static_file/backgrountzdd.png',
-        phone:'/static_file/phone.png',
-        yl:'/static_file/background.yl',
-        jcsfcjtzd:'/static_file/jcsfcjtzd.png',
-        kapiantubiao:'/static_file/kapiantubiao.png'
+        logo: '/static_file/logo.png',
+        background: '/static_file/background.png',
+        card: '/static_file/card.png',
+        tzd: '/static_file/backgrountzdd.png',
+        phone: '/static_file/phone.png',
+        yl: '/static_file/background.yl',
+        jcsfcjtzd: '/static_file/jcsfcjtzd.png',
+        kapiantubiao: '/static_file/kapiantubiao.png'
 
       }
     })
@@ -87,7 +87,7 @@ Page({
   onShow() {
     // 每次页面显示时更新用户信息
     this.updateUserInfo();
-    
+
     // 获取最新余额数据
     const _this = this;
     wx.request({
@@ -131,10 +131,10 @@ Page({
   },
 
   // 计算默认实缴金额
-  calculateDefaultAmount: function() {
+  calculateDefaultAmount: function () {
     const { actualAmount, balance } = this.data;
-    const difference =  utils.floatSub(actualAmount,balance);
-    
+    const difference = utils.floatSub(actualAmount, balance);
+
     if (difference <= 0) {
       this.setData({
         amount: 0
@@ -147,10 +147,10 @@ Page({
   },
 
   // 验证实缴金额
-  validateAmount: function(amount) {
+  validateAmount: function (amount) {
     const { actualAmount, balance } = this.data;
     const difference = actualAmount - balance;
-    
+
     if (difference <= 0) {
       return amount > 0;
     } else {
@@ -159,7 +159,7 @@ Page({
   },
 
   // 选择快捷金额
-  selectAmount: function(e) {
+  selectAmount: function (e) {
     const amount = parseFloat(e.currentTarget.dataset.amount);
     this.setData({
       selectedAmount: amount,
@@ -169,9 +169,9 @@ Page({
   },
 
   // 立即缴费
-  payNow: function() {
+  payNow: function () {
     const { amount, actualAmount, balance } = this.data;
-    const _this=this;    
+    const _this = this;
     if (amount <= 0) {
       wx.showToast({
         title: '请输入缴费金额',
@@ -180,9 +180,9 @@ Page({
       return;
     }
     debugger;
-    if (actualAmount > 0 && utils.floatAdd(amount,balance) < actualAmount) {
+    if (actualAmount > 0 && utils.floatAdd(amount, balance) < actualAmount) {
       // 先转整数计算,再转回浮点数
-      const minPayment =  utils.floatSub(actualAmount - balance);
+      const minPayment = utils.floatSub(actualAmount - balance);
       const formattedMinPayment = minPayment.toFixed(2);
       wx.showToast({
         title: '最低缴费金额:' + formattedMinPayment + '元',
@@ -205,16 +205,17 @@ Page({
       },
       data: {
         openId: app.globalData.userWxInfo.openid,
-        totalAmount: utils.floatMul(this.data.amount,100),
+        totalAmount: utils.floatMul(this.data.amount, 100),
         dskey: app.globalData.currentAccountInfo.dsKey,
         zdId: this.data.zdId,
         userNumber: app.globalData.currentAccountInfo.usernumber
       },
       success: res => {
-        if(res.data.code === '200'){
+        debugger;
+        if (res.data.code === '200') {
           wx.hideLoading();
           console.log('预下单', res);
-          let orderNo=res.data.data.orderNo;
+          let orderNo = res.data.data.orderNo;
           wx.requestPayment({
             timeStamp: res.data.data.paymentSign.timeStamp,
             nonceStr: res.data.data.paymentSign.nonceStr,
@@ -231,12 +232,12 @@ Page({
               //   this.createWeChatPayMentRecord(orderNo,this.data.amount);
               // },200)
             },
-            fail (failRes) {
+            fail(failRes) {
               _this.setData({
-                customAmount:null
+                customAmount: null
               });
               wx.request({
-                url: app.globalData.interfaceUrls.cancelPay+orderNo+"/wechat",
+                url: app.globalData.interfaceUrls.cancelPay + orderNo + "/wechat",
                 method: 'POST',
                 header: {
                   'content-type': 'application/json',
@@ -248,52 +249,48 @@ Page({
                 success(res) { },
                 fail(error) { }
               });
-              console.log("fail",failRes);
+              console.log("fail", failRes);
             },
             complete: (res) => {
-              console.log("complete",res);
+              console.log("complete", res);
             }
           })
-        }else if(res.data.code === '500'){
+        } else if (res.data.code === '500') {
+          const errorMessage = res.data.msg || "系统维护中,请一个小时后使用";
           // 支付失败处理
-          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秒
+          wx.showToast({
+            title: errorMessage,
+            icon: 'none',
+            duration: 2000  // 持续2秒
           });
-          }
         }
       }
     })
   },
 
   // 返回上一页
-  goBack: function() {
+  goBack: function () {
     // 设置刷新标记
     wx.setStorageSync('needRefreshHomepage', true);
     wx.navigateBack();
   },
 
   // 切换到首页
-  goToHome: function() {
+  goToHome: function () {
     wx.switchTab({
       url: '/pages/homepage/homepage',
     });
   },
 
   // 切换到我的页面
-  goToMine: function() {
+  goToMine: function () {
     wx.switchTab({
       url: '/pages/mine/mine',
     });
   },
 
   // 添加切换水表的方法
-  switchMeter: function() {
+  switchMeter: function () {
     wx.navigateTo({
       url: '/pages/switchMeter/switchMeter',
     })
@@ -312,7 +309,7 @@ Page({
   },
 
   // 显示键盘 - 使用微信内置键盘
-  showCustomAmountInput: function() {
+  showCustomAmountInput: function () {
     // 使用微信内置的输入框
     wx.showModal({
       title: '请输入金额',
@@ -338,12 +335,12 @@ Page({
   },
 
   // 自定义金额输入
-  onCustomAmountInput: function(e) {
+  onCustomAmountInput: function (e) {
     let value = e.detail.value;
-    
+
     // 只允许输入数字和小数点
     value = value.replace(/[^\d.]/g, '');
-    
+
     // 处理前导零
     if (value.startsWith('0')) {
       // 如果只有一个0,保持不变
@@ -357,7 +354,7 @@ Page({
         if (value === '') value = '0';
       }
     }
-    
+
     // 处理小数点
     if (value.includes('.')) {
       const parts = value.split('.');
@@ -370,9 +367,9 @@ Page({
         value = parts[0] + '.' + parts[1].substring(0, 2);
       }
     }
-    
+
     const amount = parseFloat(value) || 0;
-    
+
     this.setData({
       customAmount: value,
       amount: amount,
@@ -381,7 +378,7 @@ Page({
   },
 
   // 输入数字
-  inputNumber: function(e) {
+  inputNumber: function (e) {
     const number = e.currentTarget.dataset.number;
     let customAmount = this.data.customAmount;
 
@@ -419,7 +416,7 @@ Page({
   },
 
   // 删除数字
-  deleteNumber: function() {
+  deleteNumber: function () {
     let customAmount = this.data.customAmount;
     if (customAmount.length <= 1) {
       this.setData({
@@ -436,7 +433,7 @@ Page({
   },
 
   // 确认输入
-  confirmInput: function() {
+  confirmInput: function () {
     this.setData({
       showKeyboard: false,
       inputFocus: false
@@ -444,7 +441,7 @@ Page({
   },
 
   // 输入框获得焦点
-  onInputFocus: function() {
+  onInputFocus: function () {
     this.setData({
       inputFocus: true,
       selectedAmount: null // 取消快捷金额的选中状态
@@ -452,13 +449,13 @@ Page({
   },
 
   // 输入框失去焦点
-  onInputBlur: function() {
+  onInputBlur: function () {
     this.setData({
       inputFocus: false
     });
   },
   // 创建微信付款记录
-  createWeChatPayMentRecord:function(orderNo,paymentAmount){
+  createWeChatPayMentRecord: function (orderNo, paymentAmount) {
     wx.request({
       url: app.globalData.interfaceUrls.createPaymentRecord,
       method: 'POST',
@@ -492,7 +489,7 @@ Page({
   },
 
   // 从接口获取支付数据
-  fetchPaymentData: function() {
+  fetchPaymentData: function () {
     // 这里是模拟数据,实际应用中应该调用真实接口
     // wx.request({
     //   url: 'your-api-endpoint',
@@ -503,7 +500,7 @@ Page({
     //     });
     //   }
     // });
-    
+
     // this.setData({
     //   amountDue: 150.00,
     //   balance: 200.50