完善出库闭环和前端作业体验

This commit is contained in:
zhougf committed 2026-06-03 23:25:41 +08:00
1 parent 3c6dfda5e5
commit ce0fd7ec52
21 files changed
+1495 -261

No files matched your search

+297 -27
View File
@@ -9,12 +9,15 @@ import {
ProTable,
} from '@ant-design/pro-components';
import type { ColumnsType } from 'antd/es/table';
import { Button, Drawer, Form, Input, InputNumber, message, Modal, Select, Space, Table, Typography } from 'antd';
import { Button, Drawer, Form, Input, InputNumber, message, Modal, Popconfirm, Select, Space, Table, Tag, Typography } from 'antd';
import type { FormListFieldData } from 'antd/es/form/FormList';
import { EyeOutlined, PlusOutlined, ReloadOutlined } from '@ant-design/icons';
import { CheckOutlined, EyeOutlined, PlusOutlined, ReloadOutlined } from '@ant-design/icons';
import {
actionRecord,
addOrderLine,
confirmOutboundPickTask,
confirmInboundLine,
createOrderHeader,
createRecord,
getOutboundPickTasks,
getRecordLines,
@@ -49,6 +52,7 @@ const ORDER_ACTIONS: Record<OrderKind, OrderActionDef[]> = {
outbound: [
{ label: '待拣', backendAction: 'pending' },
{ label: '确认出库', backendAction: 'confirm' },
{ label: '取消', backendAction: 'cancel' },
],
transfer: [
{ label: '待处理', backendAction: 'pending' },
@@ -137,7 +141,6 @@ function createEmptyLine(kind: OrderKind): Record<string, any> {
areaCode: '',
locationCode: '',
qty: 0,
unit: 'pcs',
};
case 'transfer':
return {
@@ -181,6 +184,9 @@ function normalizeLinesForSubmit(lines: Record<string, any>[]) {
if ('locationCode' in next && !String(next.locationCode ?? '').trim()) {
delete next.locationCode;
}
if ('unit' in next && !String(next.unit ?? '').trim()) {
delete next.unit;
}
if ('qty' in next) next.qty = Number(next.qty);
if ('countedQty' in next && next.countedQty !== undefined && next.countedQty !== '')
next.countedQty = Number(next.countedQty);
@@ -573,14 +579,12 @@ function outboundLinesEditorColumns(
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',
@@ -638,6 +642,42 @@ function lineIsFullyReceived(row: Record<string, any>) {
return s === 'completed' || s === 'Completed' || s === 2;
}
function orderIsDraft(row?: Record<string, any> | null) {
const s = row?.orderStatus;
return s === 'draft' || s === 'Draft' || s === 1;
}
function normalizeStatusKey(value: unknown) {
if (value === 1) return 'draft';
if (value === 2) return 'pending';
if (value === 3) return 'completed';
if (value === 4) return 'cancelled';
return String(value ?? '').trim().toLowerCase();
}
function orderStatusColor(value: unknown) {
const key = normalizeStatusKey(value);
if (key === 'draft') return 'default';
if (key === 'pending') return 'processing';
if (key === 'completed') return 'success';
if (key === 'cancelled' || key === 'canceled') return 'error';
return 'default';
}
function orderStatusFallback(value: unknown) {
const key = normalizeStatusKey(value);
if (key === 'draft') return '草稿';
if (key === 'pending') return '待处理';
if (key === 'completed') return '已完成';
if (key === 'cancelled' || key === 'canceled') return '已取消';
return String(value ?? '-');
}
function renderOrderStatusTag(value: unknown, label?: React.ReactNode) {
const text = label && String(label).trim() ? label : orderStatusFallback(value);
return <Tag color={orderStatusColor(value)}>{text}</Tag>;
}
function viewerColumnsForKind(kind: OrderKind): ProColumns<Record<string, any>>[] {
if (kind === 'inbound') {
const defs = INBOUND_LINE_FIELDS.filter((d) => d.key !== 'attrsJson');
@@ -756,8 +796,10 @@ export default function OrderPage({ title, controller, kind }: OrderPageProps) {
const actionRef = useRef<ActionType>();
const viewerOrderIdRef = useRef<string | number | null>(null);
const [createOpen, setCreateOpen] = useState(false);
const [addLineOpen, setAddLineOpen] = useState(false);
const [viewerOpen, setViewerOpen] = useState(false);
const [viewerLoading, setViewerLoading] = useState(false);
const [viewerRecord, setViewerRecord] = useState<Record<string, any> | null>(null);
const [viewerLines, setViewerLines] = useState<Record<string, any>[]>([]);
const [viewerPickTasks, setViewerPickTasks] = useState<Record<string, any>[]>([]);
const [viewerTitle, setViewerTitle] = useState('');
@@ -767,6 +809,7 @@ export default function OrderPage({ title, controller, kind }: OrderPageProps) {
const [locationOptions, setLocationOptions] = useState<{ label: string; value: string }[]>([]);
const [confirmForm] = Form.useForm();
const [createForm] = Form.useForm();
const [addLineForm] = Form.useForm();
const fetchConfirmContainerPage = useCallback(async (keyword: string) => {
const res = await pagedList<Record<string, any>>('Container', {
@@ -813,9 +856,20 @@ export default function OrderPage({ title, controller, kind }: OrderPageProps) {
const headerColumns = useMemo(
() =>
headerColumnsBase.map((col): ProColumns<OrderRow> => {
if (col.dataIndex === 'orderNo') {
return {
...col,
render: (_, row) => <span className="wms-order-no">{row.orderNo || '-'}</span>,
};
}
if (col.dataIndex === 'orderStatus') {
const valueEnum = buildValueEnum('OrderStatus');
return Object.keys(valueEnum).length ? { ...col, valueEnum } : col;
return {
...col,
...(Object.keys(valueEnum).length ? { valueEnum } : {}),
render: (_, row) =>
renderOrderStatusTag(row.orderStatus, resolveLabel('OrderStatus', row.orderStatus)),
};
}
if (col.dataIndex === 'bizType') {
const valueEnum = buildValueEnum(bizTypeDictCategory);
@@ -823,7 +877,7 @@ export default function OrderPage({ title, controller, kind }: OrderPageProps) {
}
return col;
}),
[buildValueEnum, bizTypeDictCategory],
[buildValueEnum, bizTypeDictCategory, resolveLabel],
);
const refreshViewerLines = useCallback(async () => {
@@ -841,6 +895,20 @@ export default function OrderPage({ title, controller, kind }: OrderPageProps) {
}
}, [controller, kind]);
const confirmPickTask = useCallback(
async (task: Record<string, any>) => {
if (!task.id) return;
await confirmOutboundPickTask({
id: task.id,
pickedQty: Number(task.qty),
});
message.success('拣货已确认');
await refreshViewerLines();
actionRef.current?.reload();
},
[refreshViewerLines],
);
const openConfirmInbound = useCallback(
async (line: Record<string, any>) => {
setConfirmLine(line);
@@ -877,6 +945,7 @@ export default function OrderPage({ title, controller, kind }: OrderPageProps) {
const openViewer = useCallback(
async (record: Record<string, any>) => {
viewerOrderIdRef.current = record.id;
setViewerRecord(record);
setViewerTitle(`${record.orderNo || record.id}`);
setViewerOpen(true);
setViewerLoading(true);
@@ -946,6 +1015,15 @@ export default function OrderPage({ title, controller, kind }: OrderPageProps) {
{ title: '应拣', dataIndex: 'qty', width: 88 },
{ title: '已拣', dataIndex: 'pickedQty', width: 88 },
{ title: '单位', dataIndex: 'unit', width: 72 },
{ title: '拣货人', dataIndex: 'pickerUserId', width: 120, ellipsis: true },
{
title: '拣货时间',
dataIndex: 'pickedTime',
width: 168,
ellipsis: true,
render: (_, row) => row.pickedTime || '-',
},
{ title: '异常原因', dataIndex: 'exceptionReason', width: 160, ellipsis: true },
{
title: '状态',
dataIndex: 'taskStatus',
@@ -957,8 +1035,31 @@ export default function OrderPage({ title, controller, kind }: OrderPageProps) {
return '待拣';
},
},
{
title: '操作',
key: 'pickAction',
width: 110,
fixed: 'right',
render: (_, row) => {
const s = row.taskStatus;
const isOpen = s === 'open' || s === 'Open' || s === 1;
if (!isOpen) return '-';
return (
<Popconfirm
title="确认该拣货任务已完成?"
okText="确认"
cancelText="取消"
onConfirm={() => confirmPickTask(row)}
>
<Button type="link" size="small" icon={<CheckOutlined />}>
确认拣货
</Button>
</Popconfirm>
);
},
},
],
[],
[confirmPickTask],
);
const createInitialValues = useMemo(
@@ -969,6 +1070,13 @@ export default function OrderPage({ title, controller, kind }: OrderPageProps) {
[kind],
);
const addLineInitialValues = useMemo(
() => ({ lines: [createEmptyLine(kind)] }),
[kind],
);
const canMaintainLines = kind === 'inbound' || kind === 'outbound';
const createModalWidth = kind === 'inbound' || kind === 'outbound' ? 1180 : 1040;
return (
@@ -982,7 +1090,7 @@ export default function OrderPage({ title, controller, kind }: OrderPageProps) {
{
title: '操作',
valueType: 'option',
width: kind === 'inbound' ? 140 : 220,
width: kind === 'inbound' ? 140 : kind === 'outbound' ? 280 : 220,
fixed: 'right',
search: false,
render: (_, record) => (
@@ -990,20 +1098,40 @@ export default function OrderPage({ title, controller, kind }: OrderPageProps) {
<Button type="link" size="small" icon={<EyeOutlined />} onClick={() => openViewer(record)}>
查看明细
</Button>
{actions.map((a, idx) => (
<Button
key={`${a.backendAction}-${idx}-${a.label}`}
type="link"
size="small"
onClick={async () => {
await actionRecord(controller, a.backendAction, record.id);
message.success('操作成功');
actionRef.current?.reload();
}}
>
{a.label}
</Button>
))}
{actions.map((a, idx) => {
const button = (
<Button
key={`${a.backendAction}-${idx}-${a.label}`}
type="link"
size="small"
onClick={async () => {
await actionRecord(controller, a.backendAction, record.id);
message.success('操作成功');
actionRef.current?.reload();
}}
>
{a.label}
</Button>
);
if (a.backendAction !== 'cancel') return button;
return (
<Popconfirm
key={`${a.backendAction}-${idx}-${a.label}`}
title="取消出库单会释放已预占库存,确认继续?"
okText="确认"
cancelText="取消"
onConfirm={async () => {
await actionRecord(controller, a.backendAction, record.id);
message.success('操作成功');
actionRef.current?.reload();
}}
>
<Button type="link" size="small">
{a.label}
</Button>
</Popconfirm>
);
})}
</Space>
),
},
@@ -1016,6 +1144,23 @@ export default function OrderPage({ title, controller, kind }: OrderPageProps) {
<Button key="reload" icon={<ReloadOutlined />} onClick={() => actionRef.current?.reload()}>
刷新
</Button>,
...(canMaintainLines
? [
<Button
key="new-header"
onClick={async () => {
await createOrderHeader(controller, {
bizType: `${kind}_default`,
...(kind === 'outbound' ? { attrs: {} } : {}),
});
message.success('单头创建成功');
actionRef.current?.reload();
}}
>
新增单头
</Button>,
]
: []),
<Button key="new" type="primary" icon={<PlusOutlined />} onClick={() => setCreateOpen(true)}>
新增
</Button>,
@@ -1114,13 +1259,140 @@ export default function OrderPage({ title, controller, kind }: OrderPageProps) {
</Form.Item>
</ModalForm>
<ModalForm
title={`新增${title}明细`}
width={kind === 'inbound' || kind === 'outbound' ? 1180 : 1040}
open={addLineOpen}
initialValues={addLineInitialValues}
key={`${kind}-add-line`}
form={addLineForm}
modalProps={{
destroyOnHidden: true,
onCancel: () => setAddLineOpen(false),
}}
onFinish={async (values) => {
const orderId = viewerOrderIdRef.current;
if (!orderId) {
message.error('请先打开单据详情');
return false;
}
const lines = values.lines as Record<string, any>[];
if (!lines?.length) {
message.error('请至少添加一行明细');
return false;
}
const normalized = normalizeLinesForSubmit(lines);
if (kind === 'inbound' && !validateInboundCreateLines(normalized)) return false;
for (const line of normalized) {
await addOrderLine(controller, { orderId, line });
}
message.success('明细添加成功');
setAddLineOpen(false);
await refreshViewerLines();
actionRef.current?.reload();
return true;
}}
>
<Form.Item label="明细" required style={{ marginBottom: 0 }}>
<Form.List name="lines">
{(fields, { add, remove }) => (
<>
<Table<FormListFieldData>
size="small"
pagination={false}
scroll={{ x: 'max-content' }}
dataSource={fields}
rowKey="key"
columns={
kind === 'inbound'
? inboundLinesEditorColumns(fields, remove, inventoryKindInboundOpts)
: (linesEditorColumns(kind, fields, remove) as ColumnsType<FormListFieldData>)
}
/>
<Button
type="dashed"
block
style={{ marginTop: 8 }}
onClick={() => add(createEmptyLine(kind))}
>
新增明细行
</Button>
</>
)}
</Form.List>
</Form.Item>
</ModalForm>
<Drawer
title={`单据明细 — ${viewerTitle}`}
open={viewerOpen}
width={kind === 'inbound' || kind === 'outbound' ? 1280 : 1040}
destroyOnHidden
onClose={() => setViewerOpen(false)}
extra={
canMaintainLines && orderIsDraft(viewerRecord) ? (
<Button
type="primary"
size="small"
icon={<PlusOutlined />}
onClick={() => {
addLineForm.resetFields();
addLineForm.setFieldsValue(addLineInitialValues);
setAddLineOpen(true);
}}
>
新增明细
</Button>
) : null
}
onClose={() => {
setViewerOpen(false);
setViewerRecord(null);
}}
>
<div className="wms-order-detail-head">
<div className="wms-order-detail-title">
<div>
<div className="wms-order-detail-title-main">{viewerRecord?.orderNo || viewerTitle || '-'}</div>
<Typography.Text type="secondary">{title}</Typography.Text>
</div>
{renderOrderStatusTag(
viewerRecord?.orderStatus,
resolveLabel('OrderStatus', viewerRecord?.orderStatus),
)}
</div>
<div className="wms-order-detail-meta">
<div>
<div className="wms-order-detail-meta-label">业务类型</div>
<div className="wms-order-detail-meta-value">
{viewerRecord?.bizType
? resolveLabel(bizTypeDictCategory, viewerRecord.bizType) || viewerRecord.bizType
: '-'}
</div>
</div>
<div>
<div className="wms-order-detail-meta-label">明细行数</div>
<div className="wms-order-detail-meta-value">{viewerLines.length}</div>
</div>
{kind === 'outbound' && (
<div>
<div className="wms-order-detail-meta-label">拣货任务</div>
<div className="wms-order-detail-meta-value">{viewerPickTasks.length}</div>
</div>
)}
<div>
<div className="wms-order-detail-meta-label">创建时间</div>
<div className="wms-order-detail-meta-value">{viewerRecord?.createTime || '-'}</div>
</div>
<div>
<div className="wms-order-detail-meta-label">备注</div>
<div className="wms-order-detail-meta-value">{viewerRecord?.remark || '-'}</div>
</div>
</div>
</div>
<ProTable<Record<string, any>>
loading={viewerLoading}
rowKey={(row, i) => String(row.id ?? row.lineNo ?? i)}
@@ -1133,9 +1405,7 @@ export default function OrderPage({ title, controller, kind }: OrderPageProps) {
/>
{kind === 'outbound' && (
<>
<Typography.Title level={5} style={{ marginTop: 16, marginBottom: 8 }}>
拣货任务
</Typography.Title>
<div className="wms-section-title">拣货任务</div>
<ProTable<Record<string, any>>
loading={viewerLoading}
rowKey={(row, i) => String(row.id ?? row.taskNo ?? i)}