feat(stocktake): 重复扫码提示并确认是否修改
问题: 同一个码扫两遍输入两个数,后端 draft/add 直接覆盖,无任何提示 可能误改已盘数量 改进: - 后端 draft/list 支持 uuid 过滤,可精确查某物料是否已盘 - 扫码弹输入框前,先精确查询该物料是否已盘 - 已盘过 → 弹窗提示『当前实盘为 X,是否修改?』 确认后预填旧值供修改,取消则不改变
This commit is contained in:
@ -861,15 +861,58 @@ const handleManualInput = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const openQtyDialog = (item: StockItem) => {
|
||||
currentItem.value = item
|
||||
inputQty.value = item.scanned ? item.qty_actual : 1
|
||||
showQtyDialog.value = true
|
||||
const openQtyDialog = async (item: StockItem) => {
|
||||
// ★ 重复扫码检测:精确查该物料是否已在本 session 盘过
|
||||
let existingQty: number | null = null
|
||||
try {
|
||||
const uuidForQuery = item.uuid || item.sku || ''
|
||||
const dupRes: any = await request({
|
||||
url: '/v1/inbound/stock/draft/list',
|
||||
method: 'get',
|
||||
params: { session_id: currentSessionId.value, uuid: uuidForQuery, limit: 1 }
|
||||
})
|
||||
const dupItems = dupRes?.items || dupRes?.data?.items || []
|
||||
if (dupItems.length > 0 && dupItems[0].quantity !== undefined) {
|
||||
existingQty = Number(dupItems[0].quantity)
|
||||
}
|
||||
} catch (e) {
|
||||
// 查询失败不阻断,视为未盘过
|
||||
}
|
||||
|
||||
nextTick(() => {
|
||||
const inputEl = document.querySelector('.qty-dialog input') as HTMLInputElement
|
||||
if(inputEl) inputEl.focus()
|
||||
})
|
||||
if (existingQty !== null) {
|
||||
// 已盘过 → 提示当前值,询问是否修改
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`⚠️ 【${item.name} × ${item.standard}】已盘过,当前实盘为 ${existingQty}。\n\n是否修改本次盘点的数量?`,
|
||||
'重复扫码提示',
|
||||
{
|
||||
confirmButtonText: '修改数量',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}
|
||||
)
|
||||
// 用户确认修改 → 预填当前值,弹输入框
|
||||
currentItem.value = item
|
||||
inputQty.value = existingQty || 1
|
||||
showQtyDialog.value = true
|
||||
nextTick(() => {
|
||||
const inputEl = document.querySelector('.qty-dialog input') as HTMLInputElement
|
||||
if(inputEl) inputEl.focus()
|
||||
})
|
||||
} catch (e) {
|
||||
// 用户取消,不修改
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// 未盘过 → 正常弹输入框
|
||||
currentItem.value = item
|
||||
inputQty.value = item.scanned ? item.qty_actual : 1
|
||||
showQtyDialog.value = true
|
||||
nextTick(() => {
|
||||
const inputEl = document.querySelector('.qty-dialog input') as HTMLInputElement
|
||||
if(inputEl) inputEl.focus()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const handleManualConfirm = () => {
|
||||
|
||||
Reference in New Issue
Block a user