diff --git a/src/api/stock.check/stock.check.ts b/src/api/stock.check/stock.check.ts index 84edc1df..e1d14c57 100644 --- a/src/api/stock.check/stock.check.ts +++ b/src/api/stock.check/stock.check.ts @@ -500,18 +500,27 @@ export function stockCheckList( // ============ stock.check.addDetail ============ -/** stock.check.addDetail 请求参数(与任务 type 对齐:商品类传 stock_ids,库位类传 locations) */ +/** stock.check.addDetail 请求参数(与任务 type 对齐:商品类传 stock_ids,库位类传 location_ids/locations) */ export type StockCheckAddDetailParams = { /** 盘点任务ID */ id: number /** * 商品库存ID列表(wms_stock_warehouse.id):type=store/goods 按商品盘点时使用, - * 与 locations 按任务类型二选一 + * 与 location_ids/locations 按任务类型二选一 */ stock_ids?: number[] /** - * 库位编码列表(wms_location_space.space_code):type=all/location 按库位盘点时使用, - * 与 stock_ids 按任务类型二选一;**type=all 未传时由后端自动拉取全仓库启用库位生成盘点范围** + * 库位ID列表(wms_location_space.id):type=all/location 按库位盘点时使用, + * **优先于 locations**(与 locations 同时传时 locations 被忽略), + * 服务端直接按 id + warehouse_id 查库校验,不再按编码二次解析; + * 查不到的 ID 记入 invalid_location_ids(不报错) + */ + location_ids?: number[] + /** 库位ID列表(驼峰别名,兼容写法;location_ids 优先) */ + locationIds?: number[] + /** + * 库位编码列表(wms_location_space.space_code):仅传编码时按 warehouse_id + space_code 匹配, + * 不存在的编码记入 invalid_locations;**type=all 未传库位且未传库位ID时由后端自动拉取全仓库启用库位** */ locations?: string[] /** 库位编码列表(兼容别名;locations 优先,两者都传时以 locations 为准) */ @@ -528,11 +537,22 @@ export type StockCheckAddDetailResponse = { invalid_stock_ids: number[] /** 无效库位编码列表(当前仓库不存在对应库位编码) */ invalid_locations: string[] + /** 无效库位ID列表(按 wms_location_space.id 直查当前仓库不存在) */ + invalid_location_ids: number[] /** 重算后的明细总行数 */ total_items: number } -/** stock.check.addDetail:添加盘点明细(仅 created/rejected 允许;同 stock_id 幂等跳过) */ +/** + * stock.check.addDetail:添加盘点明细(商品或库位,按任务盘点类型决定) + * + * - 仅 created/rejected 允许;stock_ids 与 location_ids/locations 按任务类型二选一 + * (传错维度后端报 400:按库位盘点传 stock_ids / 按商品盘点传 locations 或 location_ids) + * - 已存在同盘点项(商品行 stock_id / 库位行 location_code)自动跳过(幂等) + * - 完成后重算主表 total_items + * + * 注:兼容入口 stock.check.addLocationDetail 是 addDetail 库位ID路径的薄封装,前端无需单独接入。 + */ export function stockCheckAddDetail( data: StockCheckAddDetailParams ): Promise< @@ -553,32 +573,36 @@ export function stockCheckAddDetail( // ============ stock.check.detailDelete ============ -/** stock.check.detailDelete 请求参数 */ +/** stock.check.detailDelete 请求参数(批量;单次上限 200) */ export type StockCheckDetailDeleteParams = { /** 盘点任务ID */ id: number - /** 盘点明细ID(与 detailId 二选一,detail_id 优先) */ + /** 盘点明细ID数组(单次上限 200;优先级 detail_ids > detailIds > detail_id) */ + detail_ids?: number[] + /** 盘点明细ID数组(驼峰别名,兼容写法) */ + detailIds?: number[] + /** 旧版单值写法(自动转数组;detail_ids/detailIds 优先) */ detail_id?: number - /** 盘点明细ID(驼峰别名,兼容写法) */ - detailId?: number } /** stock.check.detailDelete 响应 */ export type StockCheckDetailDeleteResponse = { - /** 被删除的盘点明细ID */ - detail_id: number - /** 是否删除成功 */ - deleted: boolean + /** 实际删除的明细数量 */ + deleted_count: number + /** 实际删除的明细ID列表(保持入参顺序) */ + deleted_ids: number[] + /** 未命中被跳过的明细ID列表(明细不存在或不属于当前仓库,不报错;保持入参顺序) */ + skipped_ids: number[] /** 删除后重算的主表明细总行数 */ total_items: number } /** - * stock.check.detailDelete:删除盘点明细(从任务中移除某个商品) + * stock.check.detailDelete:**批量**删除盘点明细(从任务中移除商品/库位行) * - * - 仅主表状态 created/rejected 允许删除 - * - 该明细若存在作业记录(wms_stock_check_record)会防御性一并删除 - * (正常流程 created/rejected 状态不应有记录) + * - 仅主表状态 created/rejected 允许删除(非该状态报错) + * - 单次最多 200 条;未命中的明细ID计入 skipped_ids(不报错) + * - 命中明细批量删除,并防御性清理 wms_stock_check_record(正常流程该状态不应有记录) * - 删除后服务端重算主表 total_items */ export function stockCheckDetailDelete( diff --git a/src/views/storage/stockcheck/components/LocationPicker.vue b/src/views/storage/stockcheck/components/LocationPicker.vue new file mode 100644 index 00000000..d6a31729 --- /dev/null +++ b/src/views/storage/stockcheck/components/LocationPicker.vue @@ -0,0 +1,564 @@ + + + + + + diff --git a/src/views/storage/stockcheck/config/components/CheckItemsPanel.vue b/src/views/storage/stockcheck/config/components/CheckItemsPanel.vue index c4c1db5b..588f0bb1 100644 --- a/src/views/storage/stockcheck/config/components/CheckItemsPanel.vue +++ b/src/views/storage/stockcheck/config/components/CheckItemsPanel.vue @@ -14,9 +14,11 @@ 上报需带 stock_id → 商品行直接上报;同明细的「明细类型 / 库位」单元格合并显示 2. 盘点作业:行内或批量上报(stock.check.report,**覆盖式**: 商品行=同明细+同库位;库位行=同明细+同商品+同库位,均重复上报为更新) - 3. 完成盘点(stock.check.finish,允许部分未盘完成: + 3. 批量删除明细(stock.check.detailDelete,仅 created/rejected):勾选行按**明细ID**去重提交, + 单次上限 200 条;未命中的明细ID由服务端计入 skipped_ids(不报错) + 4. 完成盘点(stock.check.finish,允许部分未盘完成: 未盘商品明细按实盘 0 计入盘亏与差异行数,未盘库位明细不计差异) - 4. 「添加商品 / 添加库位」交给宿主 index.vue 打开 CheckStockPickerDialog(emit add-items) + 5. 「添加商品 / 添加库位」交给宿主 index.vue 打开 CheckStockPickerDialog(emit add-items) 状态约束(与后端一致): - created/rejected → 可添加明细(addDetail) @@ -33,6 +35,17 @@ {{ isLocationTask ? '添加库位' : '添加商品' }} + + 批量删除明细{{ selectedDetailIds.length ? `(${selectedDetailIds.length})` : '' }} + + + @@ -195,6 +211,7 @@ import { getStatusTextClass } from '@/views/order/orderManagement/config/order-c import { formatTime, isCheckApiSuccess, isLocationScopeType, translate } from '../template-config' import { stockCheckDetail, + stockCheckDetailDelete, stockCheckFinish, stockCheckReport, stockCheckResult, @@ -440,6 +457,8 @@ async function loadItems() { stats.checked = Number(check.checked_items ?? 0) || 0 stats.diff = Number(check.diff_items ?? 0) || 0 resetInputs() + selectedRows.value = [] + nextTick(() => tableRef.value?.clearSelection?.()) page.value = 1 } catch (e: any) { console.error('[stockcheck] 加载盘点明细失败', e) @@ -520,6 +539,72 @@ function resetInputs() { } } +// ============================================================ +// 批量删除明细(stock.check.detailDelete,仅 created/rejected) +// ============================================================ +const selectedRows = ref[]>([]) +const deleting = ref(false) + +/** 选中行对应的明细ID(按明细去重:库位行平铺后同一明细可能对应多行) */ +const selectedDetailIds = computed(() => { + const ids = selectedRows.value.map((row) => + Number(row?.detail_id ?? row?.item?.id ?? row?.id) + ) + return [...new Set(ids.filter((id) => Number.isFinite(id) && id > 0))] +}) + +function handleSelectionChange(rows: Record[]) { + selectedRows.value = Array.isArray(rows) ? rows : [] +} + +/** 批量删除选中的盘点明细(单次上限 200,与后端一致) */ +async function deleteSelected() { + const ids = selectedDetailIds.value + if (!ids.length) { + ElMessage.warning('请先勾选要删除的盘点明细') + return + } + if (ids.length > 200) { + ElMessage.warning(`单次最多删除 200 条明细(已选 ${ids.length} 条),请分批删除`) + return + } + try { + await ElMessageBox.confirm( + `确定删除选中的 ${ids.length} 个盘点明细?删除后需重新添加。`, + '批量删除盘点明细', + { confirmButtonText: '确定删除', cancelButtonText: '取消', type: 'warning' } + ) + } catch { + return + } + + deleting.value = true + try { + const res: any = await stockCheckDetailDelete({ id: taskId.value, detail_ids: ids }) + if (!isCheckApiSuccess(res)) { + throw new Error(res?.message || '删除盘点明细失败') + } + const data = res.data ?? res + const deletedCount = Number(data.deleted_count ?? 0) + const skippedIds: number[] = Array.isArray(data.skipped_ids) ? data.skipped_ids : [] + if (skippedIds.length) { + ElMessage.warning( + `已删除 ${deletedCount} 条明细,跳过 ${skippedIds.length} 条(不存在或不属于当前仓库)` + ) + } else { + ElMessage.success(`已删除 ${deletedCount} 条盘点明细`) + } + // loadItems 内部会重置页码与勾选 + await loadItems() + emit('changed') + } catch (e: any) { + console.error('[stockcheck] 删除盘点明细失败', e) + ElMessage.error(e?.message || '删除盘点明细失败') + } finally { + deleting.value = false + } +} + // ============================================================ // 上报实盘(stock.check.report) // ============================================================ diff --git a/src/views/storage/stockcheck/pages/CheckStockPickerDialog.vue b/src/views/storage/stockcheck/pages/CheckStockPickerDialog.vue index fd9ead76..91ce6414 100644 --- a/src/views/storage/stockcheck/pages/CheckStockPickerDialog.vue +++ b/src/views/storage/stockcheck/pages/CheckStockPickerDialog.vue @@ -3,11 +3,13 @@ 两种模式(由来源盘点单的 type 决定): - 商品类(type=store/goods):从 storage.inventory.list 选商品 → 传 stock_ids - - 库位类(type=all/location):填写/粘贴库位编码(wms_location_space.space_code)→ 传 locations - · type=all 不填库位 = 不传 locations,由后端自动拉取全仓启用库位 + - 库位类(type=all/location):LocationPicker 逐层下拉(仓库 → 库区 → 货架 → 库位)选择 + → 传 **location_ids**(wms_location_space.id,服务端按 id + warehouse_id 直查校验, + 优先于 locations 编码;新契约下不再走编码二次解析) + · type=all 不选库位 = 不传库位/库位ID,由后端自动拉取全仓启用库位 - 响应含 invalid_stock_ids(商品)与 invalid_locations(库位)两类无效项,均需在提示中体现。 - 仅 created(新建)/ rejected(驳回)状态可添加,后端会校验。 + 响应含 invalid_stock_ids(商品)/ invalid_locations(无效编码)/ invalid_location_ids(无效库位ID)三类无效项, + 均需在提示中体现。仅 created(新建)/ rejected(驳回)状态可添加,后端会校验。 --> - + @@ -127,7 +109,7 @@