From 6db5eb9e7729b3f385f258e64d07b33ae0880a67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=A8=E5=A4=A9?= Date: Fri, 16 Oct 2026 17:21:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E8=87=AA=E9=87=87?= =?UTF-8?q?=E5=88=97=E8=A1=A8:=20=E8=A7=84=E6=A0=BC=E6=95=B4=E8=A1=8C?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=20+=20=E5=8D=95=E4=BB=B7=E9=A2=84=E5=A1=AB?= =?UTF-8?q?=E5=8E=BB=200?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ① 规格从商品名列(被单位/数量/单价挤到极窄、规格与商品名都折行)移到卡片行下方独占一行; ② 单价输入预填去 0:0 视为未定价 ⇒ 留空(点击即可直接填,无需先删 0),>0 才预填;pickCostPriceHint 的「0 合法」语义不变。 均只改自采列表卡片,新增两条契约测试。 --- .../20261016-小程序自采列表展示商品规格.md | 10 +++++-- .../purchase-today-panel/index.wxml | 3 +- .../purchase-today-panel/index.wxss | 7 +++-- miniprogram/utils/purchaseToday.js | 14 ++++++++-- .../selfPurchasePricePrefill.contract.test.ts | 28 +++++++++++++++++++ .../selfPurchaseSpecColumn.contract.test.ts | 9 ++++++ 6 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 src/pages/purchase/selfPurchasePricePrefill.contract.test.ts diff --git a/docs/design/20261016-小程序自采列表展示商品规格.md b/docs/design/20261016-小程序自采列表展示商品规格.md index c0011b8..5497f31 100644 --- a/docs/design/20261016-小程序自采列表展示商品规格.md +++ b/docs/design/20261016-小程序自采列表展示商品规格.md @@ -33,7 +33,8 @@ ### 3.2 小程序(B) - `decorateProductGroupDisplay` 增 `specText`:组内 `items` 的规格**去重、非空**拼接(同 SKU 同单位多单规格不同时不会只剩一个)。 -- 卡片 `.product-row-name` 下加一行**灰色小字「规格:{specText}」**(空 ⇒ 不渲染该行,避免出现"规格:—")。 +- 卡片**整行**展示「规格:{specText}」(空 ⇒ 不渲染该行)。⚠️ 2026-10-16 调整:**不再放在商品名列内**——该列被单位/数量/单价挤到极窄,规格与商品名都会折行;改放到 `.product-row` 下方**独占一行**。 +- **单价输入预填去 0**(同批 UI 优化,开发者:「不应该是我点击后就直接输入价格就行吗,现在还得先删 0」):新增 `prefillPriceInput`,把「0 = 未定价」渲染为**空**(显示 placeholder「单价」),> 0 的真实价才预填。`pickCostPriceHint` 的「0 合法」语义不变(取值/回退仍按 0,提交空串也仍是 0)。 - **文案**:小程序界面为**中文硬编码**(如「转供应商」「今日待采」),故本列只加中文,**不涉三语**。 ### 3.3 历史自采 / 其它 @@ -75,9 +76,11 @@ | --- | --- | | `server/src/services/purchaseOrderQuery.ts` | `PURCHASE_ORDER_DISPLAY_SELECT` 增 `order_spec`(只取 `oi.spec`,无兜底) | | `miniprogram/components/purchase-today-panel/index.js` | `decorateProductGroupDisplay` 增 `specText` | -| `miniprogram/components/purchase-today-panel/index.wxml` | `.product-row-name` 下加「规格:」小字行(有值才渲染) | -| `miniprogram/components/purchase-today-panel/index.wxss` | `.product-row-spec` 样式(灰、略小) | +| `miniprogram/components/purchase-today-panel/index.wxml` | 商品名下方/卡片行下方「规格:」整行(有值才渲染;2026-10-16 从商品名列移出) | +| `miniprogram/components/purchase-today-panel/index.wxss` | `.product-row-spec` 样式(灰、略小、整行) | +| `miniprogram/utils/purchaseToday.js` | `prefillPriceInput`:单价预填去 0(0 ⇒ 留空) | | `src/pages/purchase/selfPurchaseSpecColumn.contract.test.ts` | 新增契约测试(共享 SELECT 只认 `oi.spec` + 卡片 specText/wxml/wxss) | +| `src/pages/purchase/selfPurchasePricePrefill.contract.test.ts` | 新增契约测试(单价预填去 0) | ## 8. 修订记录 @@ -85,3 +88,4 @@ | --- | --- | --- | | v1 | 2026-10-16 | 首版设计(含 §4 六项待拍板) | | v2 | 2026-10-16 | 开发者口径「与订单详情一致」⇒ 实现:共享 SELECT 带 `order_spec`(只认 `oi.spec`)+ 卡片商品名下一行「规格:xxx」(有值才显示)+ 契约测试;无商品库兜底 | +| v3 | 2026-10-16 | UI 优化:①「规格」从商品名列**移到卡片行下方独占一行**(该列太窄,规格与商品名都折行);②单价输入预填**去 0**(0 ⇒ 留空,点击即可直接填) | diff --git a/miniprogram/components/purchase-today-panel/index.wxml b/miniprogram/components/purchase-today-panel/index.wxml index 4d7ce54..1427d82 100644 --- a/miniprogram/components/purchase-today-panel/index.wxml +++ b/miniprogram/components/purchase-today-panel/index.wxml @@ -106,7 +106,6 @@ >{{product.photoCount > 0 ? '已拍' + product.photoCount : (product.photoRequired ? '拍照' : '拍照')}} {{product.productName}} - 规格:{{product.specText}} {{product.remarkText}} 仓内加工 · 只读记录 @@ -158,6 +157,8 @@ >转供应商 + 规格:{{product.specText}} + 未匹配商品库,请在下方逐单确认名称和分类 diff --git a/miniprogram/components/purchase-today-panel/index.wxss b/miniprogram/components/purchase-today-panel/index.wxss index 9e66677..58f9065 100644 --- a/miniprogram/components/purchase-today-panel/index.wxss +++ b/miniprogram/components/purchase-today-panel/index.wxss @@ -1390,13 +1390,14 @@ overflow-wrap: anywhere; } +/* 规格:整行显示在卡片行下方(2026-10-16 从商品名列移出,避免被挤到折行) */ .product-row-spec { - display: block; - margin-top: 2rpx; + margin-top: 4rpx; + padding: 0 2rpx; font-size: 22rpx; font-weight: 400; color: #71717a; - line-height: 1.35; + line-height: 1.4; word-break: break-word; overflow-wrap: anywhere; } diff --git a/miniprogram/utils/purchaseToday.js b/miniprogram/utils/purchaseToday.js index f79e352..6514e7d 100644 --- a/miniprogram/utils/purchaseToday.js +++ b/miniprogram/utils/purchaseToday.js @@ -227,6 +227,16 @@ function pickCostPriceHint(row) { return ''; } +/** + * 单价输入**预填**:0 视为「尚未定价」⇒ **留空**(点击即可直接输入,免得先删一个 0); + * 只有 > 0 的真实价才预填。⚠️ 只影响「预填」,不改 `pickCostPriceHint` 的「0 合法」语义 + * (取值/回退仍按 0 处理,提交空串也仍是 0)。 + */ +function prefillPriceInput(hint) { + const n = Number(hint); + return Number.isFinite(n) && n > 0 ? String(hint) : ''; +} + function resolveActualQty(row) { const raw = row?.actual_qty_input; if (raw !== undefined && raw !== null && String(raw).trim() !== '') { @@ -434,7 +444,7 @@ function buildProductGroups(rows) { warehouseDemandRecord: recordAll, planQtyText: planText, actual_qty_input: toInputString(null, group.planQtyTotal), - actual_price_input: toInputString(pickCostPriceHint(first), ''), + actual_price_input: prefillPriceInput(pickCostPriceHint(first)), unit: displayText(first?.unit, group.unit), unitIndex: first?.unitIndex || 0, unitOptions: first?.unitOptions || group.unitOptions, @@ -475,7 +485,7 @@ function decoratePurchaseRow(row, categoryOptions) { can_skip_warehouse: canSkipWarehouseDemand(row), order_supplier_name: displayText(row.order_supplier_name, ''), actual_qty_input: toInputString(row.actual_qty, row.purchase_qty), - actual_price_input: toInputString(pickCostPriceHint(row), ''), + actual_price_input: prefillPriceInput(pickCostPriceHint(row)), direct_delivery: isSkuDirectDelivery(row), photoRequired: needsDirectDeliveryPhoto(row), photoCount: directDeliveryPhotoCount(row), diff --git a/src/pages/purchase/selfPurchasePricePrefill.contract.test.ts b/src/pages/purchase/selfPurchasePricePrefill.contract.test.ts new file mode 100644 index 0000000..697108f --- /dev/null +++ b/src/pages/purchase/selfPurchasePricePrefill.contract.test.ts @@ -0,0 +1,28 @@ +import { readFileSync } from 'node:fs'; +import { describe, expect, it } from 'vitest'; + +/** + * 小程序自采列表「单价」输入预填(2026-10-16 开发者)。 + * + * 开发者:「为什么用真实的 0 来占位?不应该是我点击后就直接输入价格就行吗,现在还得先删掉 0」 + * ⇒ 0 视为**尚未定价**,输入框**留空**(显示 placeholder「单价」);只有 > 0 的真实价才预填。 + * ⚠️ 只改「预填」;`pickCostPriceHint` 的「0 合法」语义与取值/回退不改(提交空串仍是 0)。 + */ +const src = readFileSync( + new URL('../../../miniprogram/utils/purchaseToday.js', import.meta.url), + 'utf8' +); + +describe('自采列表单价预填:0 不再占位', () => { + it('预填走 prefillPriceInput(0 ⇒ 留空)', () => { + expect(src).toContain('function prefillPriceInput(hint) {'); + expect(src).toContain("return Number.isFinite(n) && n > 0 ? String(hint) : '';"); + expect(src).toContain('actual_price_input: prefillPriceInput(pickCostPriceHint(row)),'); + expect(src).toContain('actual_price_input: prefillPriceInput(pickCostPriceHint(first)),'); + }); + + it('不再用 toInputString 预填(会把 0 渲染成真实值)', () => { + expect(src).not.toContain("actual_price_input: toInputString(pickCostPriceHint(row), ''),"); + expect(src).not.toContain("actual_price_input: toInputString(pickCostPriceHint(first), ''),"); + }); +}); diff --git a/src/pages/purchase/selfPurchaseSpecColumn.contract.test.ts b/src/pages/purchase/selfPurchaseSpecColumn.contract.test.ts index b2751c2..31ee08c 100644 --- a/src/pages/purchase/selfPurchaseSpecColumn.contract.test.ts +++ b/src/pages/purchase/selfPurchaseSpecColumn.contract.test.ts @@ -41,6 +41,15 @@ describe('小程序自采列表:卡片展示规格(空则不显示)', () = expect(panelWxml).toContain('product-row-spec'); }); + it('规格整行显示在卡片行下方(不在商品名列里,避免折行)', () => { + const at = panelWxml.indexOf('class="product-row-name"'); + const nameBlock = panelWxml.slice(at, panelWxml.indexOf('', at)); + expect(nameBlock, '规格不得再挤在商品名列里').not.toContain('product-row-spec'); + expect(panelWxml).toContain( + '规格:{{product.specText}}' + ); + }); + it('wxss 有 .product-row-spec 样式', () => { expect(panelWxss).toContain('.product-row-spec'); });