From 0b3138e5f065bd4052118119e1f835024d172fab Mon Sep 17 00:00:00 2001 From: dzq Date: Sat, 19 Apr 2025 09:27:58 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=95=86=E5=93=81=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=95=86=E5=93=81=E5=BA=93=E5=AD=98=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=92=8C=E4=B8=8B=E6=9E=B6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在商品管理模块中,新增了库存配置和下架商品的功能。具体修改包括: 1. 在GoodsDTO和CabinetCellDTO中新增了相关字段。 2. 增加了changeGoodsCellsStock和clearGoodsCells接口用于库存配置和下架商品。 3. 在商品配置模态框中增加了库存校验逻辑。 4. 移除了部分冗余代码,优化了界面显示。 --- src/api/cabinet/cabinet-cell.ts | 7 +++ src/api/shop/goods.ts | 1 + .../cabinet-goods-config-modal.vue | 11 +++- src/views/shop/cabinet-goods/index.vue | 58 +++++++++++++++---- src/views/shop/goods/index.vue | 6 +- 5 files changed, 65 insertions(+), 18 deletions(-) diff --git a/src/api/cabinet/cabinet-cell.ts b/src/api/cabinet/cabinet-cell.ts index e7c6253..b0a3f74 100644 --- a/src/api/cabinet/cabinet-cell.ts +++ b/src/api/cabinet/cabinet-cell.ts @@ -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>('put', `/cabinet/cell/configureGoodsCellsStock/${cellId}/${goodsId}/${stock}`); +}; +export const changeGoodsCellsStock = (cellId: number, stock: number) => { + return http.request>('put', `/cabinet/cell/changeGoodsCellsStock/${cellId}/${stock}`); +}; +export const clearGoodsCells = (cellId: number) => { + return http.request>('put', `/cabinet/cell/clearGoodsCells/${cellId}`); }; \ No newline at end of file diff --git a/src/api/shop/goods.ts b/src/api/shop/goods.ts index 6054c0a..6a82c9e 100644 --- a/src/api/shop/goods.ts +++ b/src/api/shop/goods.ts @@ -25,6 +25,7 @@ export interface GoodsDTO { deleted?: number; cabinetName?: string; cellNo?: number; + cellNoStr?: string; totalStock?: number; } diff --git a/src/views/shop/cabinet-goods/cabinet-goods-config-modal.vue b/src/views/shop/cabinet-goods/cabinet-goods-config-modal.vue index 7a3b21d..6515aea 100644 --- a/src/views/shop/cabinet-goods/cabinet-goods-config-modal.vue +++ b/src/views/shop/cabinet-goods/cabinet-goods-config-modal.vue @@ -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 }); - { } }; +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); + } +}; diff --git a/src/views/shop/goods/index.vue b/src/views/shop/goods/index.vue index 7251429..dd019e4 100644 --- a/src/views/shop/goods/index.vue +++ b/src/views/shop/goods/index.vue @@ -183,7 +183,7 @@ const handleEdit = (row: GoodsDTO) => { @@ -191,10 +191,10 @@ const handleEdit = (row: GoodsDTO) => { 编辑 - 配置格口 - + -->