feat(consignment): 寄售数量支持关闭修改,固定为 1

This commit is contained in:
2026-11-07 13:46:28 +08:00
parent 6e3eb9669b
commit 8758270591
6 changed files with 105 additions and 19 deletions
@@ -1134,11 +1134,12 @@ export default function ConsignmentConfigPanel() {
<Input placeholder="展示在发布页顶部的一句话说明" />
</Form.Item>
<Form.Item
label="显示寄售数量"
label="允许修改寄售数量"
name={['fields', 'quantity']}
valuePropName="checked"
extra="关闭后打手端数量固定为 1,输入框禁用"
>
<Switch checkedChildren="显示" unCheckedChildren="隐藏" />
<Switch checkedChildren="可改" unCheckedChildren="固定 1" />
</Form.Item>
</div>
<Form.Item
@@ -245,7 +245,9 @@ export default function WorkerConsignmentPage() {
finished: 0,
}
const watchedQuantity = Form.useWatch('quantity', form)
const quantityForDeposit = Math.max(1, Number(watchedQuantity || 1))
// 「允许修改寄售数量」关闭时:数量固定 1、输入框禁用,价格/押金一律按 1 件计算。
const quantityLocked = selectedProfile?.config.fields.quantity === false
const quantityForDeposit = quantityLocked ? 1 : Math.max(1, Number(watchedQuantity || 1))
const publishDepositFen = selectedProfile?.config.deposit.enabled
? selectedProfile.config.deposit.mode === 'per_quantity'
? Math.max(0, selectedProfile.config.deposit.unitAmountFen) * quantityForDeposit
@@ -862,11 +864,7 @@ export default function WorkerConsignmentPage() {
})}
</div>
<div
className={`worker-consignment-price-grid${
selectedProfile?.config.fields.quantity === false ? ' is-two' : ''
}`}
>
<div className="worker-consignment-price-grid">
<Form.Item
label="寄售价格"
tooltip={
@@ -907,16 +905,21 @@ export default function WorkerConsignmentPage() {
</div>
)}
</Form.Item>
{selectedProfile?.config.fields.quantity !== false ? (
<Form.Item
label="寄售数量"
name="quantity"
initialValue={1}
className="worker-consignment-spec-card is-price"
>
<InputNumber min={1} precision={0} addonAfter="件" style={{ width: '100%' }} />
</Form.Item>
) : null}
<Form.Item
label="寄售数量"
name="quantity"
initialValue={1}
className="worker-consignment-spec-card is-price"
extra={quantityLocked ? '该分类数量固定为 1,不可修改' : undefined}
>
<InputNumber
min={1}
precision={0}
addonAfter="件"
style={{ width: '100%' }}
disabled={quantityLocked}
/>
</Form.Item>
<Form.Item
label="履约押金"
tooltip="平台统一配置。发布成功后暂扣,驳回或履约完成后释放。"
@@ -0,0 +1,51 @@
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import test from 'node:test'
function read(relativePath: string) {
return readFileSync(fileURLToPath(new URL(relativePath, import.meta.url)), 'utf8').replace(
/\r\n/g,
'\n',
)
}
const panel = read('../src/pages/admin/panels/ConsignmentConfigPanel.tsx')
const page = read('../src/pages/worker/WorkerConsignmentPage.tsx')
test('管理端:数量开关语义必须是「允许修改寄售数量」/「可改 / 固定 1」', () => {
assert.ok(panel.includes('label="允许修改寄售数量"'), '文案必须改成是否允许修改')
assert.ok(panel.includes('extra="关闭后打手端数量固定为 1,输入框禁用"'), '必须说明关闭后的行为')
assert.ok(panel.includes('checkedChildren="可改"'), '开启文案应为「可改」')
assert.ok(panel.includes('unCheckedChildren="固定 1"'), '关闭文案应为「固定 1」')
assert.ok(!panel.includes('label="显示寄售数量"'), '旧的「显示寄售数量」必须移除')
})
test('打手端:数量字段必须始终渲染,关闭时禁用并灰显 1', () => {
assert.ok(
page.includes('const quantityLocked = selectedProfile?.config.fields.quantity === false'),
'必须由 fields.quantity === false 推导锁定状态',
)
assert.ok(page.includes('disabled={quantityLocked}'), '锁定时输入框必须禁用')
assert.ok(
page.includes("extra={quantityLocked ? '该分类数量固定为 1,不可修改' : undefined}"),
'锁定时要给出固定 1 的提示',
)
assert.ok(
!page.includes('selectedProfile?.config.fields.quantity !== false ? ('),
'不能再按开关隐藏数量字段',
)
assert.ok(page.includes('initialValue={1}'), '数量默认值必须为 1')
assert.ok(
page.includes('const quantityForDeposit = quantityLocked ? 1 :'),
'锁定后押金必须按 1 件计算',
)
})
test('打手端:数量始终显示,价格区固定三列,不再按数量切两列', () => {
assert.ok(page.includes('className="worker-consignment-price-grid"'), '价格区必须固定三列')
assert.ok(
!page.includes("selectedProfile?.config.fields.quantity === false ? ' is-two' : ''"),
'不能再用 is-two 布局',
)
})