小程序自采列表: 规格整行显示 + 单价预填去 0
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s

① 规格从商品名列(被单位/数量/单价挤到极窄、规格与商品名都折行)移到卡片行下方独占一行;
② 单价输入预填去 0:0 视为未定价 ⇒ 留空(点击即可直接填,无需先删 0),>0 才预填;pickCostPriceHint 的「0 合法」语义不变。
均只改自采列表卡片,新增两条契约测试。
This commit is contained in:
雨天
2026-10-16 17:21:56 +08:00
parent f2e4980dce
commit 6db5eb9e77
6 changed files with 62 additions and 9 deletions
@@ -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 ⇒ 留空,点击即可直接填) |
@@ -106,7 +106,6 @@
>{{product.photoCount > 0 ? '已拍' + product.photoCount : (product.photoRequired ? '拍照' : '拍照')}}</view>
<view class="product-row-name">
<text class="task-title ptp-row-title">{{product.productName}}</text>
<text wx:if="{{product.specText}}" class="product-row-spec">规格:{{product.specText}}</text>
<text wx:if="{{product.remarkText}}" class="product-row-remark">{{product.remarkText}}</text>
<text wx:if="{{product.warehouseDemandRecord}}" class="task-sub">仓内加工 · 只读记录</text>
</view>
@@ -158,6 +157,8 @@
>转供应商</view>
</view>
<view wx:if="{{product.specText}}" class="product-row-spec">规格:{{product.specText}}</view>
<view wx:if="{{product.needs_product_setup}}" class="setup-hint">未匹配商品库,请在下方逐单确认名称和分类</view>
<view wx:if="{{product.needs_product_setup}}" class="product-children">
@@ -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;
}
+12 -2
View File
@@ -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),
@@ -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), ''),");
});
});
@@ -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('</view>', at));
expect(nameBlock, '规格不得再挤在商品名列里').not.toContain('product-row-spec');
expect(panelWxml).toContain(
'<view wx:if="{{product.specText}}" class="product-row-spec">规格:{{product.specText}}</view>'
);
});
it('wxss 有 .product-row-spec 样式', () => {
expect(panelWxss).toContain('.product-row-spec');
});