فهرست منبع

refactor(price-format): 使用formatPrice统一处理价格格式化,保留4位小数(采购单和销售单)

liujt 3 ماه پیش
والد
کامیت
3386dd6438

+ 13 - 16
src/BIZComponents/inventoryTable.vue

@@ -187,7 +187,7 @@
       </template>
       </template>
       <template v-slot:totalPrice="scope">
       <template v-slot:totalPrice="scope">
         <el-form-item :prop="'datasource.' + scope.$index + '.totalPrice'">
         <el-form-item :prop="'datasource.' + scope.$index + '.totalPrice'">
-          {{ (Number(scope.row.totalPrice) || 0).toFixed(2) }}元
+          {{ formatPrice(Number(scope.row.totalPrice) || 0) }}元
         </el-form-item>
         </el-form-item>
       </template>
       </template>
 
 
@@ -982,7 +982,7 @@
   import ProductionVersion from '@/components/ProductionVersion2/index.vue';
   import ProductionVersion from '@/components/ProductionVersion2/index.vue';
   import { getInventoryTotalAPI } from '@/api/wms';
   import { getInventoryTotalAPI } from '@/api/wms';
   import { pricingWayList, lbjtList } from '@/enum/dict.js';
   import { pricingWayList, lbjtList } from '@/enum/dict.js';
-  import { changeCount, getAllPrice, getAllDiscountPrice } from '@/BIZComponents/setProduct.js';
+  import { changeCount, getAllPrice, getAllDiscountPrice, formatPrice } from '@/BIZComponents/setProduct.js';
   import { contactQueryByCategoryIdsAPI } from '@/api/saleManage/contact';
   import { contactQueryByCategoryIdsAPI } from '@/api/saleManage/contact';
   import taskinstanceDialog from '@/BIZComponents/procedure/taskinstanceDialog.vue';
   import taskinstanceDialog from '@/BIZComponents/procedure/taskinstanceDialog.vue';
   import timeDialog from '@/components/timeDialog/index.vue';
   import timeDialog from '@/components/timeDialog/index.vue';
@@ -1502,7 +1502,7 @@
             isNone: !this.isDiscount,
             isNone: !this.isDiscount,
             formatter: (_row, _column, cellValue) => {
             formatter: (_row, _column, cellValue) => {
               return _row.discountSinglePrice
               return _row.discountSinglePrice
-                ? Number(_row.discountSinglePrice).toFixed(2)
+                ? formatPrice(Number(_row.discountSinglePrice))
                 : '';
                 : '';
             }
             }
           },
           },
@@ -1521,7 +1521,7 @@
             isNone: !this.isDiscount,
             isNone: !this.isDiscount,
             formatter: (_row, _column, cellValue) => {
             formatter: (_row, _column, cellValue) => {
               return _row.discountTotalPrice
               return _row.discountTotalPrice
-                ? Number(_row.discountTotalPrice).toFixed(2)
+                ? formatPrice(Number(_row.discountTotalPrice))
                 : '';
                 : '';
             }
             }
           },
           },
