feat(订单详情规格): 规格可编辑 + 切换商品时跟随新 SKU(保存只在载荷带 spec 时写)
开发者三点意见的前两点:「我切换商品时会不会切换规格 订单详情 当前切换时好像规格不会动」
「这边 规格是可以在订单详情这块修改的」。
① 详情「规格」列由只读改为**可编辑**(可编辑行给输入框,60 字上限,写回
`onUpdateItem(id,{spec})`;只读行仍只展示)。列数不变(同一格换控件)⇒ colCount 与合计行
colSpan 无需再动。
② 切换商品时**规格跟随新 SKU**(`applyEditItemSku`):`spec: skuSpec || item.spec || null`
—— 新 SKU **有**规格才覆盖,主数据没维护(空)则**保留原值**:否则录单从客户单据读到的规格
会被"切换一次就切没了",而当时没有可依据的新值(不造)。
③ 服务端 `orderManageItemsService` 保存规格,但**只在载荷真的带该字段时**写:
`hasSpec = hasOwnProperty(row,'spec')`;UPDATE 走 `spec = CASE WHEN $20::boolean THEN $19 ELSE spec END`;
新行 INSERT 落 `$21`。原因:改明细有 5 个入口(Web / 小程序×3 / MCP),别的入口不带 spec,
无条件写会把已存规格抹成 NULL。`OrderManageItemInput` 补 `spec`。
证据:前端 OrderParsedItemRow.spec.contract.test.ts **8 通过**(新增 ⑧:输入框/上限/写回/只读展示 +
切换跟随的 `skuSpec || item.spec || null`);详情既有 orderDetailSpecColumn.contract.test.ts 6 通过;
后端 orderItemsSpecPersistence 4 通过(④ 改为钉"只在带字段时写")+ orderParseSpec 7 +
orderSpecDisambiguation 6 共 17 通过;`tsc` 前端 exit 0(后端仅剩既有 defaults.ts variablesSchema 缺失)。
设计文档加 §9/§10(v3)。
**未做(需单独立项)**:新增商品弹窗加「规格」字段 —— 它要写商品主数据(`product_catalog.spec` 与
`skus.spec` 两处,否则"建了就丢"),属商品主数据冻结面,先确认写哪张表再动。
This commit is contained in:
@@ -83,3 +83,36 @@
|
|||||||
| `src/components/order/OrderDetailDeliveryNotePanel.tsx` | 商品名后加只读「规格」列;`colCount` 15/12→16/13;合计行 `colSpan` 6→7 |
|
| `src/components/order/OrderDetailDeliveryNotePanel.tsx` | 商品名后加只读「规格」列;`colCount` 15/12→16/13;合计行 `colSpan` 6→7 |
|
||||||
| `src/i18n/locales/{zh-CN,en,id}/orders.ts` | 新增 `detail.colSpec` 三语 |
|
| `src/i18n/locales/{zh-CN,en,id}/orders.ts` | 新增 `detail.colSpec` 三语 |
|
||||||
| `src/components/order/orderDetailSpecColumn.contract.test.ts` | 新增契约测试(落库 / 展示 / 列数 / 三语) |
|
| `src/components/order/orderDetailSpecColumn.contract.test.ts` | 新增契约测试(落库 / 展示 / 列数 / 三语) |
|
||||||
|
|
||||||
|
## 9. v3(2026-10-16 追加):详情里规格**可编辑** + 切换商品**跟随**
|
||||||
|
|
||||||
|
开发者指令:「我切换商品时会不会切换规格 订单详情 当前切换时好像规格不会动 而且这边 规格是可以在
|
||||||
|
订单详情这块修改的」。
|
||||||
|
|
||||||
|
| 变更 | 落点 |
|
||||||
|
| --- | --- |
|
||||||
|
| 规格列由**只读**改为**可编辑**(可编辑行给输入框,60 字上限,写回 `onUpdateItem(id,{spec})`;只读行仍只展示) | `OrderDetailDeliveryNotePanel.tsx` 规格单元格 |
|
||||||
|
| **切换商品时规格跟随新 SKU** | `OrderManagementPage.applyEditItemSku`:`spec: skuSpec \|\| item.spec \|\| null` |
|
||||||
|
| 改明细保存**写规格**,但**只在载荷带该字段时**写 | `orderManageItemsService`:`hasSpec = hasOwnProperty(row,'spec')`;UPDATE 用 `spec = CASE WHEN $20::boolean THEN $19 ELSE spec END`;新行 INSERT 落 `$21` |
|
||||||
|
|
||||||
|
口径与不变量:
|
||||||
|
|
||||||
|
1. **跟随但不清空**:新 SKU **有**规格才覆盖;主数据没维护(空)则**保留本行原值** ——
|
||||||
|
否则录单从客户单据读到的规格会被"切换一次就切没了",而且当时没有可依据的新值(**不造**)。
|
||||||
|
2. **只有载荷带 `spec` 才写库**:改明细有 5 个入口(Web / 小程序 ×3 / MCP),别的入口不带 `spec`
|
||||||
|
⇒ 若无条件 `spec = $N`,保存一次就把已存规格抹成 NULL。
|
||||||
|
3. **主系统不传规格(开发者确认)**:主系统分配单/追加行的 `spec` **恒为空是正确状态**,
|
||||||
|
⛔ 不得用 `skus.spec` 反填。
|
||||||
|
4. 列数不变(只是把该格内容从 `<span>` 换成 `<input>`)⇒ `colCount` 与合计行 `colSpan` **无需再动**。
|
||||||
|
|
||||||
|
## 10. v3 验证
|
||||||
|
|
||||||
|
| 验证项 | 命令 | 结果 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 详情可编辑(输入框 / 60 字上限 / 写回 onUpdateItem / 只读行仍只展示)与切换跟随 | `npx vitest run src/components/order/OrderParsedItemRow.spec.contract.test.ts` | 8 通过 |
|
||||||
|
| 详情列与落库既有契约未被破坏 | `npx vitest run src/components/order/orderDetailSpecColumn.contract.test.ts` | 6 通过 |
|
||||||
|
| 改明细只在带字段时写 spec(UPDATE 的 CASE + 新行 INSERT + 60 字上限) | `cd server && npx vitest run tests/orderItemsSpecPersistence.test.ts` | 4 通过 |
|
||||||
|
|
||||||
|
**未做(需单独立项)**:新增商品弹窗(`QuickCreateProductModal`)加「规格」字段 —— 它要写
|
||||||
|
**商品主数据**(`product_catalog.spec` 与 `skus.spec` 两处,否则"建了就丢"),属
|
||||||
|
[商品主数据冻结](../../.cursor/rules/product-freeze.mdc) 面,需先确认写哪张表 / 是否同步两处。
|
||||||
|
|||||||
@@ -137,6 +137,12 @@ export type OrderManageItemInput = {
|
|||||||
create_product?: boolean | string | null;
|
create_product?: boolean | string | null;
|
||||||
/** 录单明细备注;展示用 */
|
/** 录单明细备注;展示用 */
|
||||||
remark?: string | null;
|
remark?: string | null;
|
||||||
|
/**
|
||||||
|
* 商品规格(`order_items.spec`;2026-10-16 起可在订单详情直接改)。
|
||||||
|
* ⚠️ **区分「没传」与「传了空」**:本服务用 `hasOwnProperty('spec')` 判断是否要写,
|
||||||
|
* 没传的入口(小程序/MCP)保存时保持原值,不会把已存规格抹掉。
|
||||||
|
*/
|
||||||
|
spec?: string | null;
|
||||||
/** 弱引用质检报告库;MVP 不计硬门禁 */
|
/** 弱引用质检报告库;MVP 不计硬门禁 */
|
||||||
quality_report_id?: string | null;
|
quality_report_id?: string | null;
|
||||||
/** 可挂多份(多供应商) */
|
/** 可挂多份(多供应商) */
|
||||||
@@ -1291,6 +1297,15 @@ export async function syncOrderManageItems(params: {
|
|||||||
: isTruthyFlag(row.is_extra_dish) || Boolean(existingMap.get(id)?.is_extra_dish);
|
: isTruthyFlag(row.is_extra_dish) || Boolean(existingMap.get(id)?.is_extra_dish);
|
||||||
const remarkRaw = trimText(row.remark);
|
const remarkRaw = trimText(row.remark);
|
||||||
const remark = remarkRaw ? remarkRaw.slice(0, 500) : null;
|
const remark = remarkRaw ? remarkRaw.slice(0, 500) : null;
|
||||||
|
/**
|
||||||
|
* 规格(`order_items.spec`,2026-10-16 起可在订单详情直接改)。
|
||||||
|
*
|
||||||
|
* ⚠️ **只有载荷真的带了这个字段才动它**:改明细有 5 个入口(Web / 小程序 ×3 / MCP),
|
||||||
|
* 别的入口不带 spec ⇒ 若无条件 `spec = $N`,保存一次就会把已存规格**抹成 NULL**。
|
||||||
|
* 故用 `hasSpec` 标志位(UPDATE 里走 CASE),新行则直接取值(本来就是空)。
|
||||||
|
*/
|
||||||
|
const hasSpec = Object.prototype.hasOwnProperty.call(row, 'spec');
|
||||||
|
const spec = hasSpec ? trimText(row.spec).slice(0, 60) || null : null;
|
||||||
const qualityReportIds = normalizeQualityReportIds(row);
|
const qualityReportIds = normalizeQualityReportIds(row);
|
||||||
const qualityReportId = qualityReportIds[0] || null;
|
const qualityReportId = qualityReportIds[0] || null;
|
||||||
if (qualityReportIds.length) {
|
if (qualityReportIds.length) {
|
||||||
@@ -1407,7 +1422,9 @@ export async function syncOrderManageItems(params: {
|
|||||||
unit_cost = $15::numeric,
|
unit_cost = $15::numeric,
|
||||||
remark = $16,
|
remark = $16,
|
||||||
quality_report_id = $17::uuid,
|
quality_report_id = $17::uuid,
|
||||||
quality_report_ids = $18::uuid[]
|
quality_report_ids = $18::uuid[],
|
||||||
|
-- 规格:仅当载荷带 spec 时才写(否则保持原值,见 hasSpec 注释)
|
||||||
|
spec = CASE WHEN $20::boolean THEN $19 ELSE spec END
|
||||||
WHERE id = $13::uuid AND order_code = $14`,
|
WHERE id = $13::uuid AND order_code = $14`,
|
||||||
[
|
[
|
||||||
itemName,
|
itemName,
|
||||||
@@ -1428,6 +1445,8 @@ export async function syncOrderManageItems(params: {
|
|||||||
remark,
|
remark,
|
||||||
qualityReportId,
|
qualityReportId,
|
||||||
qualityReportIds,
|
qualityReportIds,
|
||||||
|
spec,
|
||||||
|
hasSpec,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
if (!updated.rowCount) {
|
if (!updated.rowCount) {
|
||||||
@@ -1482,8 +1501,8 @@ export async function syncOrderManageItems(params: {
|
|||||||
id, order_code, sku_code, item_name, quantity, unit, price, amount, item_status, sort_order,
|
id, order_code, sku_code, item_name, quantity, unit, price, amount, item_status, sort_order,
|
||||||
branch_code, processing_method, processing_owner, category_code, category_name, supplier_code,
|
branch_code, processing_method, processing_owner, category_code, category_name, supplier_code,
|
||||||
locked_price, price_locked_at, is_extra_dish, unit_cost, remark, quality_report_id, quality_report_ids,
|
locked_price, price_locked_at, is_extra_dish, unit_cost, remark, quality_report_id, quality_report_ids,
|
||||||
ordered_quantity
|
ordered_quantity, spec
|
||||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, 10, $9, $10, $11, $12, $13, $14, $15, $7, NOW(), $20, $16, $17, $18::uuid, $19::uuid[], $5)`,
|
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, 10, $9, $10, $11, $12, $13, $14, $15, $7, NOW(), $20, $16, $17, $18::uuid, $19::uuid[], $5, $21)`,
|
||||||
[
|
[
|
||||||
newId,
|
newId,
|
||||||
orderCode,
|
orderCode,
|
||||||
@@ -1505,6 +1524,7 @@ export async function syncOrderManageItems(params: {
|
|||||||
qualityReportId,
|
qualityReportId,
|
||||||
qualityReportIds,
|
qualityReportIds,
|
||||||
rowIsExtraDish,
|
rowIsExtraDish,
|
||||||
|
spec,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
if (params.purchaserDirectAllocation) {
|
if (params.purchaserDirectAllocation) {
|
||||||
|
|||||||
@@ -51,8 +51,15 @@ describe('录单规格 · 落库链路', () => {
|
|||||||
expect(ensured).toContain('...item');
|
expect(ensured).toContain('...item');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('④ 改明细/加菜路径不得写 spec(保存一次不能把已存规格抹掉)', () => {
|
it('④ 改明细/加菜路径:规格**只在载荷带该字段时**才写(别的入口保存不得抹掉已存规格)', () => {
|
||||||
// 用词边界匹配"规格列",避免被 inspection* 之类的子串误伤
|
// 2026-10-16 追加:详情里规格可编辑 ⇒ 保存要写 spec;但入口有 5 个(Web/小程序×3/MCP),
|
||||||
expect(/\bspec\b/.test(itemsService)).toBe(false);
|
// 不带 spec 的入口保存一次不能把已存规格抹成 NULL,故走 hasSpec 标志位。
|
||||||
|
expect(itemsService).toContain("Object.prototype.hasOwnProperty.call(row, 'spec')");
|
||||||
|
expect(itemsService).toContain('spec = CASE WHEN $20::boolean THEN $19 ELSE spec END');
|
||||||
|
// 新行直接落 spec(第 21 个参数)
|
||||||
|
expect(itemsService).toMatch(/ordered_quantity, spec\s*\)/);
|
||||||
|
expect(itemsService).toContain('$19::uuid[], $5, $21)');
|
||||||
|
// 60 字上限与录单一致
|
||||||
|
expect(itemsService).toContain('trimText(row.spec).slice(0, 60)');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -906,10 +906,30 @@ export const OrderDetailDeliveryNotePanel: React.FC<OrderDetailDeliveryNotePanel
|
|||||||
)}
|
)}
|
||||||
</td>
|
</td>
|
||||||
<td className="border border-slate-700 dark:border-slate-500 px-2 py-1.5 w-[6rem]">
|
<td className="border border-slate-700 dark:border-slate-500 px-2 py-1.5 w-[6rem]">
|
||||||
{/* 商品规格(录单录入/人工修正):空就不展示(本列只读,改规格回录单/明细编辑) */}
|
{/**
|
||||||
<span className="block text-center text-xs app-foreground-muted break-words">
|
* 商品规格(录单录入 / 人工修正)。
|
||||||
{String(item.spec || '').trim() || ''}
|
* 可编辑行给输入框(2026-10-16 开发者:「这边规格是可以在订单详情这块修改的」),
|
||||||
</span>
|
* 只读行仍只展示;切换商品时由页面把规格换成新 SKU 的规格(见 applyEditItemSku)。
|
||||||
|
*/}
|
||||||
|
{rowEditable ? (
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={String(item.spec || '')}
|
||||||
|
onChange={(e) =>
|
||||||
|
onUpdateItem(item.id, { spec: e.target.value.slice(0, 60) })
|
||||||
|
}
|
||||||
|
placeholder={t('orders.detail.colSpec')}
|
||||||
|
title={t('orders.detail.colSpec')}
|
||||||
|
maxLength={60}
|
||||||
|
className={`app-input min-w-0 w-full px-1.5 py-1 text-xs text-center border rounded focus:outline-none focus:ring-1 ${
|
||||||
|
item.spec ? '' : 'app-foreground-muted'
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<span className="block text-center text-xs app-foreground-muted break-words">
|
||||||
|
{String(item.spec || '').trim() || ''}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</td>
|
</td>
|
||||||
<td className="border border-slate-700 dark:border-slate-500 px-1 py-1.5 w-[5.5rem]">
|
<td className="border border-slate-700 dark:border-slate-500 px-1 py-1.5 w-[5.5rem]">
|
||||||
<InboundPhotoThumbs
|
<InboundPhotoThumbs
|
||||||
|
|||||||
@@ -80,6 +80,23 @@ describe('录单行 · 规格字段', () => {
|
|||||||
expect(shared).toMatch(/export interface SkuCandidate \{[\s\S]*?spec\?: string \| null;/);
|
expect(shared).toMatch(/export interface SkuCandidate \{[\s\S]*?spec\?: string \| null;/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('⑧ 订单详情:规格可编辑(写回 onUpdateItem)且切换商品时跟随新 SKU 的规格', () => {
|
||||||
|
const panel = read('./OrderDetailDeliveryNotePanel.tsx');
|
||||||
|
const cell = panel.slice(panel.indexOf("w-[6rem]\">"), panel.indexOf('<InboundPhotoThumbs'));
|
||||||
|
expect(cell, '可编辑行给输入框').toContain('rowEditable ? (');
|
||||||
|
expect(cell).toContain('value={String(item.spec || \'\')}');
|
||||||
|
expect(cell).toContain('onUpdateItem(item.id, { spec: e.target.value.slice(0, 60) })');
|
||||||
|
expect(cell, '只读行仍只展示').toContain("String(item.spec || '').trim() || ''");
|
||||||
|
|
||||||
|
// 切换 SKU 时跟随:新 SKU 有规格才覆盖,空则保留本行原值(避免把录单读到的规格切没了)
|
||||||
|
const management = read('../../pages/orders/orderManagement/OrderManagementPage.tsx');
|
||||||
|
const applyStart = management.indexOf('const applyEditItemSku = (');
|
||||||
|
expect(applyStart).toBeGreaterThan(-1);
|
||||||
|
const apply = management.slice(applyStart, management.indexOf('if (!selectedOrder) return next;', applyStart));
|
||||||
|
expect(apply).toContain('const skuSpec = String(sku.spec ?? ');
|
||||||
|
expect(apply).toContain('spec: skuSpec || item.spec || null');
|
||||||
|
});
|
||||||
|
|
||||||
it('⑤ 三语文案「规格」齐备', () => {
|
it('⑤ 三语文案「规格」齐备', () => {
|
||||||
for (const [locale, expected] of [
|
for (const [locale, expected] of [
|
||||||
['zh-CN', "lineSpec: '规格'"],
|
['zh-CN', "lineSpec: '规格'"],
|
||||||
|
|||||||
@@ -1769,6 +1769,12 @@ export const OrderManagement: React.FC = () => {
|
|||||||
const categoryName = sku.category_code
|
const categoryName = sku.category_code
|
||||||
? getCategoryLabel(sku.category_code)
|
? getCategoryLabel(sku.category_code)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
/**
|
||||||
|
* 切换商品时**规格跟随新 SKU**(2026-10-16 开发者:「我切换商品时会不会切换规格 … 当前切换时好像规格不会动」)。
|
||||||
|
* 口径:新 SKU **有**规格时才覆盖;主数据没维护规格(空)则**保留本行原值** ——
|
||||||
|
* 否则录单从客户单据上读到的规格会被"切换一次就切没了",而且这里没有可依据的新值(不造)。
|
||||||
|
*/
|
||||||
|
const skuSpec = String(sku.spec ?? '').trim().slice(0, 60);
|
||||||
return {
|
return {
|
||||||
...item,
|
...item,
|
||||||
sku_code: sku.sku_code,
|
sku_code: sku.sku_code,
|
||||||
@@ -1778,6 +1784,7 @@ export const OrderManagement: React.FC = () => {
|
|||||||
category_code: sku.category_code || item.category_code,
|
category_code: sku.category_code || item.category_code,
|
||||||
category_name: categoryName || item.category_name,
|
category_name: categoryName || item.category_name,
|
||||||
cost_price: quoteCostBySku.get(sku.sku_code) || 0,
|
cost_price: quoteCostBySku.get(sku.sku_code) || 0,
|
||||||
|
spec: skuSpec || item.spec || null,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
if (!selectedOrder) return next;
|
if (!selectedOrder) return next;
|
||||||
|
|||||||
Reference in New Issue
Block a user