ccj il y a 9 mois
Parent
commit
6603042636
3 fichiers modifiés avec 53 ajouts et 17 suppressions
  1. 2 0
      src/main.js
  2. 33 0
      src/utils/index.js
  3. 18 17
      src/views/houseSelfCollect/settlement.vue

+ 2 - 0
src/main.js

@@ -43,6 +43,8 @@ Vue.component('ItemWrap', ItemWrap)
 import Echart from './components/echart/index.vue'
 Vue.component('Echart', Echart)
 import '@/utils/jsmpeg.min'
+import { rewriteToFixed } from './utils/index'
+Number.prototype.rewriteToFixed = rewriteToFixed;
 // 初始化vue-amap
 // AMap.initAMapApiLoader({
 //   // 高德key

+ 33 - 0
src/utils/index.js

@@ -138,3 +138,36 @@ export function formatTime(time, fmt) {
     return fmt;
   }
 }
+// 重写toFixed,为了不替代原生属性toFixed,重新命名rewriteToFixed
+// 参数d表示要保留多少位小数
+export function rewriteToFixed(d) {
+  var s = this + "";
+  if (!d) d = 0;
+  if (s.indexOf(".") == -1) s += ".";
+  s += new Array(d + 1).join("0");
+  let test = new RegExp(
+    "^(-|\\+)?(\\d+(\\.\\d{0," + (d + 1) + "})?)\\d*$"
+  ).exec(s);
+  if (test) {
+    var s = "0" + test[2],
+      pm = test[1] ? test[1] : "",
+      a = test[3].length,
+      b = true;
+    if (a == d + 2) {
+      a = s.match(/\d/g);
+      if (parseInt(a[a.length - 1]) > 4) {
+        for (var i = a.length - 2; i >= 0; i--) {
+          a[i] = parseInt(a[i]) + 1;
+          if (a[i] == 10) {
+            a[i] = 0;
+            b = i != 1;
+          } else break;
+        }
+      }
+      s = a.join("").replace(new RegExp("(\\d+)(\\d{" + d + "})\\d$"), "$1.$2");
+    }
+    if (b) s = s.substring(1);
+    return (pm + s).replace(/\.$/, "");
+  }
+  return this + "";
+}

+ 18 - 17
src/views/houseSelfCollect/settlement.vue

@@ -791,7 +791,7 @@
             this.paymentList.unitDeduction = 0
           }
           if(this.paymentList.warehouseName =='杜尔伯特家禾库' && this.types == 1){
-            this.paymentList.unloadDeduction = (Number(this.paymentList.netWeight)/1000*5).toFixed(0)
+            this.paymentList.unloadDeduction = (Number(this.paymentList.netWeight)/1000*5).rewriteToFixed(0)
           }
           let compIdTmp  = localStorage.getItem('ws-pf_compId')
           //白城市鹏羽粮食贸易有限公司 扣重比1.25 干粮水分14.5
@@ -799,15 +799,15 @@
             // this.paymentList.buckleWeightRatio = this.paymentList.qualityInspectionManagement.buckleWeightRatio
             this.paymentList.buckleWeightRatio = 1.25
             this.ganwater = 14.5
