Przeglądaj źródła

Merge branch 'master' of http://47.107.245.0:3000/xiongxing/kyj-yanglao-web-new

chenjun 1 miesiąc temu
rodzic
commit
368e421b5f

+ 26 - 4
src/views/warehouses/materialsIn/components/MaterialsInDialog.vue

@@ -119,7 +119,8 @@
         </el-table-column>
         <el-table-column label="入库单价">
           <template #default="{ row }">
-            <el-input v-if="mode !== 'view'" v-model="row.inUnitPrice" @input="() => calcAmount(row)" />
+            <!-- 五位小数 -->
+            <el-input v-if="mode !== 'view'" v-model="row.inUnitPrice" @input="(val) => handleInUnitPriceInput(val, row)" />
             <el-text v-else>{{ row.inUnitPrice }}</el-text>
           </template>
         </el-table-column>
@@ -201,6 +202,15 @@ watch(
   ([val, mode, opened]) => {
     form.value = JSON.parse(JSON.stringify(val || {}))
 
+    // 回填时格式化金额为两位小数
+    if (Array.isArray(form.value.items)) {
+      form.value.items.forEach((item) => {
+        if (item.amount !== undefined && item.amount !== null) {
+          item.amount = fixedTwoNum(item.amount)
+        }
+      })
+    }
+
     // 新增默认值
     if (opened && mode === 'add') {
       form.value.bizType = 'IN'
@@ -270,14 +280,26 @@ const handleMaterialChange = (value, row) => {
   }
 }
 
+const handleInUnitPriceInput = (val, row) => {
+  // 限制最多五位小数
+  if (val !== '' && val !== null && val !== undefined) {
+    const str = String(val)
+    const dotIndex = str.indexOf('.')
+    if (dotIndex !== -1 && str.length - dotIndex - 1 > 5) {
+      row.inUnitPrice = str.slice(0, dotIndex + 6)
+    }
+  }
+  calcAmount(row)
+}
+
 const calcAmount = (row) => {
   const qty = Number(row.quantity || 0)
   const price = Number(row.inUnitPrice || 0)
   // 保留两位小数
-  row.amount = Number.isFinite(qty * price) ? fixedNum(qty * price) : 0
+  row.amount = Number.isFinite(qty * price) ? fixedTwoNum(qty * price) : 0
 }
 
-const fixedNum = (num) => {
+const fixedTwoNum = (num) => {
   if (num != undefined) {
     return Number(num).toFixed(2)
   }
@@ -296,7 +318,7 @@ const getSummaries = ({ columns, data }) => {
         const value = Number(curr.amount || 0)
         return prev + (Number.isFinite(value) ? value : 0)
       }, 0)
-      sums[index] = fixedNum(total)
+      sums[index] = fixedTwoNum(total)
     } else {
       sums[index] = ''
     }