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