Browse Source

修复微信支付金额精度丢失

zhengjinyi 4 years ago
parent
commit
599b78a66c
1 changed files with 17 additions and 2 deletions
  1. 17 2
      pages/user/order/order-pay.vue

+ 17 - 2
pages/user/order/order-pay.vue

@@ -173,7 +173,7 @@
 				}
 				}
 				this.GetPayOrderInfo()
 				this.GetPayOrderInfo()
 			},
 			},
-			GetPayOrderInfo(){
+			GetPayOrderInfo(){//初始化支付信息
 				this.PayService.PayOrderCheckoutCounter({orderId:this.orderID}).then(response =>{
 				this.PayService.PayOrderCheckoutCounter({orderId:this.orderID}).then(response =>{
 					this.isRepuest = true
 					this.isRepuest = true
 					this.discernReceipt = response.data.discernReceipt 		//支付记录
 					this.discernReceipt = response.data.discernReceipt 		//支付记录
@@ -181,6 +181,7 @@
 					this.receiptAmount = response.data.order.receiptAmount  //已付金额
 					this.receiptAmount = response.data.order.receiptAmount  //已付金额
 					this.payableAmount = response.data.order.payableAmount - this.receiptAmount//已付金额
 					this.payableAmount = response.data.order.payableAmount - this.receiptAmount//已付金额
 					this.payAmount = this.toFixedFn(this.payableAmount)	//自定义金额
 					this.payAmount = this.toFixedFn(this.payableAmount)	//自定义金额
+					console.log('this.payAmount',this.payAmount)
 					this.balanceAmount = this.payableAmount - this.payAmount// 计算剩余支付金额
 					this.balanceAmount = this.payableAmount - this.payAmount// 计算剩余支付金额
 				}).catch(error =>{
 				}).catch(error =>{
 					this.$util.msg(error.msg,2000)
 					this.$util.msg(error.msg,2000)
@@ -227,8 +228,9 @@
 						this.$util.msg("本次支付的金额必须大于¥0.02",2000)
 						this.$util.msg("本次支付的金额必须大于¥0.02",2000)
 						return
 						return
 					}
 					}
+					console.log('this.payAmount',this.payAmount)
 					let params ={
 					let params ={
-							payAmount:this.payAmount*100,
+							payAmount:this.accMul(this.payAmount,100),
 							payWay:"WEIXIN",
 							payWay:"WEIXIN",
 							code:wechatcode,
 							code:wechatcode,
 							orderId:this.orderID
 							orderId:this.orderID
@@ -269,6 +271,19 @@
 					}
 					}
 				})
 				})
 			},
 			},
+			accMul(value1, value2) {
+			    if (value1 == 0 || value2 == 0) {
+			      return 0;
+			    }
+			    let m = 0;
+			    let v1 = value1.toString();
+			    let v2 = value2.toString();
+			    m += v1.split(".")[1] ? v1.split(".")[1].length : 0;
+			    m += v2.split(".")[1] ? v2.split(".")[1].length : 0;
+			    let _v1 = Number(v1.replace(".", ""));
+			    let _v2 = Number(v2.replace(".", ""));
+			    return (_v1 * _v2) / Math.pow(10, m);
+			},
 			confirmEvent(value){//点击自定义键盘完成的回调函数
 			confirmEvent(value){//点击自定义键盘完成的回调函数
 				this.chechValue(value)
 				this.chechValue(value)
 				this.showDigitKeyboard = false
 				this.showDigitKeyboard = false