Browse Source

景聚庭-页面库存展示调整,限制小数输入

huangguoce 3 weeks atrás
parent
commit
4dbe9e4da7

File diff suppressed because it is too large
+ 703 - 679
pages/psiManagement/collect/CollectForm.vue


+ 19 - 13
pages/psiManagement/loss/LossForm.vue

@@ -63,7 +63,8 @@
                     </u-form-item>
                     <u-form-item label="报损数量" :prop="'detailInfos[' + index + '].lossNumber'" :required="true">
                         <u--input v-model="inputForm.detailInfos[index].lossNumber" placeholder="请输入报损数量"
-                            :disabled="nodeFlag" @blur="handleLossNumberBlur(index)"></u--input>
+                            type="number" :disabled="nodeFlag" @input="handleLossNumberInput(index)"
+                            @blur="handleLossNumberBlur(index)"></u--input>
                     </u-form-item>
                     <u-form-item label="报损原因" :prop="'detailInfos[' + index + '].lossReason'" :required="true">
                         <u--textarea v-model="inputForm.detailInfos[index].lossReason" placeholder="请输入报损原因"
@@ -378,28 +379,22 @@ export default {
             }
             return this.formatNumber(current * (specNumber > 0 ? specNumber : 1))
         },
-        formatNumberInput(inputValue, decimalLimit = 2) {
+        formatNumberInput(inputValue) {
             if (this.isEmpty(inputValue)) {
                 return ''
             }
-            const valueText = String(inputValue)
-            if (!/^\d*\.?\d*$/.test(valueText)) {
+            let value = String(inputValue).replace(/[^\d.]/g, '')
+            if (value.endsWith('.')) {
                 return ''
             }
-            let value = valueText.replace(/[^\d.]/g, '')
             const dotIndex = value.indexOf('.')
             if (dotIndex !== -1) {
-                const substr = value.substr(dotIndex + 1)
-                if (substr.indexOf('.') !== -1) {
-                    value = value.substr(0, dotIndex + 1) + substr.replace(/\./g, '')
-                }
-            }
-            if (dotIndex !== -1) {
                 const integerPart = value.substring(0, dotIndex)
-                const decimalPart = value.substring(dotIndex + 1, dotIndex + 1 + decimalLimit)
+                const decimalPart = value.substring(dotIndex + 1).replace(/\./g, '').replace(/[1-9]/g, '')
                 value = integerPart + '.' + decimalPart
             }
-            return value
+            value = value.replace(/^0+(\d)/, '$1')
+            return value === '.' ? '' : value
         },
         addDetail() {
             this.inputForm.detailInfos.push(this.createDetailRow())
@@ -529,6 +524,13 @@ export default {
                 detail.lossNumber = ''
             }
         },
+        handleLossNumberInput(index) {
+            const detail = (this.inputForm.detailInfos || [])[index]
+            if (!detail) {
+                return
+            }
+            detail.lossNumber = this.formatNumberInput(detail.lossNumber)
+        },
         validateDetailInfos(checkStock = true) {
             if (this.isEmpty(this.inputForm.detailInfos)) {
                 this.$message.error('请填写报损明细')
@@ -557,6 +559,10 @@ export default {
                     this.$message.error(`报损明细第${lineNo}行请输入报损数量`)
                     return false
                 }
+                if (!/^[1-9]\d*(?:\.0+)?$/.test(String(detail.lossNumber))) {
+                    this.$message.error(`报损明细第${lineNo}行报损数量请输入正整数`)
+                    return false
+                }
                 if (this.isEmpty(detail.lossReason)) {
                     this.$message.error(`报损明细第${lineNo}行请输入报损原因`)
                     return false

+ 18 - 3
pages/psiManagement/wareHouse/WareHouseAddForm.vue

@@ -108,7 +108,8 @@
                         @selected="handleGoodsSelected"></psi-goods-selector>
 						<u-form-item label="入库数量" :prop="'wareHouse[' + index + '].tradeNumber'" :required="true"  labelWidth="68px">
 						    <u--input v-model="inputForm.wareHouse[index].tradeNumber" placeholder="请输入入库数量"
-						        :disabled="nodeFlag" @blur="onRowInputBlur(index, 'tradeNumber')"></u--input>
+						        type="number" :disabled="nodeFlag" @input="onRowInputBlur(index, 'tradeNumber')"
+						        @blur="onRowInputBlur(index, 'tradeNumber')"></u--input>
 						</u-form-item>
 
                     <u-form-item label="品牌" :prop="'wareHouse[' + index + '].brand'" labelWidth="44px">
@@ -620,7 +621,9 @@ export default {
                 return
             }
             let value = row[field]
-            if (['tradeNumber', 'tradePrice', 'actualPrice'].includes(field)) {
+            if (field === 'tradeNumber') {
+                value = this.formatIntegerInput(value)
+            } else if (['tradePrice', 'actualPrice'].includes(field)) {
                 value = this.formatNumberInput(value)
             }
             if (field === 'spec') {
@@ -659,7 +662,15 @@ export default {
             if (this.isEmpty(inputValue)) {
                 return ''
             }
-            return String(inputValue).replace(/[^\d]/g, '')
+            let value = String(inputValue).replace(/[^\d.]/g, '')
+            const dotIndex = value.indexOf('.')
+            if (dotIndex !== -1) {
+                const integerPart = value.substring(0, dotIndex)
+                const decimalPart = value.substring(dotIndex + 1).replace(/\./g, '').replace(/[1-9]/g, '')
+                value = integerPart + '.' + decimalPart
+            }
+            value = value.replace(/^0+(\d)/, '$1')
+            return value === '.' ? '' : value
         },
         handleUploadSuccess(file, fileList, index, type) {
             if (type === 'detail') {
@@ -737,6 +748,10 @@ export default {
                     this.$message.error(`入库详情第${lineNo}行请填写商品数量`)
                     return false
                 }
+                if (!/^[1-9]\d*(?:\.0+)?$/.test(String(row.tradeNumber))) {
+                    this.$message.error(`入库详情第${lineNo}行入库数量请输入正整数`)
+                    return false
+                }
                 if (this.isEmpty(row.spec)) {
                     this.$message.error(`入库详情第${lineNo}行请填写包装规格`)
                     return false

+ 18 - 3
pages/psiManagement/wareHouse/WareHouseUpdateForm.vue

@@ -101,7 +101,8 @@
 						:show-stock="true" :disabled="nodeFlag" @selected="handleGoodsSelected"></psi-goods-selector>
 					<u-form-item label="商品数量" :prop="'wareHouse[' + index + '].tradeNumber'" :required="true" labelWidth="68px">
 						<u--input v-model="inputForm.wareHouse[index].tradeNumber" placeholder="请输入商品数量"
-							:disabled="nodeFlag" @blur="onRowInputBlur(index, 'tradeNumber')"></u--input>
+							type="number" :disabled="nodeFlag" @input="onRowInputBlur(index, 'tradeNumber')"
+							@blur="onRowInputBlur(index, 'tradeNumber')"></u--input>
 					</u-form-item>
 					<u-form-item label="品牌" :prop="'wareHouse[' + index + '].brand'" labelWidth="44px">
 						<u--input v-model="inputForm.wareHouse[index].brand" disabled></u--input>
@@ -736,7 +737,9 @@
 					return
 				}
 				let value = row[field]
-				if (['tradeNumber', 'tradePrice', 'actualPrice'].includes(field)) {
+				if (field === 'tradeNumber') {
+					value = this.formatIntegerInput(value)
+				} else if (['tradePrice', 'actualPrice'].includes(field)) {
 					value = this.formatNumberInput(value)
 				}
 				if (field === 'spec') {
@@ -773,7 +776,15 @@
 				if (this.isEmpty(inputValue)) {
 					return ''
 				}
-				return String(inputValue).replace(/[^\d]/g, '')
+				let value = String(inputValue).replace(/[^\d.]/g, '')
+				const dotIndex = value.indexOf('.')
+				if (dotIndex !== -1) {
+					const integerPart = value.substring(0, dotIndex)
+					const decimalPart = value.substring(dotIndex + 1).replace(/\./g, '').replace(/[1-9]/g, '')
+					value = integerPart + '.' + decimalPart
+				}
+				value = value.replace(/^0+(\d)/, '$1')
+				return value === '.' ? '' : value
 			},
 			handleUploadSuccess(file, fileList, index, type) {
 				if (type === 'detail') {
@@ -868,6 +879,10 @@
 						this.$message.error(`入库详情第${lineNo}行请填写商品数量`)
 						return false
 					}
+					if (!/^[1-9]\d*(?:\.0+)?$/.test(String(row.tradeNumber))) {
+						this.$message.error(`入库详情第${lineNo}行商品数量请输入正整数`)
+						return false
+					}
 				}
 				for (let i = 0; i < rows.length; i++) {
 					for (let j = i + 1; j < rows.length; j++) {