fix(consumable): 修复最大库存字段逻辑并改进耗材管理
将 maxStock 字段从允许 null 改为默认 0 表示无限制 添加耗材创建时的数据验证和错误处理 优化前端耗材管理页面的表单初始化和显示逻辑 添加数据库迁移脚本处理现有数据
This commit is contained in:
@@ -67,7 +67,7 @@ function ConsumableManagement() {
|
||||
const showModal = useCallback((consumable = null) => {
|
||||
setEditingConsumable(consumable);
|
||||
if (consumable) {
|
||||
const isUnlimited = consumable.maxStock === null || consumable.maxStock === undefined;
|
||||
const isUnlimited = consumable.maxStock === 0 || consumable.maxStock === null || consumable.maxStock === undefined;
|
||||
setMaxStockUnlimited(isUnlimited);
|
||||
form.setFieldsValue({
|
||||
...consumable,
|
||||
@@ -76,6 +76,13 @@ function ConsumableManagement() {
|
||||
} else {
|
||||
setMaxStockUnlimited(true);
|
||||
form.resetFields();
|
||||
form.setFieldsValue({
|
||||
unit: '个',
|
||||
currentStock: 0,
|
||||
minStock: 0,
|
||||
status: 'active',
|
||||
unitPrice: 0
|
||||
});
|
||||
}
|
||||
setModalVisible(true);
|
||||
}, [form]);
|
||||
@@ -89,7 +96,8 @@ function ConsumableManagement() {
|
||||
try {
|
||||
const submitData = {
|
||||
...values,
|
||||
maxStock: maxStockUnlimited ? null : values.maxStock
|
||||
maxStock: maxStockUnlimited ? 0 : values.maxStock,
|
||||
unitPrice: values.unitPrice || 0
|
||||
};
|
||||
if (editingConsumable) {
|
||||
await axios.put(`/api/consumables/${editingConsumable.consumableId}`, submitData);
|
||||
@@ -410,12 +418,6 @@ function ConsumableManagement() {
|
||||
}, [stockRecord, stockType, fetchConsumables]);
|
||||
|
||||
const columns = useMemo(() => [
|
||||
{
|
||||
title: '耗材ID',
|
||||
dataIndex: 'consumableId',
|
||||
key: 'consumableId',
|
||||
width: 150
|
||||
},
|
||||
{
|
||||
title: '名称',
|
||||
dataIndex: 'name',
|
||||
@@ -459,7 +461,7 @@ function ConsumableManagement() {
|
||||
dataIndex: 'maxStock',
|
||||
key: 'maxStock',
|
||||
width: 100,
|
||||
render: (value) => value === null || value === undefined ? '无限制' : value
|
||||
render: (value) => value === 0 || value === null || value === undefined ? '无限制' : value
|
||||
},
|
||||
{
|
||||
title: '单价(元)',
|
||||
@@ -482,6 +484,14 @@ function ConsumableManagement() {
|
||||
width: 120,
|
||||
render: (value) => value || '-'
|
||||
},
|
||||
{
|
||||
title: '描述',
|
||||
dataIndex: 'description',
|
||||
key: 'description',
|
||||
width: 200,
|
||||
render: (value) => value || '-',
|
||||
ellipsis: true
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
|
||||
Reference in New Issue
Block a user