fix: 仓库/业务类型下拉改用 api 模式加载,selectedStorId 追踪修复

- storId/billType Select 用 api + labelField + valueField 标准模式
- loadWarehouseOptions 同时填充 warehouseMap 供提交时查 storCode/storName
- selectedStorId 通过 Select onChange 同步 + formApi.getValues fallback
- 移除无效的 formApi.setProps/getSchema hack
This commit is contained in:
zhouz
2026-07-22 13:23:24 +08:00
parent 890edbc948
commit e018ad54cc

View File

@@ -1,5 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import { computed, ref, watch } from 'vue'; import { ref, watch } from 'vue';
import { useVbenModal } from '@vben/common-ui'; import { useVbenModal } from '@vben/common-ui';
@@ -10,7 +10,6 @@ import { useVbenForm } from '#/adapter/form';
import { VxeColumn, VxeTable } from '#/adapter/vxe-table'; import { VxeColumn, VxeTable } from '#/adapter/vxe-table';
import { import {
type OutboundCreateReq, type OutboundCreateReq,
type OutboundDetail,
createIostorInvWithDetails, createIostorInvWithDetails,
} from '#/api/wms/iostorinv'; } from '#/api/wms/iostorinv';
import { getBsrealStorAttrSimpleList } from '#/api/wms/bsrealstorattr'; import { getBsrealStorAttrSimpleList } from '#/api/wms/bsrealstorattr';
@@ -23,22 +22,22 @@ import ManualDetailModalComponent from './manual-detail.vue';
const emit = defineEmits(['success']); const emit = defineEmits(['success']);
// ========== 仓库选项 ========== // ========== 仓库选项 ==========
const storOptions = ref<any[]>([]); const warehouseMap = ref<Record<string, any>>({});
async function loadStorOptions() { async function loadWarehouseOptions() {
const list = await getBsrealStorAttrSimpleList(); const list = await getBsrealStorAttrSimpleList();
storOptions.value = (list || []).map((item: any) => ({ const map: Record<string, any> = {};
label: item.storName, const result = (list || []).map((item: any) => {
value: item.storId, map[item.storId] = item;
storCode: item.storCode, return { ...item };
storName: item.storName, });
})); warehouseMap.value = map;
return result;
} }
// ========== 业务类型选项 ========== // ========== 业务类型选项 ==========
const billTypeOptions = ref<any[]>([]);
async function loadBillTypeOptions() { async function loadBillTypeOptions() {
const list = await getSimpleDictDataList(); const list = await getSimpleDictDataList();
billTypeOptions.value = (list || []) return (list || [])
.filter((d: any) => d.dictType === 'out_bill_type') .filter((d: any) => d.dictType === 'out_bill_type')
.map((d: any) => ({ label: d.label, value: d.value })); .map((d: any) => ({ label: d.label, value: d.value }));
} }
@@ -58,9 +57,11 @@ const [Form, formApi] = useVbenForm({
rules: 'required', rules: 'required',
component: 'Select', component: 'Select',
componentProps: { componentProps: {
options: storOptions, api: loadWarehouseOptions,
labelField: 'storName',
valueField: 'storId',
placeholder: '请选择仓库', placeholder: '请选择仓库',
fieldNames: { label: 'label', value: 'value' }, allowClear: true,
onChange: (val: string) => { onChange: (val: string) => {
selectedStorId.value = val || ''; selectedStorId.value = val || '';
}, },
@@ -72,8 +73,11 @@ const [Form, formApi] = useVbenForm({
rules: 'required', rules: 'required',
component: 'Select', component: 'Select',
componentProps: { componentProps: {
options: billTypeOptions, api: loadBillTypeOptions,
labelField: 'label',
valueField: 'value',
placeholder: '请选择业务类型', placeholder: '请选择业务类型',
allowClear: true,
}, },
}, },
{ {
@@ -218,12 +222,12 @@ const [Modal, modalApi] = useVbenModal({
} }
modalApi.lock(); modalApi.lock();
try { try {
const stor = storOptions.value.find((s) => s.value === masterValues.storId); const wh = warehouseMap.value[masterValues.storId];
const req: OutboundCreateReq = { const req: OutboundCreateReq = {
billType: masterValues.billType, billType: masterValues.billType,
storId: masterValues.storId, storId: masterValues.storId,
storCode: stor?.storCode, storCode: wh?.storCode,
storName: stor?.storName, storName: wh?.storName,
bizDate: masterValues.bizDate, bizDate: masterValues.bizDate,
remark: masterValues.remark, remark: masterValues.remark,
details: detailList.value.map((d: any) => ({ details: detailList.value.map((d: any) => ({
@@ -251,8 +255,6 @@ const [Modal, modalApi] = useVbenModal({
}, },
async onOpenChange(isOpen: boolean) { async onOpenChange(isOpen: boolean) {
if (isOpen) { if (isOpen) {
await loadStorOptions();
await loadBillTypeOptions();
formApi.setValues({ bizDate: dayjs().format('YYYY-MM-DD HH:mm:ss') }); formApi.setValues({ bizDate: dayjs().format('YYYY-MM-DD HH:mm:ss') });
} }
if (!isOpen) { if (!isOpen) {