From 5df48652437b6a0f79be829e41ef7e7cb097c78e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=A8=E5=A4=A9?= Date: Tue, 13 Oct 2026 18:51:03 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=88=86=E6=8B=A3):=20=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E5=A4=9A=E9=80=89=E6=8B=A3=E8=B4=A7=E5=8D=95=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 表头全选 + 行内多选;选中后按「按订单/按分类/按商品/按区域」排序,一次生成多页标签并打印,免去逐单进详情逐个点。复用既有文案(无新 key);区域排序遵循分公司区域顺序。商品行 SELECT 补 category_name(纯读,无迁移)。同步更新 mpPickingScopeSelect 断言(2026-10-13 重新加回小程序 BLE 打印,仍不走旧 print_jobs 链路)。 --- docs/design/20261013-分拣列表批量打印标签.md | 113 +++++++++++++++++++ docs/design/README.md | 1 + server/src/services/pickingService.ts | 2 + server/tests/mpPickingScopeSelect.test.ts | 14 ++- src/pages/picking/PickingManagement.tsx | 112 +++++++++++++++++- src/utils/picking.ts | 2 + src/utils/pickingLabelPrint.test.ts | 46 +++++++- src/utils/pickingLabelPrint.ts | 52 +++++++++ 8 files changed, 333 insertions(+), 9 deletions(-) create mode 100644 docs/design/20261013-分拣列表批量打印标签.md diff --git a/docs/design/20261013-分拣列表批量打印标签.md b/docs/design/20261013-分拣列表批量打印标签.md new file mode 100644 index 0000000..367fa50 --- /dev/null +++ b/docs/design/20261013-分拣列表批量打印标签.md @@ -0,0 +1,113 @@ +# 分拣列表:多选拣货单批量打印标签(按订单/分类/商品/区域排队) + +> 立项 2026-10-13。开发者口径(原话): +> 「这块不能一个个打印拣货单旁边设置一个多选(存在一个全选按钮)多选后将商品整理一下 +> 它可以按照分类 区域 订单 商品 选择性的进行一个排排队打印 而不是一个个点击一个个打印」。 +> +> 承接:[20261013-分拣标签打印改蓝牙与浏览器直连.md](./20261013-分拣标签打印改蓝牙与浏览器直连.md)(标签版式与通道已定)。 + +## 0. 一句话 + +分拣**列表页**加一列多选(表头**全选**);勾若干拣货单后,把它们的商品行**按所选维度 +(订单 / 分类 / 商品 / 区域)排序**,**一次**生成多页标签并打印,免去逐单进详情逐个点打印。 + +## 1. 背景 + +- 2026-10-13 已把分拣标签打印改成新通道(小程序 BLE / Web 浏览器打印),但入口只在**明细弹层逐行**(一行一次点击)。 +- 列表页(`/picking`)本来就一次拉回**全部列出的拣货单 + 它们的商品行**(`fetchTasks` → + `setItemsByPickCode(grouped)`,接口 `GET /picking/tasks` 同时返回 `data` 与 `items`)⇒ + 批量打印**无需新接口**。 +- 列表表格列由 `useReorderableTableColumns` 渲染,`listColumnCount` 为可见列数。 + +## 2. 方案要点 + +### 2.1 列表多选 + +- 表格**最左**新增一列复选框(不可重排,渲染在 `listOrderedColumns` 之前): + - 表头:**全选** —— 勾选/取消**本页**全部行(`tasksPage.pageRows`)。 + - 行内:勾选该拣货单(选中键 = `pick_code`)。 +- 选中状态按 `pick_code` 记录,**跨页保留**(翻页后已选仍算)。 +- `colSpan` 需 +1(表头行、加载行、空态行)。 + +### 2.2 批量打印工具条 + +选中数 > 0 时,在表格上方显示一条工具条: + +| 控件 | 说明 | +|---|---| +| 排序维度 ` setListPrintGroupBy(e.target.value as PickingLabelGroupBy)} + className="app-input app-focus-ring px-2 py-1.5 border rounded-md text-sm" + > + + + + + + + + )} + {listOrderedColumns.map((col) => { const headerProps = getListHeaderProps(col.id); return ( @@ -2335,9 +2433,9 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin {loading ? ( - + ) : filteredTasks.length === 0 ? ( - ) : ( @@ -2361,6 +2459,14 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin : t('picking.scope.order'); return ( + {listOrderedColumns.map((col) => { switch (col.id) { case 'pick_code': diff --git a/src/utils/picking.ts b/src/utils/picking.ts index ce7d009..2493c79 100644 --- a/src/utils/picking.ts +++ b/src/utils/picking.ts @@ -29,6 +29,8 @@ export interface PickingItemRow { review_status: number; diff_reason?: string | null; barcode?: string | null; + /** 商品分类(`order_items.category_name`),分拣列表批量打印按「分类」排队用 */ + category_name?: string | null; sort_order?: number | null; container_code?: string | null; staged_at?: string | null; diff --git a/src/utils/pickingLabelPrint.test.ts b/src/utils/pickingLabelPrint.test.ts index 27c5510..efd015e 100644 --- a/src/utils/pickingLabelPrint.test.ts +++ b/src/utils/pickingLabelPrint.test.ts @@ -1,5 +1,9 @@ import { describe, it, expect } from 'vitest'; -import { buildPickingLabelHtml, formatLabelWeightLine } from './pickingLabelPrint'; +import { + buildPickingLabelHtml, + formatLabelWeightLine, + sortItemsForLabelPrint, +} from './pickingLabelPrint'; describe('formatLabelWeightLine(与旧秤端逐字一致)', () => { it('重量单位统一换算为「斤」', () => { @@ -15,6 +19,46 @@ describe('formatLabelWeightLine(与旧秤端逐字一致)', () => { }); }); +describe('sortItemsForLabelPrint(批量打印排队)', () => { + // 分组值用 ASCII,避免断言依赖中文拼音排序 + const items = [ + { item_name: 'C-白菜', order_code: 'O2', category_name: 'CAT-B', storage_zone: 'Z-B', sku_code: 'SKU-3', sort_order: 2 }, + { item_name: 'A-苹果', order_code: 'O1', category_name: 'CAT-A', storage_zone: 'Z-A', sku_code: 'SKU-1', sort_order: 1 }, + { item_name: 'B-菠菜', order_code: 'O1', category_name: 'CAT-A', storage_zone: 'Z-A', sku_code: 'SKU-2', sort_order: 1 }, + ]; + + it('按订单分组,组内按 sort_order 再按品名', () => { + const out = sortItemsForLabelPrint(items, 'order').map((i) => i.item_name); + expect(out).toEqual(['A-苹果', 'B-菠菜', 'C-白菜']); + }); + + it('按分类分组', () => { + const out = sortItemsForLabelPrint(items, 'category').map((i) => i.item_name); + expect(out).toEqual(['A-苹果', 'B-菠菜', 'C-白菜']); + }); + + it('按商品(SKU)分组', () => { + const out = sortItemsForLabelPrint(items, 'sku').map((i) => i.item_name); + expect(out).toEqual(['A-苹果', 'B-菠菜', 'C-白菜']); + }); + + it('按区域分组,且尊重分公司区域顺序', () => { + const ordered = sortItemsForLabelPrint(items, 'zone', { zoneOrder: ['Z-B', 'Z-A'] }).map((i) => i.storage_zone); + expect(ordered).toEqual(['Z-B', 'Z-A', 'Z-A']); + }); + + it('未配置区域顺序时按名称排', () => { + const fallback = sortItemsForLabelPrint(items, 'zone').map((i) => i.storage_zone); + expect(fallback).toEqual(['Z-A', 'Z-A', 'Z-B']); + }); + + it('不改动原数组', () => { + const before = items.map((i) => i.item_name); + sortItemsForLabelPrint(items, 'sku'); + expect(items.map((i) => i.item_name)).toEqual(before); + }); +}); + describe('buildPickingLabelHtml(分拣标签 · 浏览器打印)', () => { it('50×30mm 纸宽,一签一分区', () => { const html = buildPickingLabelHtml([{ itemName: '大葱', qty: 10, unit: '斤' }]); diff --git a/src/utils/pickingLabelPrint.ts b/src/utils/pickingLabelPrint.ts index 6084d65..9cde068 100644 --- a/src/utils/pickingLabelPrint.ts +++ b/src/utils/pickingLabelPrint.ts @@ -20,6 +20,58 @@ export interface PickingLabel { barcode?: string | null; } +/** 批量打印时的排队维度 */ +export type PickingLabelGroupBy = 'order' | 'category' | 'sku' | 'zone'; + +/** 可参与排队的商品行最小字段集 */ +export interface LabelSortableItem { + order_code?: string | null; + category_name?: string | null; + storage_zone?: string | null; + item_name?: string | null; + sku_code?: string | null; + sort_order?: number | null; +} + +function groupValueOf(item: LabelSortableItem, groupBy: PickingLabelGroupBy): string { + if (groupBy === 'order') return String(item.order_code || '').trim(); + if (groupBy === 'category') return String(item.category_name || '').trim(); + if (groupBy === 'zone') return String(item.storage_zone || '').trim(); + return String(item.sku_code || item.item_name || '').trim(); +} + +/** + * 批量打印标签前的排队:主键=所选维度,同键再按 sort_order、最后按品名。 + * 区域可传入分公司区域顺序(`zoneOrder`):已列入的按顺序,未列入的排最后(再按名称)。 + */ +export function sortItemsForLabelPrint( + items: T[], + groupBy: PickingLabelGroupBy, + options?: { zoneOrder?: string[] } +): T[] { + const zoneRank = + groupBy === 'zone' && Array.isArray(options?.zoneOrder) + ? new Map(options!.zoneOrder.map((z, i) => [String(z).trim(), i])) + : null; + const compareGroup = (a: string, b: string) => { + if (zoneRank) { + const ra = zoneRank.has(a) ? zoneRank.get(a)! : Number.MAX_SAFE_INTEGER; + const rb = zoneRank.has(b) ? zoneRank.get(b)! : Number.MAX_SAFE_INTEGER; + if (ra !== rb) return ra - rb; + } + return a.localeCompare(b, 'zh-CN'); + }; + return [...items].sort((a, b) => { + const ga = groupValueOf(a, groupBy); + const gb = groupValueOf(b, groupBy); + if (ga !== gb) return compareGroup(ga, gb); + const sa = Number(a.sort_order) || 0; + const sb = Number(b.sort_order) || 0; + if (sa !== sb) return sa - sb; + return String(a.item_name || '').localeCompare(String(b.item_name || ''), 'zh-CN'); + }); +} + /** 与秤端 203dpi(8 dot/mm)一致 */ const DOT_MM = 1 / 8; const LABEL_W_DOTS = 400; // 50mm
+ toggleListPrintPage(e.target.checked)} + aria-label={t('picking.aria.selectAllPrint')} + /> +
{t('picking.emptyLoading')}
{t('picking.emptyLoading')}
+
{activeTab === 'history' ? t('picking.emptyHistory') : t('picking.emptyTasks')}
+ toggleListPrintRow(task.pick_code, e.target.checked)} + aria-label={t('picking.aria.selectItem', { name: task.pick_code })} + /> +