|
|
@@ -780,6 +780,7 @@
|
|
|
import personSelect from '@/components/CommomSelect/person-select.vue';
|
|
|
import PaymentCollectionPlan from '@/BIZComponents/paymentCollectionPlan/Index.vue'
|
|
|
import { shippingModeOp, transactionMethodsOp } from '@/enum/dict.js';
|
|
|
+ import { formatPrice } from '@/BIZComponents/setProduct.js';
|
|
|
export default {
|
|
|
mixins: [dictMixins],
|
|
|
components: {
|
|
|
@@ -1952,26 +1953,26 @@
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 使用分进行计算,避免浮点数精度问题
|
|
|
- let receiptPaymentListSum = commitData.receiptPaymentList.reduce((acc, cur) => acc + Math.round(+cur.price * 100), 0) / 100;
|
|
|
+ // 使用万分之一进行计算,避免浮点数精度问题(对应4位小数)
|
|
|
+ let receiptPaymentListSum = commitData.receiptPaymentList.reduce((acc, cur) => acc + Math.round(+cur.price * 10000), 0) / 10000;
|
|
|
const payAmount = +commitData.payAmount;
|
|
|
|
|
|
if(+ratioSum == 100) {
|
|
|
- // 使用分进行计算,避免浮点数精度问题
|
|
|
- const difference = Math.round((payAmount - receiptPaymentListSum) * 100) / 100;
|
|
|
+ // 使用万分之一进行计算,避免浮点数精度问题
|
|
|
+ const difference = Math.round((payAmount - receiptPaymentListSum) * 10000) / 10000;
|
|
|
console.log('difference~~~', difference);
|
|
|
- if (Math.abs(difference) >= 0.01 && commitData.receiptPaymentList.length > 0) {
|
|
|
+ if (Math.abs(difference) >= 0.0001 && commitData.receiptPaymentList.length > 0) {
|
|
|
const lastIndex = commitData.receiptPaymentList.length - 1;
|
|
|
- // 使用分进行计算,避免浮点数精度问题
|
|
|
- const newPrice = Math.round((+commitData.receiptPaymentList[lastIndex].price + difference) * 100) / 100;
|
|
|
- commitData.receiptPaymentList[lastIndex].price = newPrice.toFixed(2);
|
|
|
- receiptPaymentListSum = commitData.receiptPaymentList.reduce((acc, cur) => acc + Math.round(+cur.price * 100), 0) / 100;
|
|
|
+ // 使用万分之一进行计算,避免浮点数精度问题
|
|
|
+ const newPrice = Math.round((+commitData.receiptPaymentList[lastIndex].price + difference) * 10000) / 10000;
|
|
|
+ commitData.receiptPaymentList[lastIndex].price = formatPrice(newPrice);
|
|
|
+ receiptPaymentListSum = commitData.receiptPaymentList.reduce((acc, cur) => acc + Math.round(+cur.price * 10000), 0) / 10000;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
console.log('receiptPaymentListSum~~~', +receiptPaymentListSum, payAmount);
|
|
|
|
|
|
- if(Math.abs(+receiptPaymentListSum - payAmount) > 0.01){
|
|
|
+ if(Math.abs(+receiptPaymentListSum - payAmount) > 0.0001){
|
|
|
this.$message.error('计划收款金额合计与优惠后金额不一致');
|
|
|
return;
|
|
|
}
|