Jelajahi Sumber

修复BOM用量和材料定额输入非法字符会报错

695593266@qq.com 10 bulan lalu
induk
melakukan
09eb98eb3a

+ 22 - 3
src/views/material/BOMmanage/components/detailedList.vue

@@ -61,7 +61,8 @@
           v-model="row.dosage"
           placeholder="请输入"
           size="mini"
-          style="width: 68px"
+          style="width: 90px"
+          @input="handleInput(row)"
         >
         </el-input>
       </template>
@@ -666,6 +667,26 @@
         }
       },
 
+      handleInput(item) {
+        let newVal = item.dosage.replace(/[^\d.]/g, '');
+
+        // 2. 不能以点开头
+        if (newVal.startsWith('.')) {
+          newVal = '';
+        }
+
+        // 3. 只允许出现一个小数点
+        const firstDotIndex = newVal.indexOf('.');
+        if (firstDotIndex !== -1) {
+          newVal =
+            newVal.slice(0, firstDotIndex + 1) +
+            newVal.slice(firstDotIndex + 1).replace(/\./g, '');
+        }
+
+        // 4. 更新数据
+        item.dosage = newVal;
+      },
+
       factoriesFn(code) {
         this.isId = code;
         this.$refs.clientSelectionRef.open();
@@ -815,8 +836,6 @@
           status: 1
         };
         contactList(param).then((res) => {
-          console.log(res, 'res11111111111');
-
           this.gysList = res.list;
         });
       },

+ 22 - 7
src/views/material/BOMmanage/components/workingProcedure.vue

@@ -511,13 +511,8 @@
                 v-else
                 v-model="row.count"
                 placeholder="请输入"
-                @input="
-                  (value) =>
-                    (row.count = value.replace(
-                      /^(-)*(\d+)\.(\d\d\d\d\d\d).*$/,
-                      '$1$2.$3'
-                    ))
-                "
+                style="width: 90px"
+                @input="handleInput(row)"
               ></el-input>
             </template>
 
@@ -1218,6 +1213,26 @@
         console.log(this.unitList, 'this.unitList');
       },
 
+      handleInput(item) {
+        let newVal = item.count.replace(/[^\d.]/g, '');
+
+        // 2. 不能以点开头
+        if (newVal.startsWith('.')) {
+          newVal = '';
+        }
+
+        // 3. 只允许出现一个小数点
+        const firstDotIndex = newVal.indexOf('.');
+        if (firstDotIndex !== -1) {
+          newVal =
+            newVal.slice(0, firstDotIndex + 1) +
+            newVal.slice(firstDotIndex + 1).replace(/\./g, '');
+        }
+
+        // 4. 更新数据
+        item.count = newVal;
+      },
+
       async detailsList() {
         console.log(this.rowData, 'this.rowData');
         await getDetailList({