-            this.paymentList.tidalGrainPrice = this.paymentList.tidalGrainPrice.toFixed(4)
+            this.paymentList.tidalGrainPrice = this.paymentList.tidalGrainPrice.rewriteToFixed(4)
             if (this.paymentList.qualityInspectionManagement.paramType == '2') {
               this.paymentList.qualityInspectionManagement.weightDeduction = (this.paymentList
                   .qualityInspectionManagement.waterContent - this.ganwater) *
                 this.paymentList.buckleWeightRatio
               this.paymentList.qualityInspectionManagement.weightDeduction = this.paymentList
-                .qualityInspectionManagement.weightDeduction.toFixed(5)
+                .qualityInspectionManagement.weightDeduction.rewriteToFixed(5)
               this.paymentList.base = (100 - this.paymentList.qualityInspectionManagement.weightDeduction) / 100
-              this.paymentList.base = this.paymentList.base.toFixed(5)
+              this.paymentList.base = this.paymentList.base.rewriteToFixed(5)
               if (this.paymentList.type == '潮粮') {
                 if(this.paymentList.base > 1){
                   this.paymentList.base = 1
@@ -843,15 +843,16 @@
             else{
               this.paymentList.buckleWeightRatio = 1.3 - (30 - this.paymentList.qualityInspectionManagement.waterContent)*0.01
             }
-            this.paymentList.tidalGrainPrice = this.paymentList.tidalGrainPrice.toFixed(4)
+            this.paymentList.tidalGrainPrice = this.paymentList.tidalGrainPrice.rewriteToFixed(4)
+            debugger
             if (this.paymentList.qualityInspectionManagement.paramType == '2') {
               this.paymentList.qualityInspectionManagement.weightDeduction = (this.paymentList
                   .qualityInspectionManagement.waterContent - this.ganwater) *
                 this.paymentList.buckleWeightRatio
               this.paymentList.qualityInspectionManagement.weightDeduction = this.paymentList
-                .qualityInspectionManagement.weightDeduction.toFixed(2)
+                .qualityInspectionManagement.weightDeduction.rewriteToFixed(2)
               this.paymentList.base = (100 - this.paymentList.qualityInspectionManagement.weightDeduction) / 100
-              this.paymentList.base = this.paymentList.base.toFixed(3)
+              this.paymentList.base = this.paymentList.base.rewriteToFixed(3)
               if (this.paymentList.type == '潮粮') {
                 if(this.paymentList.base > 1){
                   this.paymentList.base = 1
@@ -889,18 +890,18 @@
           }else{
             this.paymentList.grainMoney = (this.paymentList.qualityInspectionManagement.dryGrainPrice - this.paymentList.unitDeduction) * this.paymentList.contractManagement.weight
           }
-          this.paymentList.solidGrainPrice = (Number(this.paymentList.grainMoney) / Number(this.paymentList.pureWeight)).toFixed(4)
+          this.paymentList.solidGrainPrice = (Number(this.paymentList.grainMoney) / Number(this.paymentList.pureWeight)).rewriteToFixed(4)
           this.paymentList.calculationPayable = Number(this.paymentList.grainMoney) + Number(this.paymentList .weighingSubsidy) + Number(this.paymentList.freightSubsidy) + Number(this.paymentList.unloadSubsidy) +
             Number(this.paymentList.otherSubsidy) - Number(this.paymentList.weighingDeduction) - this.paymentList.freightDeduction - Number(this.paymentList.unloadDeduction) - Number(this.paymentList.otherDeduction) - Number(this.paymentList.qualityDeduction)
-          this.paymentList.calculationPayable = this.paymentList.calculationPayable.toFixed(2)
+          this.paymentList.calculationPayable = this.paymentList.calculationPayable.rewriteToFixed(2)
           this.paymentList.actualPayment = this.paymentList.calculationPayable
           this.actualPayment(this.paymentList.actualPayment)
         }else if (this.paymentList.type == '潮粮') {
           this.paymentList.grainMoney = (this.paymentList.qualityInspectionManagement.tidalGrainPrice - this.paymentList.unitDeduction) * this.paymentList.weighingManagement.netWeight
-          this.paymentList.solidGrainPrice = (Number(this.paymentList.grainMoney) / Number(this.paymentList.pureWeight)).toFixed(4)
+          this.paymentList.solidGrainPrice = (Number(this.paymentList.grainMoney) / Number(this.paymentList.pureWeight)).rewriteToFixed(4)
           this.paymentList.calculationPayable = Number(this.paymentList.grainMoney) + Number(this.paymentList .weighingSubsidy) + Number(this.paymentList.freightSubsidy) + Number(this.paymentList.unloadSubsidy) +
             Number(this.paymentList.otherSubsidy) - Number(this.paymentList.weighingDeduction) - this.paymentList.freightDeduction - Number(this.paymentList.unloadDeduction) - Number(this.paymentList.otherDeduction) - Number(this.paymentList.qualityDeduction)
-          this.paymentList.calculationPayable = this.paymentList.calculationPayable.toFixed(2)
+          this.paymentList.calculationPayable = this.paymentList.calculationPayable.rewriteToFixed(2)
 
           this.paymentList.actualPayment = this.paymentList.calculationPayable
           this.actualPayment(this.paymentList.actualPayment)
@@ -910,11 +911,11 @@
             Number(this.paymentList.otherSubsidy) - Number(this.paymentList.weighingDeduction) - this.paymentList
             .freightDeduction - Number(this.paymentList.unloadDeduction) - Number(this.paymentList.otherDeduction) -
             Number(this.paymentList.qualityDeduction)
-          this.paymentList.calculationPayable = this.paymentList.calculationPayable.toFixed(2)
+          this.paymentList.calculationPayable = this.paymentList.calculationPayable.rewriteToFixed(2)
           this.paymentList.actualPayment = this.paymentList.calculationPayable
           this.actualPayment(this.paymentList.actualPayment)
         }
-        this.paymentList.grainMoney = this.paymentList.grainMoney.toFixed(2)
+        this.paymentList.grainMoney = this.paymentList.grainMoney.rewriteToFixed(2)
       },
       /**
        * 将金额数字转为汉字大写
@@ -1144,16 +1145,16 @@
               .waterContent - 15) * this.paymentList
             .buckleWeightRatio
           this.paymentList.qualityInspectionManagement.weightDeduction = this.paymentList.qualityInspectionManagement
-            .weightDeduction.toFixed(2)
+            .weightDeduction.rewriteToFixed(2)
           this.paymentList.base = (100 - this.paymentList.qualityInspectionManagement.weightDeduction) / 100
-          this.paymentList.base = this.paymentList.base.toFixed(3)
+          this.paymentList.base = this.paymentList.base.rewriteToFixed(3)
           if(this.paymentList.base > 1){
             this.paymentList.base = 1
           }
           this.paymentList.pureWeight = this.paymentList.base * this.paymentList.weighingManagement.netWeight
           this.paymentList.solidGrainPrice = (Number(this.paymentList.grainMoney) / Number(this.paymentList.pureWeight))
-            .toFixed(4)
-          this.paymentList.pureWeight = this.paymentList.pureWeight.toFixed(2)
+            .rewriteToFixed(4)
+          this.paymentList.pureWeight = this.paymentList.pureWeight.rewriteToFixed(2)
 
         } else {
           this.$message({