fix: storId 选择追踪 — 用 onChange + selectedStorId ref + fallback

- Select onChange 同步选中的仓库 ID 到 selectedStorId ref
- handleSelectFromInventory fallback 兜底 formApi.getValues().storId
- 仓库切换 watch selectedStorId 清空明细
This commit is contained in:
zhouz
2026-07-22 13:21:16 +08:00
parent ec05ee98d0
commit 890edbc948

View File

@@ -61,6 +61,9 @@ const [Form, formApi] = useVbenForm({
options: storOptions,
placeholder: '请选择仓库',
fieldNames: { label: 'label', value: 'value' },
onChange: (val: string) => {
selectedStorId.value = val || '';
},
},
},
{
@@ -132,14 +135,14 @@ function updateSummary() {
});
}
// 当前选中的仓库 ID独立追踪避免 formApi.getValues() 拿到旧值)
const selectedStorId = ref('');
// 仓库切换 → 清空明细
watch(
() => formApi.getValues().storId,
() => {
detailList.value = [];
updateSummary();
},
);
watch(selectedStorId, () => {
detailList.value = [];
updateSummary();
});
function handleDeleteDetail(index: number) {
detailList.value.splice(index, 1);
@@ -150,7 +153,10 @@ function handleDeleteDetail(index: number) {
const inventorySelectRef = ref<any>();
function handleSelectFromInventory() {
const storId = formApi.getValues().storId;
let storId = selectedStorId.value;
if (!storId) {
storId = formApi.getValues().storId; // fallback
}
if (!storId) {
message.warning('请先选择仓库');
return;