feat(库存盘点): 添加盘点商品时按任务货主限定只显示该货主的商品

This commit is contained in:
liufumingren 2026-10-09 20:51:56 +08:00
parent 743f714246
commit dbf7654c0b
3 changed files with 92 additions and 8 deletions

View File

@ -235,6 +235,8 @@
:task-id="pickerTaskId"
:task-title="pickerTaskLabel"
:task-type="pickerTaskType"
:task-store-id="pickerTaskStoreId"
:task-store-name="pickerTaskStoreName"
@success="handleItemsAdded"
/>
@ -281,6 +283,7 @@ import {
isCheckApiSuccess,
isLocationScopeType,
loadStoreOptions,
storeOptions,
buildWhereConditions,
type TabPageConfig,
type DetailTabConfig,
@ -866,6 +869,18 @@ const pickerTaskLabel = computed(() => {
if (!task) return ''
return [task.check_no, task.title].filter(Boolean).join(' ')
})
/** 任务货主ID(>0 时「添加盘点商品」弹窗只显示该货主的商品) */
const pickerTaskStoreId = computed(() => Number(pickerTask.value?.store_id) || 0)
/** 任务货主名称(弹窗提示文案;list 行带 store_name,新建后缺失则回查下拉选项) */
const pickerTaskStoreName = computed(() => {
const task = pickerTask.value
if (!task) return ''
const name = String(task.store_name ?? '').trim()
if (name) return name
const id = Number(task.store_id)
if (!id) return ''
return storeOptions.value.find((opt) => Number(opt.value) === id)?.label ?? ''
})
/** 打开「添加盘点商品」(仅 created/rejected 状态可用,后端会再校验) */
function openStockPicker(row: Record<string, any> | null | undefined) {
@ -885,7 +900,14 @@ function handlePanelChanged() {
}
/** 创建成功:刷新列表,并询问是否立即添加盘点商品 / 盘点库位 */
async function handleCreateSuccess(task: { id: number; check_no: string; title: string; type?: string }) {
async function handleCreateSuccess(task: {
id: number
check_no: string
title: string
type?: string
store_id?: number
store_name?: string
}) {
await reloadAndResyncDetail()
if (!task?.id) return
const targetLabel = isLocationScopeType(task.type) ? '盘点库位' : '盘点商品'
@ -898,7 +920,14 @@ async function handleCreateSuccess(task: { id: number; check_no: string; title:
} catch {
return
}
openStockPicker({ id: task.id, check_no: task.check_no, title: task.title, type: task.type })
openStockPicker({
id: task.id,
check_no: task.check_no,
title: task.title,
type: task.type,
store_id: task.store_id,
store_name: task.store_name
})
}
/**

View File

@ -121,8 +121,22 @@ const props = defineProps<{ visible: boolean }>()
const emit = defineEmits<{
(e: 'update:visible', value: boolean): void
/** 创建成功(携创建出的盘点单关键信息;type 用于决定后续添加「商品」还是「库位」) */
(e: 'success', task: { id: number; check_no: string; title: string; type: string }): void
/**
* 创建成功(携创建出的盘点单关键信息)
* - type 用于决定后续添加「商品」还是「库位」
* - store_id/store_name 用于「添加盘点商品」时按货主限定可盘商品
*/
(
e: 'success',
task: {
id: number
check_no: string
title: string
type: string
store_id?: number
store_name?: string
}
): void
}>()
const formRef = ref<FormInstance>()
@ -224,11 +238,22 @@ async function handleSubmit() {
}
const payload: any =
res.data && (res.data.id || res.data.check_no) ? res.data : res
// 货主:创建响应(_formatCheckRow)带 store_id;兜底取表单所选,再用下拉选项补名称
const storeId = Number(payload.store_id ?? form.store_id) || 0
const storeName = storeId
? String(
payload.store_name ??
storeOptions.value.find((opt) => Number(opt.value) === storeId)?.label ??
''
).trim()
: ''
const task = {
id: Number(payload.id) || 0,
check_no: String(payload.check_no ?? ''),
title: String(payload.title ?? form.title ?? ''),
type: String(payload.type ?? form.type ?? '')
type: String(payload.type ?? form.type ?? ''),
store_id: storeId || undefined,
store_name: storeName || undefined
}
ElMessage.success(task.check_no ? `盘点单 ${task.check_no} 创建成功` : '盘点单创建成功')
emit('update:visible', false)

View File

@ -6,6 +6,8 @@
· ⚠️ 服务端按「商品 + 库存库位」**拆行**:一个商品在该仓库的每个**启用库存库位**各生成一条
明细行(location_id/location_code 快照 + 账面取该库位库存),故「新增条数」可能多于所选商品数
· 无启用库存库位的商品不入明细,计入 invalid_stock_ids(提示为「无效商品」)
· **携带货主(taskStoreId>0,即 type=store 的任务)时,库存列表加 where.store_id 限定,
只显示该货主的商品**(与后端 addDetail 的货主一致性校验对齐,避免勾选后被判无效商品)
- 库位类(type=all/location):从库位列表(index.searchSpace)勾选库位 →
· 已勾选库位 → stock.check.addLocationDetail 传 location_ids(库位ID直查,不解析编码)
· 未勾选但手填了库位编码 → stock.check.addDetail 传 locations(兼容通道)
@ -251,6 +253,13 @@ const props = defineProps<{
taskTitle?: string
/** 目标盘点单范围类型(all/location=库位类 → 添加库位;store/goods=商品类 → 添加商品) */
taskType?: string
/**
* 目标盘点单货主ID:>0 时库存列表只显示该货主的商品
* (与后端 addDetail 校验一致——任务 store_id 非空时商品货主必须一致,否则计入 invalid_stock_ids)
*/
taskStoreId?: number | null
/** 目标盘点单货主名称(仅用于提示文案) */
taskStoreName?: string | null
}>()
const emit = defineEmits<{
@ -267,6 +276,18 @@ const dialogTitle = computed(() => {
return isLocationMode.value ? `添加盘点库位${suffix}` : `添加盘点商品${suffix}`
})
/** 任务绑定的货主ID(>0 时仅显示该货主的商品) */
const boundStoreId = computed(() => {
const id = Number(props.taskStoreId)
return Number.isFinite(id) && id > 0 ? id : 0
})
/** 货主展示名:任务名称优先,缺失时退化为「ID x」 */
const boundStoreName = computed(() => {
const name = String(props.taskStoreName ?? '').trim()
return name || `ID ${boundStoreId.value}`
})
// ===== 库位模式:库位选择(多选,主通道) =====
const spaceFilters = reactive({ keyword: '' })
const spaceRows = ref<Record<string, any>[]>([])
@ -316,11 +337,16 @@ const locationAlertText = computed(() =>
* 列表里的库位仅供参考(同一商品可能在多个库位有库存,去重后只传 stock_id),
* 盘点范围由服务端按「该商品在各启用库存库位」展开 → 提示用户「新增条数」可能多于所选商品数。
*/
const goodsAlertText = computed(
() =>
const goodsAlertText = computed(() => {
const scopeTip = boundStoreId.value
? `当前盘点单已指定货主「${boundStoreName.value}」,下方列表只显示该货主的商品;`
: ''
return (
scopeTip +
'按商品添加:系统按该商品在仓库的每个启用库存库位拆成多条明细(一个「商品+库位」= 一条明细行,账面数量取该库位库存)。' +
'下方列表的库位仅供参考、不限制盘点范围;无启用库存库位的商品会被跳过(计入无效商品)。'
)
)
})
/** 库位模式:勾了库位 / 填了库位编码 / all 类型(允许不选=全仓) */
const canSubmit = computed(() => {
@ -434,6 +460,10 @@ async function loadRows() {
const batchNo = filters.batch_no.trim()
const res: any = await getInventoryList({
where: {
// 任务携带货主时限定货主(与后端 addDetail 的货主一致性校验对齐,避免勾选后被判无效商品)
...(boundStoreId.value
? { store_id: { operator: 'eq', value: boundStoreId.value, type: 'number' } }
: {}),
// stock_query 为虚拟筛选字段:按商品编码/名称/条码/SKU ID 模糊匹配
...(keyword ? { stock_query: { operator: 'like', value: keyword } } : {}),
...(batchNo ? { batch_no: batchNo } : {})