This commit is contained in:
parent
8ff796775e
commit
0f571eabc8
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 获取装备申请列表
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue