Bladeren bron

新建采反商品弹窗,增加成本价格字段及算法,增加乘法与加法精度处理计算函数

lucky-lzx 2 jaren geleden
bovenliggende
commit
a3c7d01134
1 gewijzigde bestanden met toevoegingen van 111 en 4 verwijderingen
  1. 111 4
      src/views/purchaseIn/workbench/components/baseForm.vue

+ 111 - 4
src/views/purchaseIn/workbench/components/baseForm.vue

@@ -14,9 +14,28 @@
         :span="24"
         style="padding: 12px 16px 12px 16px; text-align: right"
       >
-        <!-- <span
-          >成本合计:<span>{{ back_total }}</span></span
-        > -->
+      <!-- 贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用=成本合计 -->
+      <!-- 贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费=成本合计 -->
+      <!-- ps:没有其他费用-->  
+      <!-- (ruleForm.noble_weight*askItem.gold_price)+ (ruleForm.cost_fee*ruleForm.noble_weight)
+      + ruleForm.mark_fee + ruleForm.pakge_fee + ruleForm.cert_fee + ruleForm.nake_fee + ruleForm.delivery_fee-->
+      <!-- 乘法精度函数调用在mounted(初始调用),number_change函数(改变调用),如果放在dom层初始值时undifind会报错  r1,r2-->
+        <span
+          >成本合计:<span>
+            {{ 
+              accAdd(
+                r1,
+                r2,
+                ruleForm.mark_fee,
+                ruleForm.pakge_fee,
+                ruleForm.cert_fee,
+                ruleForm.nake_fee,
+                ruleForm.delivery_fee,
+                )
+            }}
+           <!-- {{ruleForm.delivery_fee}} -->
+            </span></span
+        >
         <span
           class="fl"
           style="height: 28px; font-size: 16px; line-height: 28px"
@@ -611,7 +630,7 @@ import {
 export default {
   name: "goodsCostAdd",
   mixins: [resToken],
-  props: ["showModel", "id", "type", "sitem", "askItem", "newTime", "editId"],
+  props: ["showModel", "id", "type", "sitem", "askItem", "newTime", "editId",],
   components: {
     baseFormAddEdit,
   },
@@ -666,12 +685,96 @@ export default {
       options11: options11,
       ruleForm: {},
       rules: JSON.parse(JSON.stringify(rules)),
+      r1:"",
+      r2:"",
     };
   },
   mounted() {
     this.initForm();
+
+  this.$nextTick(()=>{
+    this.r1 = this.accMul(this.ruleForm.noble_weight,this.askItem.gold_price)
+    this.r2 = this.accMul(this.ruleForm.cost_fee,this.ruleForm.noble_weight)
+   console.log(this.r1,this.r2)
+  })
+   
+    
   },
   methods: {
+    //加法精度问题
+//     accAdd(arg1,arg2){ 
+//     var r1,r2,m; 
+//     try{
+//     	r1=arg1.toString().split(".")[1].length;
+//     }catch(e){
+//     	r1=0;
+//     } 
+//     try{
+//     	r2=arg2.toString().split(".")[1].length;
+//     }catch(e){
+//     	r2=0;
+//     } 
+//     m=Math.pow(10,Math.max(r1,r2)) ;
+//     return (arg1*m+arg2*m)/m ;
+// },
+accAdd(arg1,arg2,arg3,arg4,arg5,arg6,arg7){ 
+    var r1,r2,r3,r4,r5,r6,r7,m; 
+    console.log(arg1,arg2,arg3,arg4,arg5,arg6,arg7)
+    try{
+    	r1=arg1.toString().split(".")[1].length;
+    }catch(e){
+    	r1=0;
+    } 
+    try{
+    	r2=arg2.toString().split(".")[1].length;
+    }catch(e){
+    	r2=0;
+    }
+    try{
+    	r3=arg3.toString().split(".")[1].length;
+    }catch(e){
+    	r3=0;
+    }  
+    try{
+    	r4=arg4.toString().split(".")[1].length;
+    }catch(e){
+    	r4=0;
+    } 
+    try{
+    	r5=arg5.toString().split(".")[1].length;
+    }catch(e){
+    	r5=0;
+    } 
+    try{
+    	r6=arg6.toString().split(".")[1].length;
+    }catch(e){
+    	r6=0;
+    } 
+    try{
+    	r7=arg7.toString().split(".")[1].length;
+    }catch(e){
+    	r7=0;
+    } 
+    m=Math.pow(10,Math.max(r1,r2,r3,r4,r5,r6,r7)) ;
+    return (arg1*m+arg2*m+arg3*m+arg4*m+arg5*m+arg6*m+arg7*m)/m ;
+},
+
+     //乘法精度问题
+    accMul(arg1, arg2) {
+        var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
+        try {
+            m += s1.split(".")[1].length;
+        }
+        catch (e) {
+        }
+        try {
+            m += s2.split(".")[1].length;
+        }
+        catch (e) {
+        }
+        let numStr = Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
+        return numStr.toString()
+    },
     async initForm() {
       this.supplierNo = [];
       console.log(this.id);
@@ -698,6 +801,10 @@ export default {
     number_change(e, key) {
       this.ruleForm[key] = e + "" || "0";
       this.$refs.ruleForm.validateField(key);
+      this.$nextTick(()=>{
+      this.r1 = this.accMul(this.ruleForm.noble_weight,this.askItem.gold_price)
+      this.r2 = this.accMul(this.ruleForm.cost_fee,this.ruleForm.noble_weight)
+  })
     },
     async initData() {
       this.loading = true;