feat(商品管理): 添加获取单个商品信息的API并优化库存配置逻辑
新增`getGoodsInfo` API用于获取单个商品的详细信息,并在库存配置时增加剩余库存的校验和提示,确保分配的库存不超过剩余库存。
This commit is contained in:
parent
463793f3d5
commit
280cbb82b3
|
@ -70,6 +70,15 @@ export const getGoodsListApi = (params?: GoodsQuery) => {
|
|||
});
|
||||
};
|
||||
|
||||
/** 获取单个商品信息 */
|
||||
export const getGoodsInfo = (goodsId: number) => {
|
||||
return http.request<ResponseData<GoodsDTO>>("get", "/shop/goods/getGoodsInfo", {
|
||||
params: {
|
||||
goodsId
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/** 新增商品 */
|
||||
export const addGoodsApi = (data: GoodsRequest) => {
|
||||
return http.request<ResponseData<void>>("post", "/shop/goods", {
|
||||
|
|
|
@ -13,6 +13,7 @@ import Refresh from "@iconify-icons/ep/refresh";
|
|||
import { ElMessage, ElMessageBox } from "element-plus";
|
||||
import { on } from "events";
|
||||
import CabinetGoodsConfigModal from "./cabinet-goods-config-modal.vue";
|
||||
import { getGoodsInfo } from "@/api/shop/goods";
|
||||
|
||||
defineOptions({
|
||||
name: "CabinetGoods"
|
||||
|
@ -156,16 +157,33 @@ const switchCellType = (cellType: number) => {
|
|||
|
||||
const handleStockConfig = async (row: CabinetCellDTO) => {
|
||||
try {
|
||||
// 获取商品详细信息
|
||||
const { data } = await getGoodsInfo(row.goodsId!);
|
||||
const remainingStock = data.stock - data.totalStock + row.stock;
|
||||
|
||||
const { value } = await ElMessageBox.prompt(
|
||||
`请输入${row.goodsName || '未配置商品'}的库存数量`,
|
||||
`请输入${row.goodsName || '未配置商品'}的库存数量(本次最多可分配:${remainingStock})。
|
||||
若可分配数量不足,请先调整商品列表中的库存。`,
|
||||
'配置库存',
|
||||
{
|
||||
inputPattern: /^0$|^[1-9]\d*/,
|
||||
inputPattern: /^0$|^[1-9]\d*$/,
|
||||
inputValue: row.stock?.toString(),
|
||||
inputErrorMessage: '库存必须大于等于0'
|
||||
inputErrorMessage: '请输入有效的非负整数',
|
||||
inputValidator: (inputValue: string) => {
|
||||
const num = Number(inputValue);
|
||||
if (num > remainingStock) {
|
||||
return '分配数量不能超过剩余库存';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (Number(value) > remainingStock) {
|
||||
ElMessage.warning('分配数量不能超过剩余库存');
|
||||
return;
|
||||
}
|
||||
|
||||
await changeGoodsCellsStock(row.cellId!, Number(value));
|
||||
ElMessage.success('库存更新成功');
|
||||
getList();
|
||||
|
|
Loading…
Reference in New Issue