feat(商品管理): 增加商品库存配置和下架功能

在商品管理模块中,新增了库存配置和下架商品的功能。具体修改包括:
1. 在GoodsDTO和CabinetCellDTO中新增了相关字段。
2. 增加了changeGoodsCellsStock和clearGoodsCells接口用于库存配置和下架商品。
3. 在商品配置模态框中增加了库存校验逻辑。
4. 移除了部分冗余代码,优化了界面显示。
This commit is contained in:
dzq 2025-04-19 09:27:58 +08:00
parent d70ee43c29
commit 0b3138e5f0
5 changed files with 65 additions and 18 deletions

View File

@ -19,6 +19,7 @@ export interface CabinetCellDTO {
goodsName?: string;
price?: number;
coverImg?: string;
stock?: number;
}
export interface AddCabinetCellCommand {
@ -67,4 +68,10 @@ export const configureGoodsCells = (cellId: number, goodsId: number) => {
};
export const configureGoodsCellsStock = (cellId: number, goodsId: number, stock: number) => {
return http.request<ResponseData<void>>('put', `/cabinet/cell/configureGoodsCellsStock/${cellId}/${goodsId}/${stock}`);
};
export const changeGoodsCellsStock = (cellId: number, stock: number) => {
return http.request<ResponseData<void>>('put', `/cabinet/cell/changeGoodsCellsStock/${cellId}/${stock}`);
};
export const clearGoodsCells = (cellId: number) => {
return http.request<ResponseData<void>>('put', `/cabinet/cell/clearGoodsCells/${cellId}`);
};

View File

@ -25,6 +25,7 @@ export interface GoodsDTO {
deleted?: number;
cabinetName?: string;
cellNo?: number;
cellNoStr?: string;
totalStock?: number;
}

View File

@ -59,6 +59,14 @@ const handleConfigure = async (row: GoodsDTO) => {
}
);
if (!value) {
ElMessage.warning('请输入库存数量');
return;
}
if (Number(value) > row.stock - row.totalStock) {
ElMessage.warning('分配数量不能超过剩余库存');
return;
}
await configureGoodsCellsStock(props.cellId, row.goodsId!, Number(value));
ElMessage.success('配置成功');
emit('refresh');
@ -118,9 +126,6 @@ defineExpose({ getList });
</el-button>
</template>
</el-table-column>
<div class="dialog-footer" style="margin-top: 20px; text-align: right">
<el-button @click="closeModal">取消</el-button>
</div>
</el-table>
<el-pagination v-model:current-page="pagination.currentPage" v-model:page-size="pagination.pageSize"

View File

@ -3,7 +3,7 @@ import { ref, onMounted } from "vue";
import { PureTableBar } from "@/components/RePureTableBar";
import { onBeforeRouteUpdate, useRoute } from "vue-router";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import { getCabinetCellList, deleteCabinetCell, CabinetCellDTO } from "@/api/cabinet/cabinet-cell";
import { getCabinetCellList, deleteCabinetCell, CabinetCellDTO, changeGoodsCellsStock, clearGoodsCells } from "@/api/cabinet/cabinet-cell";
import { allCabinets, SmartCabinetDTO } from "@/api/cabinet/smart-cabinet";
import EditPen from "@iconify-icons/ep/edit-pen";
import Delete from "@iconify-icons/ep/delete";
@ -154,6 +154,40 @@ const switchCellType = (cellType: number) => {
}
};
const handleStockConfig = async (row: CabinetCellDTO) => {
try {
const { value } = await ElMessageBox.prompt(
`请输入${row.goodsName || '未配置商品'}的库存数量`,
'配置库存',
{
inputPattern: /^0$|^[1-9]\d*/,
inputValue: row.stock?.toString(),
inputErrorMessage: '库存必须大于等于0'
}
);
await changeGoodsCellsStock(row.cellId!, Number(value));
ElMessage.success('库存更新成功');
getList();
} catch (error) {
console.error('库存配置取消或失败', error);
}
};
const handleClearGoods = async (row: CabinetCellDTO) => {
try {
await ElMessageBox.confirm(
`确认要下架${row.goodsName || '未配置商品'}吗?`,
'警告',
{ confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }
);
await clearGoodsCells(row.cellId!);
ElMessage.success('商品下架成功');
getList();
} catch (error) {
console.error('操作取消或失败', error);
}
};
</script>
<template>
@ -218,19 +252,17 @@ const switchCellType = (cellType: number) => {
</el-table-column>
<el-table-column label="操作" width="150" fixed="right">
<template #default="{ row }">
<el-button type="primary" link :icon="useRenderIcon(EditPen)" @click="handleEdit(row)">
编辑
</el-button>
<el-button type="success" link :icon="useRenderIcon(AddFill)" @click="handleConfigure(row)">
配置商品
</el-button>
<el-popconfirm :title="`确认删除【${row.cellNo}】号单元格?`" @confirm="handleDelete(row)">
<template #reference>
<el-button type="danger" link :icon="useRenderIcon(Delete)">
删除
</el-button>
</template>
</el-popconfirm>
<el-button v-if="row.goodsId" type="warning" link :icon="useRenderIcon(EditPen)"
@click="handleStockConfig(row)">
配置库存
</el-button>
<el-button v-if="row.goodsId" type="danger" link :icon="useRenderIcon(Delete)"
@click="handleClearGoods(row)">
下架商品
</el-button>
</template>
</el-table-column>
</el-table>
@ -238,7 +270,9 @@ const switchCellType = (cellType: number) => {
:page-sizes="[10, 20, 50]" layout="total, sizes, prev, pager, next, jumper" :total="pagination.total"
@size-change="onSizeChange" @current-change="onCurrentChange" />
</PureTableBar>
<CabinetGoodsConfigModal v-model="configVisible" :cell-id="currentCellId" @refresh="getList" />
<el-dialog v-model="configVisible" title="配置商品" width="80%">
<CabinetGoodsConfigModal v-model="configVisible" :cell-id="currentCellId" @refresh="getList" />
</el-dialog>
</div>
</template>

View File

@ -183,7 +183,7 @@ const handleEdit = (row: GoodsDTO) => {
</el-table-column>
<el-table-column label="柜口" prop="cellNo" width="120">
<template #default="{ row }">
{{ !row.cellNo ? '未配置' : row.cabinetName + ' 格口' + row.cellNo }}
{{ !row.cellNoStr ? '未配置' : row.cabinetName + ' 格口' + row.cellNoStr }}
</template>
</el-table-column>
<el-table-column label="操作" width="150" fixed="right">
@ -191,10 +191,10 @@ const handleEdit = (row: GoodsDTO) => {
<el-button type="primary" link :icon="useRenderIcon(EditPen)" @click="handleEdit(row)" class="right-btn">
编辑
</el-button>
<el-button type="warning" link :icon="useRenderIcon(Setting)" class="right-btn"
<!-- <el-button type="warning" link :icon="useRenderIcon(Setting)" class="right-btn"
@click="currentRow = row; configVisible = true">
配置格口
</el-button>
</el-button> -->
<el-popconfirm :title="`确认删除【${row.goodsName}】?`" @confirm="handleDelete(row)">
<template #reference>
<el-button type="danger" link :icon="useRenderIcon(Delete)" class="right-btn">