diff --git a/docs/design/20261023-库存管理列表内联编辑.md b/docs/design/20261023-库存管理列表内联编辑.md
new file mode 100644
index 0000000..d2386f3
--- /dev/null
+++ b/docs/design/20261023-库存管理列表内联编辑.md
@@ -0,0 +1,106 @@
+# 库存管理列表:区域 / 规格 / 单位 / 可用数量 / 成本价 列表内直接改
+
+- 日期:2026-10-23
+- 需求:开发者(附截图)「仓库管理这块 我需要在外面就能修改区域 规格 单位 可用数量(需要是这批的可用数量) 成本价 这块参考我们的客户列表的的效果」
+- 口径:**只是在列表里多一个入口,写路径/权限/留痕一律复用现有的**「修改」弹窗那套接口,不新增接口、不改库存语义。
+
+## 1. 改前事实
+
+| # | 事实 |
+|---|---|
+| F1 | `src/pages/inventory/InventoryManagement.tsx` 列表里「区域编号 / 规格 / 单位 / 可用数量 / 成本价」都是**只读文本**,要改必须点行尾「修改」打开弹窗(`openAdjustModal`)。 |
+| F2 | 弹窗提交分两条既有通道:可用数量 → `POST /inventory/adjust`(`adjustInventoryAvailableApi`,按 **批次 `inventory_id`**);批次属性/成本/商品档案 → `POST /inventory/batch-update`(`updateInventoryBatchApi`)。 |
+| F3 | 客户列表(`src/pages/customers/CustomerManagement.tsx`)的交互是「单元格本身就是输入框,失焦/回车提交、失败回退并 toast」——`CustomerInlineTextCell`。 |
+| F4 | 服务端权限:`batch-update` 需 `inventory_adjust`,且当请求体含 `category_code/spec/unit/origin` 时**另需 `product_manage`**;`/inventory/adjust` 需 `inventory_adjust`。备注为空时服务端补中性标签(`库存批次修改` / `库存调整`),**留痕不留空**。 |
+
+## 2. 交互(对齐客户列表)
+
+- 有权限的账号:这 5 列直接渲染输入框(`InventoryInlineCell`),**失焦或回车提交**;值没变不提交;提交失败 `notify.error` 并把值回退到服务端已知值。
+- 无权限的账号:仍渲染只读文本(与改前一致),不能通过内联入口越权。
+- 提交成功后 **重新拉列表**(`fetchInventory`)——因为「总价值 / 可调配 / 预留占用 / 统计 KPI」是由可用量与成本价派生的,本地 patch 会不一致。
+
+## 3. 字段 ↔ 接口 ↔ 权限
+
+| 列 | 组件形态 | 接口 | 门槛 |
+|---|---|---|---|
+| 区域编号 `storage_zone` | 文本 | `updateInventoryBatchApi` | `inventory_adjust` |
+| 规格 `spec` | 文本 | 同上(写商品档案,影响该 SKU 所有批次) | `inventory_adjust` **+ `product_manage`** |
+| 单位 `unit` | 文本 | 同上 | 同上 |
+| 成本价 `cost_price` | 数字(可空=清空) | 同上(成本改动仍走服务端既有重算) | `inventory_adjust` |
+| 可用数量 `available_qty` | 数字(≥ 0) | `adjustInventoryAvailableApi`(**按本批次 `inventory_id`**) | `inventory_adjust` |
+
+## 4. 校验与留痕
+
+- 可用数量:空 / 非数字 / < 0 ⇒ 抛 `inventory.toast.qtyInvalid`(**与服务端同一句**),不提交。
+- 成本价:空 ⇒ `null`(清空);< 0 ⇒ 拒绝。
+- 备注:内联提交传空串,由服务端补 `库存调整` / `库存批次修改` —— 与弹窗同一口径,**审计与 `inventory_logs` 双写不变**。
+- 成本价联动:仍由服务端 `inventoryBatchCostService` 重算未结算订单,前端只负责刷新列表。
+
+## 5. 非目标
+
+- 不动「修改」弹窗(保留,字段更全:生产日期/保质期/产地/分类等)。
+- 不做行内编辑 生产日期 / 保质期 / 产地 / 分类(弹窗里改)。
+- 不改 FIFO、预留、出库扣减、成本口径——一行未动。
+
+## 6. 验收
+
+1. 有 `inventory_adjust` 的账号在列表里可直接改区域/成本价/可用数量,改完列表数字与总价值同步刷新;
+2. 有 `product_manage` 才能改规格/单位,否则这两列仍是只读;
+3. 审计里能查到每次内联改动(`inventory_batch_edit` / `inventory_adjust`),备注是服务端补的中性标签;
+4. 契约测试:`src/pages/inventory/inventoryInlineEdit.contract.test.ts`(见下方证据)。
+
+## 7. 证据(已回填)
+
+- 契约测试 **6 条全绿**(`src/pages/inventory/inventoryInlineEdit.contract.test.ts`):
+ 五列接线、可用数量按批次 `inventory_id`、`product_manage` 门槛、失败回退与「值未变不提交」、静默刷新、
+ 备注留空(`remark: ''`)走服务端补中性标签。
+- 注入对拍两处:把 `saveInlineAvailableQty` 里的 `inventoryId: item.id` 换成 `item.sku_code` ⇒ **立即变红**;
+ 把 `canInlineEditArchiveFields` 的 `hasPermission('product_manage')` 去掉 ⇒ **立即变红**(均已还原)。
+- `npx tsc --noEmit` 通过(`onClick={fetchInventory}` 同步改成 `onClick={() => void fetchInventory()}`,因为该函数新增了 `{ silent }` 参数)。
+
+## 8. 追加(同日):区域/单位改下拉、数字格去掉 number 步进、按钮改「批量上传报告」
+
+开发者(附两张截图):「上传报告改为批量上传报告 然就我记得区域这个不是选择框吗 单位也是」「成本价这个不能存在滚轮滚动变动价格」。
+
+- **按钮文案**:工具栏那颗按钮改用**新键** `inventory.batchReport.bulkButton` = 「批量上传报告」(en `Upload reports in bulk` / id `Unggah laporan massal`);
+ `inventory.batchReport.button` 保持「上传报告」——它还被**修改弹窗里本批次补充报告**的小链接复用,不能一起改成批量。
+- **区域 / 单位改为下拉选择**(新增 `InventoryInlineSelectCell`):区域选项取页面已加载的 `zoneOptions`(后端 `zones`),
+ 单位选项取 `unitChoices`(`listUnitsApi({ activeOnly: true })`);**当前值不在列表里时自动补进选项**,否则下拉会显示成别的值;
+ 空选项复用既有文案 `adjust.zoneEmpty` / `adjust.unitEmpty`(选空 = 清空该字段,服务端写 NULL)。
+ 单位**不支持就地新建**(新建单位仍在「修改」弹窗里做)。
+- **数字格去掉 `type="number"`**(成本价 / 可用数量):改为 `type="text" inputMode="decimal"`,不再渲染上下箭头,
+ 滚轮/方向键也不会步进改值;校验仍在提交时做(可用量 ≥ 0、成本可空 = 清空、负数由服务端按既有口径拒绝)。
+
+证据:契约测试 **9 条**(新增 3 条:区域/单位走 `InventoryInlineSelectCell` 且当前值不在列表里要补、
+数字格不得出现 `'number'` / `step=`、中文按钮文案);注入对拍:把 `type="text"` 改回 `number` ⇒ **立即变红**;
+把区域/单位换回文本框 ⇒ **立即变红**(均已还原)。
+
+## 9. 追加(同日):区域/单位下拉改用 `SearchableSelect`(限制展开高度)
+
+开发者(附截图,单位下拉一路铺到底):「选择的高度限制一下区域选择与单位选择 高度限制一下」。
+
+原生 `
- {item.category_name}
+ {canInlineEditArchiveFields ? (
+
+ {/* 分类可就地切换(商品档案级,影响该 SKU 所有批次) */}
+
+ saveInlineBatchFields(item, { category_code: next })
+ }
+ />
+
+ ) : (
+ {item.category_name}
+ )}
{reservationGap ? (
{t('inventory.reservedOverAvailable')}
@@ -1283,16 +1542,30 @@ export const InventoryManagement: React.FC = () => {
case 'batchReport': {
/** 2026-10-20:列名「存在报告」,并显示已绑定报告数量 */
const reportCount = Number(item.batch_report_count || 0);
+ const reportLabel =
+ reportCount > 0 ? (
+
+ {t('inventory.batchReport.presentCount', { n: reportCount })}
+
+ ) : (
+
+ {t('inventory.batchReport.missing')}
+
+ );
return (
- {reportCount > 0 ? (
-
- {t('inventory.batchReport.presentCount', { n: reportCount })}
-
+ {/* 2026-10-23 开发者:「报告在外面也能删除 上传」⇒ 点该格直接管这一批的报告 */}
+ {canAdjustInventory ? (
+
) : (
-
- {t('inventory.batchReport.missing')}
-
+ reportLabel
)}
|
);
@@ -1300,7 +1573,17 @@ export const InventoryManagement: React.FC = () => {
case 'available':
return (
- {formatQty(item.available_qty)}
+ {canAdjustInventory ? (
+ saveInlineAvailableQty(item, next)}
+ />
+ ) : (
+ formatQty(item.available_qty)
+ )}
|
);
case 'reserved': {
@@ -1363,6 +1646,21 @@ export const InventoryManagement: React.FC = () => {
const missingCost =
(Number(item.available_qty) || 0) > 0 &&
!((Number(item.cost_price) || 0) > 0);
+ // 列表内直接改(2026-10-23):成本改动仍由服务端重算未结算订单
+ if (canAdjustInventory) {
+ return (
+
+ saveInlineCostPrice(item, next)}
+ />
+ |
+ );
+ }
if (missingCost) {
return (
@@ -1413,19 +1711,45 @@ export const InventoryManagement: React.FC = () => {
case 'zone':
return (
|
- {item.storage_zone || '-'}
+ {canAdjustInventory ? (
+ ({ value: z, label: z }))}
+ emptyLabel={t('inventory.adjust.zoneEmpty')}
+ onCommit={(next) => saveInlineBatchFields(item, { storage_zone: next })}
+ />
+ ) : (
+ item.storage_zone || '-'
+ )}
|
);
case 'spec':
return (
- {item.spec || '-'}
+ {canInlineEditArchiveFields ? (
+ saveInlineBatchFields(item, { spec: next })}
+ />
+ ) : (
+ item.spec || '-'
+ )}
|
);
case 'unit':
return (
- {item.unit || '-'}
+ {canInlineEditArchiveFields ? (
+ saveInlineBatchFields(item, { unit: next })}
+ />
+ ) : (
+ item.unit || '-'
+ )}
|
);
case 'supplier':
@@ -2134,6 +2458,79 @@ export const InventoryManagement: React.FC = () => {
)}
+ {/* 列表内联:本批次报告查看 / 上传 / 删除 */}
+ {inlineReportItem ? (
+
+ e.stopPropagation()}
+ >
+
+
{t('inventory.adjust.reportsLabel')}
+
+
+
+ {inlineReportItem.sku_name || inlineReportItem.sku_code} ·{' '}
+ {inlineReportItem.batch_no}
+
+
+ {inlineReportsLoading ? (
+
…
+ ) : inlineReports.length === 0 ? (
+
{t('inventory.adjust.reportsEmpty')}
+ ) : (
+
+ {inlineReports.map((rep) => (
+ -
+
+ {t(`inventory.batchReport.type.${rep.report_type}` as any) || rep.report_type}
+ {rep.report_no ? (
+ · {rep.report_no}
+ ) : null}
+ {rep.uploaded_at ? (
+ · {rep.uploaded_at}
+ ) : null}
+
+
+
+ ))}
+
+ )}
+
+
+ ) : null}
+
+ setInlineReportBindOpen(false)}
+ onSaved={() => {
+ const inventoryId = inlineReportItem?.id;
+ if (inventoryId) void loadInlineReports(String(inventoryId));
+ void fetchInventory({ silent: true });
+ }}
+ />
+
{/* 库存「修改」弹窗内:报告直传/修改(批次已确定,不再走解析匹配) */}
{
+ it('五列都渲染内联输入(区域/规格/单位/可用数量/成本价)', () => {
+ expect(page).toContain('function InventoryInlineCell({');
+ // 逐个列接线
+ expect(page).toContain('onCommit={(next) => saveInlineAvailableQty(item, next)}');
+ expect(page).toContain('onCommit={(next) => saveInlineCostPrice(item, next)}');
+ expect(page).toContain("onCommit={(next) => saveInlineBatchFields(item, { storage_zone: next })}");
+ expect(page).toContain("onCommit={(next) => saveInlineBatchFields(item, { spec: next })}");
+ expect(page).toContain("onCommit={(next) => saveInlineBatchFields(item, { unit: next })}");
+ });
+
+ it('可用数量按本批次 inventory_id 调整(不是 SKU 级)', () => {
+ const fn = page.slice(page.indexOf('const saveInlineAvailableQty'), page.indexOf('const saveInlineCostPrice'));
+ expect(fn).toContain('adjustInventoryAvailableApi({');
+ expect(fn).toContain('inventoryId: item.id');
+ expect(fn).not.toContain('sku_code');
+ expect(fn).toContain("t('inventory.toast.qtyInvalid')");
+ });
+
+ it('规格/单位需要 product_manage;区域/成本/可用数量只需 inventory_adjust', () => {
+ expect(page).toContain(
+ "const canInlineEditArchiveFields = canAdjustInventory && hasPermission('product_manage');"
+ );
+ // 规格/单位用 canInlineEditArchiveFields 分支
+ const specBlock = page.slice(page.indexOf("case 'spec':"), page.indexOf("case 'unit':"));
+ expect(specBlock).toContain('canInlineEditArchiveFields ? (');
+ const unitBlock = page.slice(page.indexOf("case 'unit':"), page.indexOf("case 'supplier':"));
+ expect(unitBlock).toContain('canInlineEditArchiveFields ? (');
+ // 区域/可用/成本只需 inventory_adjust
+ expect(page.slice(page.indexOf("case 'zone':"), page.indexOf("case 'spec':"))).toContain(
+ 'canAdjustInventory ? ('
+ );
+ expect(page).toContain('if (canAdjustInventory) {');
+ });
+
+ it('写路径复用既有接口,备注留空交给服务端补中性标签', () => {
+ expect(page).toContain('updateInventoryBatchApi({');
+ const fn = page.slice(page.indexOf('const saveInlineBatchFields'), page.indexOf('const saveInlineAvailableQty'));
+ expect(fn).toContain("remark: ''");
+ expect(fn).toContain('operatingBranchCode: operatingBranchCode || readOperatingBranchCode()');
+ });
+
+ it('提交后静默刷新列表(不把整表切成 loading)', () => {
+ expect(page).toContain('await fetchInventory({ silent: true });');
+ expect(page).toContain('if (!options.silent) setLoading(true);');
+ expect(page).toContain('if (!options.silent && !isStale()) setLoading(false);');
+ });
+
+ it('失败回退:toast 并把值还原成服务端已知值', () => {
+ const cell = page.slice(page.indexOf('function InventoryInlineCell({'), page.indexOf('export const InventoryManagement'));
+ expect(cell).toContain('notify.error(');
+ expect(cell).toContain('setText(value);');
+ expect(cell).toContain('onKeyDown={(e) => {');
+ expect(cell).toContain("if (e.key === 'Enter') e.currentTarget.blur();");
+ });
+
+ it('区域 / 单位是下拉选择框(不是自由文本)', () => {
+ expect(page).toContain('function InventoryInlineSelectCell({');
+ const zoneBlock = page.slice(page.indexOf("case 'zone':"), page.indexOf("case 'spec':"));
+ expect(zoneBlock).toContain(' ({ value: z, label: z }))}');
+ const unitBlock = page.slice(page.indexOf("case 'unit':"), page.indexOf("case 'supplier':"));
+ expect(unitBlock).toContain(' opt.value === value))");
+ // 下拉必须用项目统一的 SearchableSelect(原生 select 的展开高度 CSS 管不了)
+ const cell = page.slice(page.indexOf('function InventoryInlineSelectCell({'), page.indexOf('export const InventoryManagement'));
+ expect(cell).toContain(' {
+ const cell = page.slice(page.indexOf('function InventoryInlineCell({'), page.indexOf('function InventoryInlineSelectCell({'));
+ expect(cell).toContain('type="text"');
+ expect(cell).toContain("inputMode={inputKind === 'decimal' ? 'decimal' : undefined}");
+ expect(cell).not.toContain("'number'");
+ expect(cell).not.toContain('step=');
+ });
+
+ it('工具栏按钮:上传报告 → 批量上传报告', () => {
+ expect(zhInventory).toContain("'batchReport.bulkButton': '批量上传报告',");
+ // 弹窗里「本批次补充报告」仍用原文案(不能被一起改成批量)
+ expect(zhInventory).toContain("'batchReport.button': '上传报告',");
+ });
+
+ it('分类也能在列表里就地切换(商品档案级,需 product_manage)', () => {
+ const productBlock = page.slice(page.indexOf("case 'product':"), page.indexOf("case 'batch':"));
+ expect(productBlock).toContain(' {
+ const reportBlock = page.slice(page.indexOf("case 'batchReport':"), page.indexOf("case 'zone':"));
+ expect(reportBlock).toContain('openInlineReports(item)');
+ const handlers = page.slice(page.indexOf('const loadInlineReports'), page.indexOf('const deleteInlineReport'));
+ expect(handlers).toContain('fetchInventoryBatchReportsByInventoryApi(inventoryId)');
+ expect(page).toContain('await deleteInventoryBatchReportApi(reportId);');
+ // 上传复用「按批次绑定」的同一个弹窗,不新造通道
+ const bind = page.slice(
+ page.indexOf('open={inlineReportBindOpen'),
+ page.indexOf('{/* 库存「修改」弹窗内')
+ );
+ expect(bind).toContain('inventoryId={String(inlineReportItem?.id');
+ expect(page).toContain('