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

This commit is contained in:
Mac mini git server 2026-06-01 23:49:07 +08:00
parent 7f621dd553
commit 3c6dfda5e5
13 changed files with 488 additions and 42 deletions

View File

@ -41,6 +41,8 @@ public class InventoryViewDto
public decimal Qty { get; set; }
public decimal AvailableQty { get; set; }
public decimal PendingInboundQty { get; set; }
public decimal PendingOutboundQty { get; set; }

View File

@ -7,7 +7,6 @@ namespace WmsLite.Api.Dtos.Orders;
public abstract class OrderSaveRequestBase
{
[Required]
[StringLength(128)]
public string OrderNo { get; set; } = string.Empty;

View File

@ -3,4 +3,6 @@ namespace WmsLite.Api.Services.Interfaces;
public interface IOrderNumberGenerator
{
Task<string> NextInboundOrderNoAsync(string tenantId, string ownerCode, CancellationToken cancellationToken = default);
Task<string> NextOutboundOrderNoAsync(string tenantId, string ownerCode, CancellationToken cancellationToken = default);
}

View File

@ -281,6 +281,7 @@ public class InventoryService : IInventoryService
LocationCode = item.LocationCode,
MaterialName = materialName,
Qty = item.Qty,
AvailableQty = item.Qty - item.PendingOutboundQty - item.FrozenQty,
PendingInboundQty = item.PendingInboundQty,
PendingOutboundQty = item.PendingOutboundQty,
FrozenQty = item.FrozenQty,

View File

@ -15,10 +15,16 @@ public class OrderNumberGenerator : IOrderNumberGenerator
}
public async Task<string> NextInboundOrderNoAsync(string tenantId, string ownerCode, CancellationToken cancellationToken = default)
=> await NextOrderNoAsync<Models.InboundOrder>(tenantId, ownerCode, "IN", "入库单");
public async Task<string> NextOutboundOrderNoAsync(string tenantId, string ownerCode, CancellationToken cancellationToken = default)
=> await NextOrderNoAsync<Models.OutboundOrder>(tenantId, ownerCode, "OUT", "出库单");
private async Task<string> NextOrderNoAsync<TOrder>(string tenantId, string ownerCode, string prefix, string displayName)
where TOrder : Models.BaseEntity, new()
{
var tenant = tenantId.Trim();
var owner = ownerCode.Trim();
var prefix = "IN";
var datePart = DateTime.Now.ToString("yyyyMMdd", CultureInfo.InvariantCulture);
const int maxAttempts = 5;
@ -26,8 +32,9 @@ public class OrderNumberGenerator : IOrderNumberGenerator
{
var seq = await AllocateSequenceAsync(tenant, owner, prefix, datePart);
var no = $"{prefix}{datePart}{seq.ToString("D5", CultureInfo.InvariantCulture)}";
var exists = await _db.Queryable<Models.InboundOrder>()
.Where(x => !x.IsDeleted && x.TenantId == tenant && x.OwnerCode == owner && x.OrderNo == no)
var exists = await _db.Queryable<TOrder>()
.Where(x => !x.IsDeleted && x.TenantId == tenant && x.OwnerCode == owner)
.Where("order_no = @orderNo", new { orderNo = no })
.AnyAsync();
if (!exists)
{
@ -35,7 +42,7 @@ public class OrderNumberGenerator : IOrderNumberGenerator
}
}
throw new BusinessException("生成唯一入库单单号失败,请重试。");
throw new BusinessException($"生成唯一{displayName}单号失败,请重试。");
}
private async Task<int> AllocateSequenceAsync(string tenantId, string ownerCode, string prefix, string dateYyyyMmDd)

View File