@@ -1773,6 +1773,7 @@
       });
       });
     },
     },
     methods: {
     methods: {
+      formatPrice,
       handleCountChange(row, index,weightType) {
       handleCountChange(row, index,weightType) {
         // 数量变化时,若为生产加工类型,触发含税小计计算
         // 数量变化时,若为生产加工类型,触发含税小计计算
         if (this.quoteType === 2) {
         if (this.quoteType === 2) {
@@ -1949,7 +1950,7 @@
           this.$set(
           this.$set(
             this.form.datasource[index],
             this.form.datasource[index],
             'totalPrice',
             'totalPrice',
-            ((row.increaseTotalWeight || 0) * row.singlePrice).toFixed(2)
+            formatPrice((row.increaseTotalWeight || 0) * row.singlePrice)
           );
           );
           this.changeAll();
           this.changeAll();
         }
         }
@@ -1985,7 +1986,7 @@
         this.$set(
         this.$set(
           this.form.datasource[index],
           this.form.datasource[index],
           'totalPrice',
           'totalPrice',
-          totalPrice.toFixed(2)
+          formatPrice(totalPrice)
         );
         );
         if (
         if (
           row[this.countObj.unitKey] == row.weightUnit &&
           row[this.countObj.unitKey] == row.weightUnit &&
@@ -2030,16 +2031,14 @@
             this.$set(
             this.$set(
               this.form.datasource[index],
               this.form.datasource[index],
               'discountSinglePrice',
               'discountSinglePrice',
-              parseFloat(
-                (item.singlePrice * (item.discountRatio / 100)).toFixed(2)
-              )
+              formatPrice(item.singlePrice * (item.discountRatio / 100))
             );
             );
 
 
             this.$set(
             this.$set(
               this.form.datasource[index],
               this.form.datasource[index],
               'discountTotalPrice',
               'discountTotalPrice',
-              parseFloat(
-                (item.totalPrice * (item.discountRatio / 100)).toFixed(2)
+              formatPrice(
+                item.totalPrice * (item.discountRatio / 100)
               )
               )
             );
             );
             
             
@@ -2066,9 +2065,7 @@
             this.$set(
             this.$set(
               this.form.datasource[index],
               this.form.datasource[index],
               'notaxSinglePrice',
               'notaxSinglePrice',
-              parseFloat(
-                (item.singlePrice / (1 + item.taxRate / 100)).toFixed(2)
-              )
+              formatPrice(item.singlePrice / (1 + item.taxRate / 100))
             );
             );
           } else {
           } else {
             this.$set(this.form.datasource[index], 'notaxSinglePrice', '');
             this.$set(this.form.datasource[index], 'notaxSinglePrice', '');
@@ -2114,7 +2111,7 @@
         let num =
         let num =
           (Number(this.form.discountTotalPrice) / Number(this.allPrice)) *
           (Number(this.form.discountTotalPrice) / Number(this.allPrice)) *
           Number(row.singlePrice);
           Number(row.singlePrice);
-        return isNaN(num) ? '' : num;
+        return isNaN(num) ? '' : formatPrice(num);
       },
       },
 
 
       //获取折让比例
       //获取折让比例
@@ -2136,7 +2133,7 @@
         let num = 0;
         let num = 0;
         num =
         num =
           Number(row.discountSinglePrice) * Number(row[this.countObj.countKey]);
           Number(row.discountSinglePrice) * Number(row[this.countObj.countKey]);
-        return isNaN(num) ? '' : num.toFixed(2);
+        return isNaN(num) ? '' : formatPrice(num);
       },
       },
       orderNoChange(row, item) {
       orderNoChange(row, item) {
         row['orderId'] = item.orderId;
         row['orderId'] = item.orderId;

+ 13 - 10
src/BIZComponents/setProduct.js

@@ -1,5 +1,10 @@
 import Vue from 'vue';
 import Vue from 'vue';
 
 
+// 保留指定位数小数并去掉多余的0
+export function formatPrice(price, decimals = 4) {
+  return price.toFixed(decimals).replace(/\.?0+$/, '');
+}
+
 //改变数量
 //改变数量
 export function changeCount(row, countObj, noDiscountSingle, weightType) {
 export function changeCount(row, countObj, noDiscountSingle, weightType) {
   
   
@@ -32,7 +37,7 @@ export function changeCount(row, countObj, noDiscountSingle, weightType) {
   //   ? data.singlePrice
   //   ? data.singlePrice
   //   : data.discountSinglePrice;
   //   : data.discountSinglePrice;
 
 
-  data['discountSinglePrice'] = data.singlePrice && data.discountRatio ? (+data.singlePrice * (+data.discountRatio /100)).toFixed(2) : data.singlePrice;
+  data['discountSinglePrice'] = data.singlePrice && data.discountRatio ? formatPrice(+data.singlePrice * (+data.discountRatio /100)) : data.singlePrice;
   // console.log('discountSinglePrice~~~', data.singlePrice, data.discountRatio);
   // console.log('discountSinglePrice~~~', data.singlePrice, data.discountRatio);
 
 
   if (weightType == 'totalWeight') {
   if (weightType == 'totalWeight') {
@@ -47,19 +52,17 @@ export function changeCount(row, countObj, noDiscountSingle, weightType) {
   data['discountTotalPrice'] = 0;
   data['discountTotalPrice'] = 0;
   if (data.pricingWay == 2 || data.pricingWay == 3) {
   if (data.pricingWay == 2 || data.pricingWay == 3) {
     if (data.totalWeight && data.singlePrice) {
     if (data.totalWeight && data.singlePrice) {
-      data['totalPrice'] = (data.totalWeight * data.singlePrice).toFixed(2);
+      data['totalPrice'] = formatPrice(data.totalWeight * data.singlePrice);
     }
     }
   } else {
   } else {
     if (data[countObj.countKey] && data.singlePrice) {
     if (data[countObj.countKey] && data.singlePrice) {
-      data['totalPrice'] = (data[countObj.countKey] * data.singlePrice).toFixed(
-        2
-      );
+      data['totalPrice'] = formatPrice(data[countObj.countKey] * data.singlePrice);
     }
     }
   }
   }
   // data['discountTotalPrice'] = !noDiscountSingle
   // data['discountTotalPrice'] = !noDiscountSingle
   //   ? data.totalPrice
   //   ? data.totalPrice
   //   : data.discountTotalPrice;
   //   : data.discountTotalPrice;
-  data['discountTotalPrice'] = data['totalPrice'] && data.discountRatio ? (data['totalPrice'] * (data.discountRatio /100)).toFixed(2) : data['totalPrice'];
+  data['discountTotalPrice'] = data['totalPrice'] && data.discountRatio ? formatPrice(+data['totalPrice'] * (data.discountRatio /100)) : data['totalPrice'];
   return data;
   return data;
 }
 }
 // 计算总重
 // 计算总重
@@ -125,7 +128,7 @@ export function getAllPrice(arr) {
       sum += Number(item.totalPrice);
       sum += Number(item.totalPrice);
     }
     }
   });
   });
-  return isNaN(sum) ? 0 : sum.toFixed(2);
+  return isNaN(sum) ? 0 : formatPrice(sum);
 }
 }
 
 
 // 获取优惠后总金额
 // 获取优惠后总金额
@@ -136,7 +139,7 @@ export function getAllDiscountPrice(arr) {
       sum += Number(item.discountTotalPrice);
       sum += Number(item.discountTotalPrice);
     }
     }
   });
   });
