feat: 拆包扫码商品模式增加一次性数量输入框(默认1,用后重置)
This commit is contained in:
parent
3494d6b2a7
commit
2dcf4de60a
@ -37,15 +37,28 @@
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="商品条码">
|
||||
<el-input
|
||||
ref="detailBarcodeRef"
|
||||
v-model="detailBarcode"
|
||||
placeholder="扫描条码(自动查询添加)"
|
||||
clearable
|
||||
:disabled="!createResult?.id"
|
||||
@keyup.enter="() => handleBarcodeQuickAdd()"
|
||||
@change="() => handleBarcodeQuickAdd()"
|
||||
/>
|
||||
<div class="barcode-row">
|
||||
<el-input
|
||||
ref="detailBarcodeRef"
|
||||
v-model="detailBarcode"
|
||||
placeholder="扫描条码(自动查询添加)"
|
||||
clearable
|
||||
:disabled="!createResult?.id"
|
||||
@keyup.enter="() => handleBarcodeQuickAdd()"
|
||||
@change="() => handleBarcodeQuickAdd()"
|
||||
/>
|
||||
<el-input-number
|
||||
v-model="scanQty"
|
||||
:min="1"
|
||||
:max="999"
|
||||
:controls="true"
|
||||
controls-position="right"
|
||||
size="small"
|
||||
class="barcode-qty-input"
|
||||
:disabled="!createResult?.id"
|
||||
title="本次扫码录入数量(一次性使用,扫描后自动重置为1)"
|
||||
/>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="createResult?.id" label="货主">
|
||||
<el-select
|
||||
@ -539,6 +552,8 @@ const savingDetailId = ref<number | null>(null)
|
||||
// 左侧快速添加
|
||||
const detailBarcode = ref('')
|
||||
const detailBarcodeRef = ref<any>(null)
|
||||
/** 本次扫码录入数量(一次性使用,扫描后重置为 1) */
|
||||
const scanQty = ref(1)
|
||||
const quickAddLoading = ref(false)
|
||||
const quickAddPickerVisible = ref(false)
|
||||
const quickAddKeyword = ref('')
|
||||
@ -1035,55 +1050,68 @@ async function findSameStockDetail(stockId: number, productStatus?: string): Pro
|
||||
return null
|
||||
}
|
||||
|
||||
/** 扫码数量校验:仅接受数字,取整并限制在 1~999 */
|
||||
function normalizeScanQty(): number {
|
||||
const n = Number(scanQty.value)
|
||||
if (!Number.isFinite(n) || n < 1) return 1
|
||||
return Math.min(999, Math.floor(n))
|
||||
}
|
||||
|
||||
async function quickAddDetail(item: any) {
|
||||
const unpackId = createResult.value?.id
|
||||
if (!unpackId) return
|
||||
// 数量一次性使用:本次扫码使用当前数量,结束后重置为 1
|
||||
const qty = normalizeScanQty()
|
||||
const scannedBarcode = String(detailBarcode.value ?? '').trim()
|
||||
// 兼容商品搜索行(item_id)与商品选择弹窗返回项(id)两种字段
|
||||
const rawStockId = item?.item_id ?? item?.id
|
||||
const stockId = rawStockId != null ? Number(rawStockId) : null
|
||||
// 相同商品且相同产品状态才累加数量
|
||||
const existing = stockId != null ? await findSameStockDetail(stockId, defaultProductStatus.value) : null
|
||||
if (existing) {
|
||||
const res: any = await returnUnpackUpdateDetail({
|
||||
try {
|
||||
// 相同商品且相同产品状态才累加数量
|
||||
const existing = stockId != null ? await findSameStockDetail(stockId, defaultProductStatus.value) : null
|
||||
if (existing) {
|
||||
const res: any = await returnUnpackUpdateDetail({
|
||||
id: unpackId,
|
||||
detail_id: existing.id,
|
||||
quantity: Number(existing.quantity || 0) + qty,
|
||||
})
|
||||
if (isOk(res)) {
|
||||
detailBarcode.value = ''
|
||||
if (scannedBarcode) lastScannedBarcode.value = scannedBarcode
|
||||
void pushOsdText()
|
||||
ElMessage.success(`相同商品数量已累加 ${qty}`)
|
||||
loadDetailList()
|
||||
focusTarget.value = 'barcode'
|
||||
nextTick(() => {
|
||||
detailBarcodeRef.value?.focus()
|
||||
})
|
||||
} else {
|
||||
ElMessage.error(res?.message || '明细累加失败')
|
||||
}
|
||||
return
|
||||
}
|
||||
const res: any = await returnUnpackAddDetail({
|
||||
id: unpackId,
|
||||
detail_id: existing.id,
|
||||
quantity: Number(existing.quantity || 0) + 1,
|
||||
stock_id: stockId,
|
||||
barcode: String(detailBarcode.value ?? '').trim() || undefined,
|
||||
quantity: qty,
|
||||
product_status: defaultProductStatus.value,
|
||||
})
|
||||
if (isOk(res)) {
|
||||
detailBarcode.value = ''
|
||||
if (scannedBarcode) lastScannedBarcode.value = scannedBarcode
|
||||
void pushOsdText()
|
||||
ElMessage.success('相同商品数量已累加')
|
||||
ElMessage.success(stockId == null ? '未找到匹配商品,已按未识别商品登记' : '明细添加成功')
|
||||
loadDetailList()
|
||||
focusTarget.value = 'barcode'
|
||||
nextTick(() => {
|
||||
detailBarcodeRef.value?.focus()
|
||||
})
|
||||
} else {
|
||||
ElMessage.error(res?.message || '明细累加失败')
|
||||
ElMessage.error(res?.message || '明细添加失败')
|
||||
}
|
||||
return
|
||||
}
|
||||
const res: any = await returnUnpackAddDetail({
|
||||
id: unpackId,
|
||||
stock_id: stockId,
|
||||
barcode: String(detailBarcode.value ?? '').trim() || undefined,
|
||||
quantity: 1,
|
||||
product_status: defaultProductStatus.value,
|
||||
})
|
||||
if (isOk(res)) {
|
||||
detailBarcode.value = ''
|
||||
if (scannedBarcode) lastScannedBarcode.value = scannedBarcode
|
||||
void pushOsdText()
|
||||
ElMessage.success(stockId == null ? '未找到匹配商品,已按未识别商品登记' : '明细添加成功')
|
||||
loadDetailList()
|
||||
focusTarget.value = 'barcode'
|
||||
nextTick(() => {
|
||||
detailBarcodeRef.value?.focus()
|
||||
})
|
||||
} else {
|
||||
ElMessage.error(res?.message || '明细添加失败')
|
||||
} finally {
|
||||
scanQty.value = 1
|
||||
}
|
||||
}
|
||||
|
||||
@ -2072,6 +2100,22 @@ async function confirmRemoveDetail() {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.barcode-row {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
align-items: center;
|
||||
|
||||
.el-input {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.barcode-qty-input {
|
||||
width: 110px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.right-area {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user