This commit is contained in:
bb_pan 2025-12-19 11:26:36 +08:00
parent 8ff796775e
commit 0f571eabc8
3 changed files with 49 additions and 4 deletions

View File

@ -315,3 +315,33 @@ export async function downloadPDF(options) {
modal?.closeLoading?.()
}
}
/**
* 正数输入处理
* @param {string | number} value 输入值
* @param {number} decimal 最多保留的小数位默认不限制
*/
export function handlePositiveNumberInput(value, decimal = Infinity) {
let val = String(value ?? '')
// 1⃣ 只保留数字和 .
val = val.replace(/[^\d.]/g, '')
// 2⃣ 只保留第一个小数点
const dotIndex = val.indexOf('.')
if (dotIndex !== -1) {
val = val.slice(0, dotIndex + 1) + val.slice(dotIndex + 1).replace(/\./g, '')
}
// 3⃣ 限制小数位数(可配置)
if (dotIndex !== -1 && Number.isFinite(decimal)) {
val = val.slice(0, dotIndex + decimal + 1)
}
// 4⃣ ".5" → "0.5"
if (val.startsWith('.')) {
val = '0' + val
}
return val
}

View File

@ -344,6 +344,7 @@ import {
import { getManufacturerSelectApi } from '@/api/EquipmentLedger/index.js'
import ImageUpload from '@/components/ImageUpload'
import FileUpload from '@/components/FileImageUpload'
import { handlePositiveNumberInput } from '@/utils/bonus.js'
export default {
name: 'EquipmentEntryEditDialog', //
@ -536,10 +537,11 @@ export default {
},
//
handlePriceInput(v) {
this.form.originalValue = this.form.originalValue
.replace(/[^\d.]/g, '') //
.replace(/\.{2,}/g, '.') // ->
.replace(/^(\d+)\.(.*)\./, '$1.$2'); //
this.form.originalValue = handlePositiveNumberInput(this.form.originalValue)
// this.form.originalValue = this.form.originalValue
// .replace(/[^\d.]/g, '') //
// .replace(/\.{2,}/g, '.') // ->
// .replace(/^(\d+)\.(.*)\./, '$1.$2'); //
},
//
handleImageChange(files) {

View File

@ -116,6 +116,7 @@
style="width: 105px"
placeholder="请输入"
v-model.trim="queryParams.minBuyPrice"
@input="handleNumber('min')"
/>
</el-form-item>
@ -125,6 +126,7 @@
style="width: 105px"
placeholder="请输入"
v-model.trim="queryParams.maxBuyPrice"
@change="handleNumber('max')"
/>
</el-form-item>
@ -304,6 +306,7 @@ import {
equipmentPassAndRejectApiNew
} from '@/api/EquipmentEntryApply/index'
import { getManufacturerSelectApi } from '@/api/EquipmentLedger/index.js'
import { handlePositiveNumberInput } from '@/utils/bonus'
export default {
name: 'EquipmentDetailList',
@ -384,6 +387,16 @@ export default {
}
})
},
handleNumber(key) {
if (key === 'min') {
this.queryParams.minBuyPrice = handlePositiveNumberInput(this.queryParams.minBuyPrice)
} else if (key === 'max') {
this.queryParams.maxBuyPrice = handlePositiveNumberInput(this.queryParams.maxBuyPrice)
}
if (Number(this.queryParams.minBuyPrice) > Number(this.queryParams.maxBuyPrice) && this.queryParams.maxBuyPrice) {
this.queryParams.minBuyPrice = this.queryParams.maxBuyPrice
}
},
/**
* 获取装备申请列表
*/