@ -574,6 +574,7 @@ public class OutboundOrderService : OrderServiceBase, IOutboundOrderService
private readonly IOutboundPickTaskRepository _pickTaskRepository;
private readonly ILocationRepository _locationRepository;
private readonly IInventoryAllocationService _allocationService;
private readonly IOrderNumberGenerator _orderNumberGenerator;
private readonly ICurrentUserContext _userContext;
public OutboundOrderService(
@ -583,6 +584,7 @@ public class OutboundOrderService : OrderServiceBase, IOutboundOrderService
IOutboundPickTaskRepository pickTaskRepository,
ILocationRepository locationRepository,
IInventoryAllocationService allocationService,
IOrderNumberGenerator orderNumberGenerator,
IInventoryRepository inventoryRepository,
IInventoryMovementService inventoryMovementService,
ICurrentUserContext userContext) : base(inventoryRepository, inventoryMovementService)
@ -593,6 +595,7 @@ public class OutboundOrderService : OrderServiceBase, IOutboundOrderService
_pickTaskRepository = pickTaskRepository;
_locationRepository = locationRepository;
_allocationService = allocationService;
_orderNumberGenerator = orderNumberGenerator;
_userContext = userContext;
}
@ -638,16 +641,22 @@ public class OutboundOrderService : OrderServiceBase, IOutboundOrderService
{
return await _tx.ExecuteAsync(async () =>
{
if (await _orderRepository.GetByOrderNoAsync(_userContext.TenantId.Trim(), _userContext.OwnerCode.Trim(), request.OrderNo) is not null)
var tenantId = _userContext.TenantId.Trim();
var ownerCode = _userContext.OwnerCode.Trim();
var orderNo = string.IsNullOrWhiteSpace(request.OrderNo)
? await _orderNumberGenerator.NextOutboundOrderNoAsync(tenantId, ownerCode)
: request.OrderNo.Trim();
if (await _orderRepository.GetByOrderNoAsync(tenantId, ownerCode, orderNo) is not null)
{
throw new BusinessException($"Outbound order '{request.OrderNo}' already exists.");
throw new BusinessException($"Outbound order '{orderNo}' already exists.");
}
var order = new OutboundOrder
{
TenantId = _userContext.TenantId.Trim(),
OwnerCode = _userContext.OwnerCode.Trim(),
OrderNo = request.OrderNo.Trim(),
TenantId = tenantId,
OwnerCode = ownerCode,
OrderNo = orderNo,
BizType = request.BizType?.Trim(),
Remark = request.Remark?.Trim(),
Attrs = request.Attrs,
@ -891,6 +900,11 @@ public class TransferOrderService : OrderServiceBase, ITransferOrderService
{
return await _tx.ExecuteAsync(async () =>
{
if (string.IsNullOrWhiteSpace(request.OrderNo))
{
throw new BusinessException("OrderNo is required.");
}
if (await _orderRepository.GetByOrderNoAsync(_userContext.TenantId.Trim(), _userContext.OwnerCode.Trim(), request.OrderNo) is not null)
{
throw new BusinessException($"Transfer order '{request.OrderNo}' already exists.");
@ -1066,6 +1080,11 @@ public class StocktakeOrderService : OrderServiceBase, IStocktakeOrderService
{
return await _tx.ExecuteAsync(async () =>
{
if (string.IsNullOrWhiteSpace(request.OrderNo))
{
throw new BusinessException("OrderNo is required.");
}
if (await _orderRepository.GetByOrderNoAsync(_userContext.TenantId.Trim(), _userContext.OwnerCode.Trim(), request.OrderNo) is not null)
{
throw new BusinessException($"Stocktake order '{request.OrderNo}' already exists.");

View File

@ -46,6 +46,7 @@ export type CrudField = {
hideInSearch?: boolean;
/** 是否参与表格搜索;不设则按字段名启发式(编码/名称类默认可搜) */
searchable?: boolean;
formRender?: (ctx: { field: CrudField; isEdit: boolean; disabled: boolean }) => React.ReactNode;
};
type CrudPageProps = {
@ -100,7 +101,10 @@ export default function CrudPage({
const renderFormItem = (field: CrudField) => {
const rules = field.required ? [{ required: true, message: `请输入${field.title}` }] : undefined;
const disabled = field.readOnly || (field.readOnlyOnEdit && isEdit);
const disabled = Boolean(field.readOnly || (field.readOnlyOnEdit && isEdit));
if (field.formRender) {
return field.formRender({ field, isEdit, disabled });
}
const common = {
key: field.name,
name: field.name,

View File

@ -0,0 +1,77 @@
import React, { useCallback, useRef, useState } from 'react';
import { Select } from 'antd';
import { pagedList } from '@/services/api';
type Option = { label: string; value: string };
type MasterDataSelectProps = Omit<React.ComponentProps<typeof Select<string>>, 'options' | 'onSearch'> & {
controller: string;
buildParams?: (keyword: string) => Record<string, any>;
optionLabel?: (row: Record<string, any>) => string;
afterChange?: () => void;
};
export default function MasterDataSelect({
controller,
buildParams,
optionLabel,
afterChange,
...selectProps
}: MasterDataSelectProps) {
const [options, setOptions] = useState<Option[]>([]);
const [loading, setLoading] = useState(false);
const timerRef = useRef<ReturnType<typeof setTimeout>>();
const fetchOptions = useCallback(
async (keyword: string) => {
setLoading(true);
try {
const res = await pagedList<Record<string, any>>(controller, {
current: 1,
pageSize: 50,
...(buildParams ? buildParams(keyword) : keyword ? { keyword } : {}),
});
setOptions(
(res.data || []).map((row) => ({
value: String(row.code),
label: optionLabel ? optionLabel(row) : `${row.code} (${row.name || '-'})`,
})),
);
} catch {
setOptions([]);
} finally {
setLoading(false);
}
},
[controller, buildParams, optionLabel],
);
React.useEffect(() => () => clearTimeout(timerRef.current), []);
return (
<Select<string>
{...selectProps}
showSearch
allowClear
loading={loading}
filterOption={false}
optionFilterProp="label"
options={options}
onSearch={(value) => {
clearTimeout(timerRef.current);
timerRef.current = setTimeout(() => void fetchOptions(value.trim()), 250);
}}
onOpenChange={(open) => {
if (open) void fetchOptions('');
}}
onChange={(value, option) => {
selectProps.onChange?.(value, option);
afterChange?.();
}}
onClear={() => {
selectProps.onClear?.();
afterChange?.();
}}
/>
);
}

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="确认入库"

View File

@ -13,6 +13,7 @@ import {
} from 'antd';
import type { ColumnsType } from 'antd/es/table';
import CrudPage from '@/components/CrudPage';
import MasterDataSelect from '@/components/MasterDataSelect';
import { useDictionary } from '@/contexts/DictionaryContext';
import { batchCreateLocations } from '@/services/api';
import {
@ -26,6 +27,74 @@ import {
const defaultCodeTemplate = '{Warehouse}-{Area}-{Zone}-{Aisle}-R{Row:D2}C{Col:D2}L{Layer:D2}';
function LocationWarehouseSelect({ disabled }: { disabled: boolean }) {
const form = Form.useFormInstance();
return (
<Form.Item
name="warehouseCode"
label="仓库编码"
rules={[{ required: true, message: '请选择仓库' }]}
>
<MasterDataSelect
controller="Warehouse"
placeholder="搜索仓库"
disabled={disabled}
afterChange={() => {
form.setFieldValue('areaCode', undefined);
form.setFieldValue('zoneCode', undefined);
}}
/>
</Form.Item>
);
}
function LocationAreaSelect({ disabled }: { disabled: boolean }) {
const form = Form.useFormInstance();
const warehouseCode = Form.useWatch('warehouseCode', form);
const wh = String(warehouseCode || '').trim();
return (
<Form.Item
name="areaCode"
label="库区编码"
rules={[{ required: true, message: '请选择库区' }]}
>
<MasterDataSelect
controller="Area"
placeholder={wh ? '搜索库区' : '先选仓库'}
disabled={disabled || !wh}
buildParams={(keyword) => ({ warehouseCode: wh, ...(keyword ? { keyword } : {}) })}
afterChange={() => form.setFieldValue('zoneCode', undefined)}
/>
</Form.Item>
);
}
function LocationZoneSelect({ disabled }: { disabled: boolean }) {
const form = Form.useFormInstance();
const warehouseCode = Form.useWatch('warehouseCode', form);
const areaCode = Form.useWatch('areaCode', form);
const wh = String(warehouseCode || '').trim();
const area = String(areaCode || '').trim();
return (
<Form.Item
name="zoneCode"
label="分区编码"
rules={[{ required: true, message: '请选择分区' }]}
>
<MasterDataSelect
controller="Zone"
placeholder={wh && area ? '搜索分区' : '先选仓库/库区'}
disabled={disabled || !wh || !area}
buildParams={(keyword) => ({
warehouseCode: wh,
areaCode: area,
...(keyword ? { keyword } : {}),
})}
/>
</Form.Item>
);
}
export default function LocationPage() {
const { buildSelectOptions } = useDictionary();
const reloadTableRef = useRef<(() => void) | null>(null);
@ -231,6 +300,7 @@ export default function LocationPage() {
required: true,
readOnlyOnEdit: true,
searchable: true,
formRender: ({ disabled }) => <LocationWarehouseSelect disabled={disabled} />,
},
{
name: 'areaCode',
@ -238,6 +308,7 @@ export default function LocationPage() {
required: true,
readOnlyOnEdit: true,
searchable: true,
formRender: ({ disabled }) => <LocationAreaSelect disabled={disabled} />,
},
{
name: 'zoneCode',
@ -245,6 +316,7 @@ export default function LocationPage() {
required: true,
readOnlyOnEdit: true,
searchable: true,
formRender: ({ disabled }) => <LocationZoneSelect disabled={disabled} />,
},
{
name: 'aisleCode',

View File

@ -1,4 +1,36 @@
import CrudPage from '@/components/CrudPage';
import MasterDataSelect from '@/components/MasterDataSelect';
import { Form } from 'antd';
function ZoneWarehouseSelect({ disabled }: { disabled: boolean }) {
const form = Form.useFormInstance();
return (
<Form.Item name="warehouseCode" label="仓库编码" rules={[{ required: true, message: '请选择仓库' }]}>
<MasterDataSelect
controller="Warehouse"
placeholder="搜索仓库"
disabled={disabled}
afterChange={() => form.setFieldValue('areaCode', undefined)}
/>
</Form.Item>
);
}
function ZoneAreaSelect({ disabled }: { disabled: boolean }) {
const form = Form.useFormInstance();
const warehouseCode = Form.useWatch('warehouseCode', form);
const wh = String(warehouseCode || '').trim();
return (
<Form.Item name="areaCode" label="库区编码" rules={[{ required: true, message: '请选择库区' }]}>
<MasterDataSelect
controller="Area"
placeholder={wh ? '搜索库区' : '先选仓库'}
disabled={disabled || !wh}
buildParams={(keyword) => ({ warehouseCode: wh, ...(keyword ? { keyword } : {}) })}
/>
</Form.Item>
);
}
export default function ZonePage() {
return (
@ -7,8 +39,20 @@ export default function ZonePage() {
controller="Zone"
defaultValues={{ attrs: '{}' }}
fields={[
{ name: 'warehouseCode', title: '仓库编码', required: true, readOnlyOnEdit: true },
{ name: 'areaCode', title: '库区编码', required: true, readOnlyOnEdit: true },
{
name: 'warehouseCode',
title: '仓库编码',
required: true,
readOnlyOnEdit: true,
formRender: ({ disabled }) => <ZoneWarehouseSelect disabled={disabled} />,
},
{
name: 'areaCode',
title: '库区编码',
required: true,
readOnlyOnEdit: true,
formRender: ({ disabled }) => <ZoneAreaSelect disabled={disabled} />,
},
{ name: 'code', title: '分区编码', required: true, readOnlyOnEdit: true },
{ name: 'name', title: '分区名称', required: true },
{ name: 'attrs', title: '扩展字段', valueType: 'json', hideInTable: true, hideInSearch: true },

View File

@ -1,9 +1,9 @@
import { ProColumns, ProTable, ActionType } from '@ant-design/pro-components';
import { Button } from 'antd';
import { ReloadOutlined } from '@ant-design/icons';
import React, { useMemo, useRef } from 'react';
import { Button, Drawer, Form, InputNumber, Space, Typography, message } from 'antd';
import { ExportOutlined, ReloadOutlined } from '@ant-design/icons';
import React, { useCallback, useMemo, useRef, useState } from 'react';
import { useDictionary } from '@/contexts/DictionaryContext';
import { pagedList } from '@/services/api';
import { actionRecord, createRecord, pagedList } from '@/services/api';
import type { InventoryBalanceRow } from '@/types/inventory';
const kindEnumFallback = {
@ -21,6 +21,22 @@ const statusEnumFallback = {
export default function InventoryBalancePage() {
const actionRef = useRef<ActionType>();
const { buildValueEnum } = useDictionary();
const [outboundOpen, setOutboundOpen] = useState(false);
const [outboundLoading, setOutboundLoading] = useState(false);
const [currentStock, setCurrentStock] = useState<InventoryBalanceRow | null>(null);
const [form] = Form.useForm();
const availableQtyOf = useCallback((row: InventoryBalanceRow) => Number(row.availableQty ?? 0), []);
const openOutbound = useCallback((row: InventoryBalanceRow) => {
setCurrentStock(row);
form.resetFields();
form.setFieldsValue({
qty: Math.max(0, availableQtyOf(row)),
unit: row.unit || 'pcs',
});
setOutboundOpen(true);
}, [availableQtyOf, form]);
const columns: ProColumns<InventoryBalanceRow>[] = useMemo(
() => [
@ -42,7 +58,8 @@ export default function InventoryBalancePage() {
{ title: '分区(编码)', dataIndex: 'zoneCode', width: 88, ellipsis: true, search: true },
{ title: '分区名称', dataIndex: 'zoneName', width: 120, ellipsis: true, search: false },
{ title: '库位', dataIndex: 'locationCode', width: 110, ellipsis: true, search: true },
{ title: '可用数量', dataIndex: 'qty', width: 100, search: false, valueType: 'digit' },
{ title: '账面数量', dataIndex: 'qty', width: 100, search: false, valueType: 'digit' },
{ title: '可分配量', dataIndex: 'availableQty', width: 100, search: false, valueType: 'digit' },
{
title: '待入数量',
dataIndex: 'pendingInboundQty',
@ -66,25 +83,111 @@ export default function InventoryBalancePage() {
search: false,
valueEnum: { ...statusEnumFallback, ...buildValueEnum('InventoryStatus') },
},
{
title: '操作',
valueType: 'option',
width: 100,
fixed: 'right',
render: (_, row) => (
<Button
type="link"
size="small"
icon={<ExportOutlined />}
disabled={availableQtyOf(row) <= 0 || Number(row.inventoryKind) !== 1}
onClick={() => openOutbound(row)}
>
出库
</Button>
),
},
],
[buildValueEnum],
[availableQtyOf, buildValueEnum, openOutbound],
);
return (
<ProTable<InventoryBalanceRow>
actionRef={actionRef}
rowKey="id"
headerTitle="库存余额"
columns={columns}
scroll={{ x: 'max-content' }}
search={{ labelWidth: 'auto' }}
options={{ density: true, reload: false, setting: true }}
request={(params) => pagedList('Inventory', params)}
toolBarRender={() => [
<Button key="reload" icon={<ReloadOutlined />} onClick={() => actionRef.current?.reload()}>
刷新
</Button>,
]}
/>
<>
<ProTable<InventoryBalanceRow>
actionRef={actionRef}
rowKey="id"
headerTitle="库存工作台"
columns={columns}
scroll={{ x: 'max-content' }}
search={{ labelWidth: 'auto' }}
options={{ density: true, reload: false, setting: true }}
request={(params) => pagedList('Inventory', params)}
toolBarRender={() => [
<Button key="reload" icon={<ReloadOutlined />} onClick={() => actionRef.current?.reload()}>
刷新
</Button>,
]}
/>
<Drawer
title="从库存发起出库"
open={outboundOpen}
width={480}
destroyOnHidden
onClose={() => setOutboundOpen(false)}
extra={
<Space>
<Button onClick={() => setOutboundOpen(false)}>取消</Button>
<Button
type="primary"
loading={outboundLoading}
onClick={async () => {
if (!currentStock) return;
const values = await form.validateFields();
setOutboundLoading(true);
try {
const order = await createRecord<{ id: string }>('OutboundOrder', {
bizType: 'outbound_default',
remark: `从库存工作台发起:${currentStock.materialCode || currentStock.containerCode}`,
lines: [
{
inventoryKind: currentStock.inventoryKind,
materialCode: currentStock.materialCode,
containerCode: currentStock.containerCode,
warehouseCode: currentStock.warehouseCode,
areaCode: currentStock.areaCode,
locationCode: currentStock.locationCode,
qty: Number(values.qty),
unit: currentStock.unit || 'pcs',
},
],
});
await actionRecord('OutboundOrder', 'pending', order.id);
message.success('已创建出库单并生成拣货任务');
setOutboundOpen(false);
actionRef.current?.reload();
} finally {
setOutboundLoading(false);
}
}}
>
创建并待拣
</Button>
</Space>
}
>
{currentStock && (
<>
<Typography.Paragraph>
{currentStock.materialCode} · {currentStock.warehouseCode}/{currentStock.areaCode}/{currentStock.locationCode}
</Typography.Paragraph>
<Typography.Paragraph type="secondary">
账面 {currentStock.qty ?? 0},待出 {currentStock.pendingOutboundQty ?? 0},冻结 {currentStock.frozenQty ?? 0},可分配 {availableQtyOf(currentStock)}
</Typography.Paragraph>
</>
)}
<Form form={form} layout="vertical">
<Form.Item
name="qty"
label="出库数量"
rules={[{ required: true, message: '请输入出库数量' }]}
>
<InputNumber min={0.000001} max={currentStock ? availableQtyOf(currentStock) : undefined} style={{ width: '100%' }} />
</Form.Item>
</Form>
</Drawer>
</>
);
}

View File

@ -8,6 +8,7 @@ export type InventoryBalanceRow = {
zoneCode: string;
locationCode: string;
qty?: number;
availableQty?: number;
pendingInboundQty?: number;
pendingOutboundQty?: number;
frozenQty?: number;