库存展示修改 主数据层级联动

This commit is contained in:
zhougf committed 2026-06-01 23:49:07 +08:00
1 parent 7f621dd553
commit 3c6dfda5e5
13 files changed
+488 -42

No files matched your search

+123 -8
View File
@@ -9,7 +9,7 @@ import {
ProTable,
} from '@ant-design/pro-components';
import type { ColumnsType } from 'antd/es/table';
import { Button, Form, Input, InputNumber, message, Modal, Select, Space, Table, Typography } from 'antd';
import { Button, Drawer, Form, Input, InputNumber, message, Modal, Select, Space, Table, Typography } from 'antd';
import type { FormListFieldData } from 'antd/es/form/FormList';
import { EyeOutlined, PlusOutlined, ReloadOutlined } from '@ant-design/icons';
import {
@@ -23,6 +23,7 @@ import {
} from '@/services/api';
import { useDictionary } from '@/contexts/DictionaryContext';
import type { OrderRow } from '@/types/orders';
import MasterDataSelect from './MasterDataSelect';
type OrderKind = 'inbound' | 'outbound' | 'transfer' | 'stocktake';
@@ -483,11 +484,126 @@ function inboundLinesEditorColumns(
return cols;
}
function OutboundMaterialCell({ rowKey }: { rowKey: React.Key }) {
const form = Form.useFormInstance();
return (
<Form.Item noStyle dependencies={[['lines', rowKey, 'inventoryKind']]}>
{() => {
const ik = Number(form.getFieldValue(['lines', rowKey, 'inventoryKind']) ?? 1);
if (ik === 2) return <span style={{ color: '#999' }}>-</span>;
return (
<Form.Item name={[rowKey as never, 'materialCode']} rules={[{ required: true, message: '请选择物料' }]} noStyle>
<MasterDataSelect controller="Material" placeholder="搜物料编码/名称" size="small" style={{ minWidth: 180 }} />
</Form.Item>
);
}}
</Form.Item>
);
}
function OutboundWarehouseCell({ rowKey }: { rowKey: React.Key }) {
const form = Form.useFormInstance();
return (
<Form.Item name={[rowKey as never, 'warehouseCode']} rules={[{ required: true, message: '请选择仓库' }]} noStyle>
<MasterDataSelect
controller="Warehouse"
placeholder="搜仓库"
size="small"
style={{ minWidth: 160 }}
afterChange={() => {
form.setFieldValue(['lines', rowKey, 'areaCode'], undefined);
form.setFieldValue(['lines', rowKey, 'locationCode'], undefined);
}}
/>
</Form.Item>
);
}
function OutboundAreaCell({ rowKey }: { rowKey: React.Key }) {
const form = Form.useFormInstance();
return (
<Form.Item noStyle dependencies={[['lines', rowKey, 'warehouseCode']]}>
{() => {
const warehouseCode = String(form.getFieldValue(['lines', rowKey, 'warehouseCode']) || '').trim();
return (
<Form.Item name={[rowKey as never, 'areaCode']} rules={[{ required: true, message: '请选择库区' }]} noStyle>
<MasterDataSelect
controller="Area"
placeholder={warehouseCode ? '搜库区' : '先选仓库'}
size="small"
style={{ minWidth: 150 }}
disabled={!warehouseCode}
buildParams={(keyword) => ({ warehouseCode, ...(keyword ? { keyword } : {}) })}
afterChange={() => form.setFieldValue(['lines', rowKey, 'locationCode'], undefined)}
/>
</Form.Item>
);
}}
</Form.Item>
);
}
function OutboundLocationCell({ rowKey }: { rowKey: React.Key }) {
const form = Form.useFormInstance();
return (
<Form.Item noStyle dependencies={[['lines', rowKey, 'warehouseCode'], ['lines', rowKey, 'areaCode']]}>
{() => {
const warehouseCode = String(form.getFieldValue(['lines', rowKey, 'warehouseCode']) || '').trim();
const areaCode = String(form.getFieldValue(['lines', rowKey, 'areaCode']) || '').trim();
const disabled = !warehouseCode || !areaCode;
return (
<Form.Item name={[rowKey as never, 'locationCode']} noStyle>
<MasterDataSelect
controller="Location"
placeholder={disabled ? '自动分配' : '可选指定库位'}
size="small"
style={{ minWidth: 160 }}
disabled={disabled}
buildParams={(keyword) => ({ warehouseCode, areaCode, ...(keyword ? { keyword } : {}) })}
/>
</Form.Item>
);
}}
</Form.Item>
);
}
function outboundLinesEditorColumns(
fields: FormListFieldData[],
remove: (index: number | number[]) => void,
): ColumnsType<FormListFieldData> {
const qtyDef: LineFieldDef = { key: 'qty', title: '数量', width: 88, type: 'number', required: true };
const unitDef: LineFieldDef = { key: 'unit', title: '单位', width: 72, type: 'text', required: true };
return [
{ title: '物料', key: 'materialCode', width: 220, render: (_u, rowField) => <OutboundMaterialCell rowKey={rowField.name} /> },
{ title: '仓库', key: 'warehouseCode', width: 180, render: (_u, rowField) => <OutboundWarehouseCell rowKey={rowField.name} /> },
{ title: '库区', key: 'areaCode', width: 170, render: (_u, rowField) => <OutboundAreaCell rowKey={rowField.name} /> },
{ title: '指定库位', key: 'locationCode', width: 180, render: (_u, rowField) => <OutboundLocationCell rowKey={rowField.name} /> },
{ title: '数量', key: 'qty', width: 100, render: (_u, rowField) => renderLineCell(rowField, qtyDef) },
{ title: '单位', key: 'unit', width: 90, render: (_u, rowField) => renderLineCell(rowField, unitDef) },
{
title: '操作',
key: '_op',
width: 56,
fixed: 'right',
render: (_u, rowField) => (
<Button type="link" size="small" danger disabled={fields.length <= 1} onClick={() => remove(rowField.name)}>
删
</Button>
),
},
];
}
function linesEditorColumns(
kind: OrderKind,
fields: FormListFieldData[],
remove: (index: number | number[]) => void,
): any[] {
if (kind === 'outbound') {
return outboundLinesEditorColumns(fields, remove);
}
const defs = lineFieldsForKind(kind);
const cols: any[] = defs.map((def) => ({
title: def.title,
@@ -853,7 +969,7 @@ export default function OrderPage({ title, controller, kind }: OrderPageProps) {
[kind],
);
const createModalWidth = kind === 'inbound' ? 1180 : 1040;
const createModalWidth = kind === 'inbound' || kind === 'outbound' ? 1180 : 1040;
return (
<>
@@ -935,7 +1051,7 @@ export default function OrderPage({ title, controller, kind }: OrderPageProps) {
});
} else {
await createRecord(controller, {
orderNo: values.orderNo,
...(kind === 'outbound' ? {} : { orderNo: values.orderNo }),
bizType: values.bizType,
remark: values.remark,
attrs: parseJsonObject(values.attrsJson, {}),
@@ -948,7 +1064,7 @@ export default function OrderPage({ title, controller, kind }: OrderPageProps) {
return true;
}}
>
{kind !== 'inbound' && (
{kind !== 'inbound' && kind !== 'outbound' && (
<ProFormText name="orderNo" label="单号" rules={[{ required: true, message: '请输入单号' }]} />
)}
{kind === 'inbound' ? (
@@ -998,13 +1114,12 @@ export default function OrderPage({ title, controller, kind }: OrderPageProps) {
</Form.Item>
</ModalForm>
<Modal
<Drawer
title={`单据明细 — ${viewerTitle}`}
open={viewerOpen}
width={kind === 'inbound' || kind === 'outbound' ? 1280 : 1040}
footer={null}
destroyOnHidden
onCancel={() => setViewerOpen(false)}
onClose={() => setViewerOpen(false)}
>
<ProTable<Record<string, any>>
loading={viewerLoading}
@@ -1034,7 +1149,7 @@ export default function OrderPage({ title, controller, kind }: OrderPageProps) {
/>
</>
)}
</Modal>
</Drawer>
<Modal
title="确认入库"