Procházet zdrojové kódy

采购金额小数点

cz před 1 rokem
rodič
revize
21023ec368

+ 3 - 3
src/components/PDF/purchasePDF.vue

@@ -213,9 +213,9 @@ const handlePrintPdf = (row) => {
           countTotal += Number(e.count);
           productMoney += Number(e.amount);
         }
-        res.countTotal = countTotal;
-        res.productMoney = productMoney;
-        res.otherMoney = res.amount - res.productMoney;
+        res.countTotal = countTotal.toFixed(2);
+        res.productMoney = productMoney.toFixed(2);
+        res.otherMoney = (res.amount - res.productMoney).toFixed(2);
         res.moneyChinese = NumberToChinese(res.amount);
         res.supplyAddress = {
           countryName: supplyData.countryName,

+ 13 - 8
src/components/process/SendPurchase.vue

@@ -686,12 +686,12 @@ const handleChangeSupplier = (val) => {
   }
 };
 
-const formatNumber = (value) => {
+const formatNumber = (value, num = 10000) => {
   if (value === null || value === undefined || value === "") {
     return "";
   }
   // 将输入值保留四位小数
-  const formattedValue = Math.round(Number(value) * 10000) / 10000;
+  const formattedValue = Math.round(Number(value) * num) / num;
   return formattedValue;
 };
 
@@ -700,31 +700,36 @@ const handleChangeAmount = () => {
   let productAmount = 0;
   for (let i = 0; i < formData.data.purchaseDetailList.length; i++) {
     const e = formData.data.purchaseDetailList[i];
-    e.amount = formatNumber(parseFloat(e.count * e.price));
+    e.amount = formatNumber(parseFloat(e.count * e.price), 100);
     productAmount += Number(e.amount);
   }
-  formData.data.productAmount = formatNumber(productAmount);
+  formData.data.productAmount = formatNumber(productAmount, 100);
   // 其他收费
   let otherAmount = 0;
   for (let i = 0; i < formData.data.otherFeeList.length; i++) {
     const e = formData.data.otherFeeList[i];
     otherAmount += Number(e.price);
   }
-  formData.data.otherAmount = formatNumber(otherAmount);
+  formData.data.otherAmount = formatNumber(otherAmount, 100);
   formData.data.amount = formatNumber(
     parseFloat(
       Number(formData.data.productAmount) + Number(formData.data.otherAmount)
-    )
+    ),
+    100
   );
 };
 
 const handleChangeMoney = (val, index, key) => {
-  formData.data.purchaseDetailList[index][key] = formatNumber(val);
+  let num = 100;
+  if (key === "count") {
+    num = 10000;
+  }
+  formData.data.purchaseDetailList[index][key] = formatNumber(val, num);
   handleChangeAmount();
 };
 
 const handleChangeOtherMoney = (val, index, key) => {
-  formData.data.otherFeeList[index][key] = formatNumber(val);
+  formData.data.otherFeeList[index][key] = formatNumber(val, 100);
   handleChangeAmount();
 };