fix(库存入库/新建商品): 分类框移到规格行下方 + 换成原生输入框/datalist(真机打不进字)
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

## 为什么上一轮没生效(我的问题)
上一轮我改的是 `QuickCreateProductModal`(**录单**用的新建商品弹窗),
而**库存入库**的「新建商品」弹窗其实在 `StockInboundPanel.tsx` 里(自带一套字段)——
两个不同组件,所以你看的那个弹窗一个字都没变。

## 真正的差异(截图 + 代码定位)
该弹窗里四个字段中,**规格 / 单位 / 生产地区本来就是原生 `<input>`**(单位还已经用了 datalist),
**只有「分类」用了共享组件 `SearchableSelect`**:
- 它的下拉是 **portal 到 body 的浮层**,会盖住下面的规格/单位/生产地区;
- 它的输入框 `value` 绑的是内部 `inputDisplay`(`open ? query : 选中项 label`,SearchableSelect.tsx:336)
  ⇒ 真机上**打不进字**、点别的字段却操作到分类。

## 本次改动(按开发者要求「把分类放到规格这行的下方」)
`StockInboundPanel.tsx` 的新建商品弹窗:
- **位置**:分类由「商品名之后」移到「规格 / 单位 / 生产地区」这一行**下方**;
- **控件**:换成与旁边字段**同款的原生 `<input>` + `<datalist id="stock-inbound-categories">`**
  —— 无浮层、输入天然可用、不遮挡任何字段;输入命中分类名 ⇒ 回填 `categoryCode`。
(识别结果表格里那个逐行「分类格」保持原样,未动;录单弹窗上一轮的改动也保留。)

## 验证与边界
- 前端 `tsc --noEmit`:**0 错**;`stockInboundPanelShelfLife.contract.test.ts` 通过。
- ⚠️ 仍未做浏览器目视验证(本机无 playwright/puppeteer 模块)。**请刷新页面**后确认:
  ① 分类框能正常打字;② 它位于规格那一行**下方**;③ 选中分类后「确定」能建出商品。
This commit is contained in:
Ubuntu
2026-10-17 08:30:50 +08:00
parent 91c9618399
commit b1ca4e68c5
+26 -10
View File
@@ -984,6 +984,11 @@ export const StockInboundPanel: React.FC = () => {
<option key={u} value={u} />
))}
</datalist>
<datalist id="stock-inbound-categories">
{categoryOptions.map((item) => (
<option key={item.value} value={item.label} />
))}
</datalist>
{/* B:新建商品弹窗(2026-11-02) */}
<Modal
@@ -1023,16 +1028,6 @@ export const StockInboundPanel: React.FC = () => {
onChange={(e) => setNewProductDraft((d) => (d ? { ...d, name: e.target.value } : d))}
/>
</label>
<label className="block text-sm">
<span className="app-foreground-muted mb-1 block">{t('inventory.stockIn.phCategory')}</span>
<SearchableSelect
className="w-full"
value={newProductDraft?.categoryCode || ''}
onChange={(code) => setNewProductDraft((d) => (d ? { ...d, categoryCode: code } : d))}
options={categoryOptions}
placeholder={t('inventory.stockIn.phCategory')}
/>
</label>
<div className="grid grid-cols-3 gap-2">
<label className="block text-sm">
<span className="app-foreground-muted mb-1 block">{t('inventory.stockIn.phSpec')}</span>
@@ -1060,6 +1055,27 @@ export const StockInboundPanel: React.FC = () => {
/>
</label>
</div>
{/* 「分类」移到规格这一行**下方**,并改用与左邻右舍同款的**原生输入框 + datalist**
(2026-10-16 真机缺陷):原先只有它用共享 `SearchableSelect`,那个组件的下拉是 portal 到
body 的浮层,会**盖住**下面的规格/单位/生产地区,且它的输入框 `value` 绑的是内部
`inputDisplay`(`open ? query : 选中项 label`)⇒ 真机上**打不进字**、点单位却操作到分类。
原生控件没有浮层、输入天然可用,与旁边的规格/单位/生产地区保持同一套交互。 */}
<label className="block text-sm">
<span className="app-foreground-muted mb-1 block">{t('inventory.stockIn.phCategory')}</span>
<input
className={`${cellCls} w-full`}
list="stock-inbound-categories"
value={
categoryOptions.find((item) => item.value === newProductDraft?.categoryCode)?.label || ''
}
onChange={(e) => {
const next = e.target.value;
const hit = categoryOptions.find((item) => item.label === next);
setNewProductDraft((d) => (d ? { ...d, categoryCode: hit ? hit.value : '' } : d));
}}
placeholder={t('inventory.stockIn.phCategory')}
/>
</label>
</div>
</Modal>
</div>