-  return isNaN(sum) ? 0 : sum.toFixed(2);
+  return isNaN(sum) ? 0 : formatPrice(sum);
 }
 }
 
 
 //获取折让合计
 //获取折让合计
@@ -144,7 +147,7 @@ export function getDiscountTotalPrice(row) {
   let num = 0;
   let num = 0;
   num =
   num =
     Number(row.discountSinglePrice) * Number(row[countObj.countKey]);
     Number(row.discountSinglePrice) * Number(row[countObj.countKey]);
-  return isNaN(num) ? '' : num.toFixed(2);
+  return isNaN(num) ? '' : formatPrice(num);
 }
 }
 
 
 //获取折让单价
 //获取折让单价
@@ -152,7 +155,7 @@ export function getDiscountSinglePrice(row) {
   let num =
   let num =
     Number(row.discountTotalPrice) *
     Number(row.discountTotalPrice) *
     Number(row[countObj.countKey]);
     Number(row[countObj.countKey]);
-  return isNaN(num) ? '' : num.toFixed(2);
+  return isNaN(num) ? '' : formatPrice(num);
 }
 }
 // //计算不含税单价
 // //计算不含税单价
 // function getNotaxSinglePrice(row) {
 // function getNotaxSinglePrice(row) {

+ 5 - 4
src/views/purchasingManage/purchaseOrder/components/inventoryTableNew.vue

@@ -121,7 +121,7 @@
           style="margin-bottom: 20px"
           style="margin-bottom: 20px"
           :prop="'datasource.' + scope.$index + '.totalPrice'"
           :prop="'datasource.' + scope.$index + '.totalPrice'"
         >
         >
-          {{ (Number(scope.row.totalPrice) || 0).toFixed(2) }}元
+          {{ formatPrice(Number(scope.row.totalPrice) || 0) }}元
         </el-form-item>
         </el-form-item>
       </template>
       </template>
 
 
@@ -638,7 +638,7 @@
   import tabMixins from '@/mixins/tableColumnsMixin';
   import tabMixins from '@/mixins/tableColumnsMixin';
   import { levelList, quoteTypeOp } from '@/enum/dict.js';
   import { levelList, quoteTypeOp } from '@/enum/dict.js';
   import { getGoodsPriceByCondition } from '@/api/goodsManage/index';
   import { getGoodsPriceByCondition } from '@/api/goodsManage/index';
-  import { changeCount, getAllPrice, getAllDiscountPrice } from '@/BIZComponents/setProduct.js';
+  import { changeCount, getAllPrice, getAllDiscountPrice, formatPrice } from '@/BIZComponents/setProduct.js';
   import { queryHistoricalUnitPrice } from '@/api/purchasingManage/purchaseOrder';
   import { queryHistoricalUnitPrice } from '@/api/purchasingManage/purchaseOrder';
   const dayjs = require('dayjs');
   const dayjs = require('dayjs');
 
 
