diff --git a/src/views/EquipmentEntryApply/equipmentInput/index.vue b/src/views/EquipmentEntryApply/equipmentInput/index.vue index f5348bc4..5b8abbb5 100644 --- a/src/views/EquipmentEntryApply/equipmentInput/index.vue +++ b/src/views/EquipmentEntryApply/equipmentInput/index.vue @@ -82,11 +82,11 @@ /> --> - - + + - - + + @@ -726,12 +726,17 @@ export default { originalCode: '', manufacturerId: '', productionDate: '', - minBuyPrice: '', - maxBuyPrice: '', + minOriginalValue: '', + maxOriginalValue: '', pageNum: 1, pageSize: 10, }, + // 用于存储上一次的有效值,避免循环验证 + lastValidValues: { + minOriginalValue: '', + maxOriginalValue: '' + }, currentRow: null, uploadType: 1, // 1:装备外观,2:合格证,3:定期检验报告,4:采购发票 uploadVisible: false, @@ -788,6 +793,117 @@ export default { this.getManufacturerSelectList() }, methods: { + handleNumberInput(key) { + let value = this.queryParams[key] || '' + // 1. 清理输入 + const cleanedValue = this.cleanNumberInput(value) + + // 2. 存储为上次有效值(清理后) + this.lastValidValues[key] = cleanedValue + + // 3. 根据输入类型进行验证 + if (key === 'minOriginalValue') { + this.queryParams[key] = this.validateMinValue(cleanedValue) + } else if (key === 'maxOriginalValue') { + this.queryParams[key] = this.validateMaxValue(cleanedValue) + } else { + this.queryParams[key] = cleanedValue + } + + // 4. 确保响应式更新 + this.$forceUpdate() + }, + + // 清理数字输入 + cleanNumberInput(input) { + if (!input) return '' + + // 过滤非数字和小数点 + let cleaned = input.replace(/[^\d.]/g, '') + + // 处理多个小数点 + const dotIndex = cleaned.indexOf('.') + if (dotIndex !== -1) { + const before = cleaned.substring(0, dotIndex + 1) + const after = cleaned.substring(dotIndex + 1).replace(/\./g, '') + cleaned = before + after + } + + // 限制小数位数 + const parts = cleaned.split('.') + if (parts.length > 1) { + cleaned = parts[0] + '.' + parts[1].slice(0, 2) + } + + return cleaned + }, + + // 验证最小值(不能大于最大值) + validateMinValue(value) { + // 如果是空值或纯小数点,直接返回 + if (!value || value === '.') return value + + const maxValue = this.queryParams.maxOriginalValue + const minNum = this.safeParseNumber(value) + const maxNum = this.safeParseNumber(maxValue) + + // 如果最大值无效,直接返回清理后的值 + if (maxNum === null) return value + + // 如果最小值大于最大值,则使用最大值 + if (minNum !== null && minNum > maxNum) { + return maxValue + } + + return value + }, + + // 验证最大值(不能小于最小值) + validateMaxValue(value) { + // 如果是空值或纯小数点,直接返回 + if (!value || value === '.') return value + + const minValue = this.queryParams.minOriginalValue + const maxNum = this.safeParseNumber(value) + const minNum = this.safeParseNumber(minValue) + + // 如果最小值无效,直接返回清理后的值 + if (minNum === null) return value + + // 如果最大值小于最小值,则使用最小值 + if (maxNum !== null && maxNum < minNum) { + return minValue + } + + return value + }, + + // 安全解析数字 + safeParseNumber(str) { + if (!str || str === '.' || isNaN(Number(str))) { + return null + } + return Number(str) + }, + + // 同时验证两个值(在表单提交前调用) + validateNumberRange() { + const minNum = this.safeParseNumber(this.queryParams.minOriginalValue) + const maxNum = this.safeParseNumber(this.queryParams.maxOriginalValue) + + if (minNum !== null && maxNum !== null && minNum > maxNum) { + // 交换值,使最小值 <= 最大值 + const temp = this.queryParams.minOriginalValue + this.queryParams.minOriginalValue = this.queryParams.maxOriginalValue + this.queryParams.maxOriginalValue = temp + + // 提示用户 + this.$message.warning('已自动调整数值范围,确保最小值 ≤ 最大值') + return false + } + + return true + }, // 文件上传中处理 handleFileUploadProgress(event, file, fileList) { this.upload.isUploading = true @@ -895,6 +1011,7 @@ export default { // 查询表格数据 queryTableList() { + this.validateNumberRange() this.queryParams.pageNum = 1 this.getList() }, diff --git a/src/views/EquipmentEntryApproval/EquipmentDetailList.vue b/src/views/EquipmentEntryApproval/EquipmentDetailList.vue index ad0d7c8e..dffa92dc 100644 --- a/src/views/EquipmentEntryApproval/EquipmentDetailList.vue +++ b/src/views/EquipmentEntryApproval/EquipmentDetailList.vue @@ -9,144 +9,148 @@ > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 查询 - - - 重置 - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + 查询 + + + 重置 + + + + + + + + + + 收起明细 - - + + @@ -178,13 +182,17 @@ - + - + @@ -198,7 +206,9 @@ 查看 - + @@ -265,19 +275,19 @@
- - + +
- +