@@ -1140,6 +1140,7 @@
       this.requestDict('商品价格类型');
       this.requestDict('商品价格类型');
     },
     },
     methods: {
     methods: {
+      formatPrice,
       async getPurchaseSinglePrice(row) {
       async getPurchaseSinglePrice(row) {
         this.purchaseSinglePriceData = [];
         this.purchaseSinglePriceData = [];
         this.purchaseSinglePriceData = await queryHistoricalUnitPrice(
         this.purchaseSinglePriceData = await queryHistoricalUnitPrice(
@@ -1282,8 +1283,8 @@
             this.$set(
             this.$set(
               this.form.datasource[index],
               this.form.datasource[index],
               'notaxSinglePrice',
               'notaxSinglePrice',
-              parseFloat(
-                (item.singlePrice / (1 + item.taxRate / 100)).toFixed(2)
+              formatPrice(
+                item.singlePrice / (1 + item.taxRate / 100)
               )
               )
             );
             );
           } else {
           } else {

+ 3 - 3
src/views/purchasingManage/purchaseOrder/invoice/components/inventoryTable.vue

@@ -424,7 +424,7 @@
   import productListMain from '@/BIZComponents/product-list.vue';
   import productListMain from '@/BIZComponents/product-list.vue';
   import warehouseAll from '@/BIZComponents/warehouseAll.vue';
   import warehouseAll from '@/BIZComponents/warehouseAll.vue';
   import { levelList } from '@/enum/dict.js';
   import { levelList } from '@/enum/dict.js';
-  import { changeCount, getAllPrice } from '@/BIZComponents/setProduct.js';
+  import { changeCount, getAllPrice, formatPrice } from '@/BIZComponents/setProduct.js';
 
 
   const dayjs = require('dayjs');
   const dayjs = require('dayjs');
 
 
@@ -1032,8 +1032,8 @@
             this.$set(
             this.$set(
               this.form.datasource[index],
               this.form.datasource[index],
               'notaxSinglePrice',
               'notaxSinglePrice',
-              parseFloat(
-                (item.singlePrice / (1 + item.taxRate / 100)).toFixed(2)
+              formatPrice(
+                item.singlePrice / (1 + item.taxRate / 100)
               )
               )
             );
             );
           } else {
           } else {

+ 3 - 4
src/views/saleManage/saleOrder/invoice/components/inventoryTable.vue

@@ -458,7 +458,7 @@
   import BIZproductList from '@/BIZComponents/product-list.vue';
   import BIZproductList from '@/BIZComponents/product-list.vue';
   import tabMixins from '@/mixins/tableColumnsMixin';
   import tabMixins from '@/mixins/tableColumnsMixin';
   import { levelList, pricingWayList, lbjtList } from '@/enum/dict.js';
   import { levelList, pricingWayList, lbjtList } from '@/enum/dict.js';
-  import { changeCount } from '@/BIZComponents/setProduct.js';
+  import { changeCount, formatPrice } from '@/BIZComponents/setProduct.js';
   import { parameterGetByCode } from '@/api/main/index.js';
   import { parameterGetByCode } from '@/api/main/index.js';
   import { getSummaries } from '@/utils/util.js';
   import { getSummaries } from '@/utils/util.js';
   import { getBatchList } from '@/api/wms';
   import { getBatchList } from '@/api/wms';
@@ -1002,6 +1002,7 @@
       // this.clientEnvironmentId =
       // this.clientEnvironmentId =
     },
     },
     methods: {
     methods: {
+      formatPrice,
       getSummaries(param) {
       getSummaries(param) {
         if (this.clientEnvironmentId != 4) {
         if (this.clientEnvironmentId != 4) {
           return;
           return;
@@ -1219,9 +1220,7 @@
             this.$set(
             this.$set(
               this.form.datasource[index],
               this.form.datasource[index],
               'notaxSinglePrice',
               'notaxSinglePrice',
-              parseFloat(
-                (item.singlePrice / (1 + item.taxRate / 100)).toFixed(2)
-              )
+              formatPrice(item.singlePrice / (1 + item.taxRate / 100))
             );
             );
           } else {
           } else {
             this.$set(this.form.datasource[index], 'notaxSinglePrice', '');
             this.$set(this.form.datasource[index], 'notaxSinglePrice', '');