feat: 添加柜体商品配置功能
新增柜体商品配置功能,包括商品库存配置、单元格商品信息展示等。新增接口和页面组件,支持商品与单元格的关联配置,并优化了相关数据展示和操作流程。
This commit is contained in:
parent
550df0a15b
commit
d70ee43c29
|
@ -15,6 +15,10 @@ export interface CabinetCellDTO {
|
|||
usageStatus: number;
|
||||
availableStatus: number;
|
||||
operator?: string;
|
||||
goodsId?: number;
|
||||
goodsName?: string;
|
||||
price?: number;
|
||||
coverImg?: string;
|
||||
}
|
||||
|
||||
export interface AddCabinetCellCommand {
|
||||
|
@ -60,4 +64,7 @@ export interface ConfigureGoodsCellsCommand {
|
|||
|
||||
export const configureGoodsCells = (cellId: number, goodsId: number) => {
|
||||
return http.request<ResponseData<void>>('put', `/cabinet/cell/configureGoodsCells/${cellId}/${goodsId}`);
|
||||
};
|
||||
export const configureGoodsCellsStock = (cellId: number, goodsId: number, stock: number) => {
|
||||
return http.request<ResponseData<void>>('put', `/cabinet/cell/configureGoodsCellsStock/${cellId}/${goodsId}/${stock}`);
|
||||
};
|
|
@ -58,3 +58,7 @@ export const deleteSmartCabinet = (ids: string) => {
|
|||
export const getAllCabinetsWithCells = () => {
|
||||
return http.request<ResponseData<AllCabinetDataDTO>>('get', '/cabinet/smartCabinet/all');
|
||||
};
|
||||
|
||||
export const allCabinets = () => {
|
||||
return http.request<ResponseData<Array<SmartCabinetDTO>>>('get', '/cabinet/smartCabinet/allCabinets');
|
||||
};
|
|
@ -25,6 +25,7 @@ export interface GoodsDTO {
|
|||
deleted?: number;
|
||||
cabinetName?: string;
|
||||
cellNo?: number;
|
||||
totalStock?: number;
|
||||
}
|
||||
|
||||
/** 商品请求参数 */
|
||||
|
|
|
@ -0,0 +1,140 @@
|
|||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
|
||||
import { getGoodsListApi, type GoodsDTO } from "@/api/shop/goods";
|
||||
import { configureGoodsCellsStock } from "@/api/cabinet/cabinet-cell";
|
||||
import Search from "@iconify-icons/ep/search";
|
||||
import Refresh from "@iconify-icons/ep/refresh";
|
||||
import { ElMessage, ElMessageBox } from "element-plus";
|
||||
|
||||
const props = defineProps({
|
||||
cellId: {
|
||||
type: Number,
|
||||
required: true
|
||||
}
|
||||
});
|
||||
|
||||
const emit = defineEmits(['refresh', 'update:modelValue']);
|
||||
const closeModal = () => {
|
||||
emit('update:modelValue', false);
|
||||
};
|
||||
|
||||
const searchFormParams = ref({
|
||||
goodsName: "",
|
||||
status: null
|
||||
});
|
||||
|
||||
const pagination = ref({
|
||||
pageSize: 10,
|
||||
currentPage: 1,
|
||||
total: 0
|
||||
});
|
||||
|
||||
const loading = ref(false);
|
||||
const dataList = ref<GoodsDTO[]>([]);
|
||||
|
||||
const getList = async () => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const { data } = await getGoodsListApi({
|
||||
...searchFormParams.value,
|
||||
pageSize: pagination.value.pageSize,
|
||||
pageNum: pagination.value.currentPage
|
||||
});
|
||||
dataList.value = data.rows;
|
||||
pagination.value.total = data.total;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleConfigure = async (row: GoodsDTO) => {
|
||||
try {
|
||||
const { value } = await ElMessageBox.prompt(
|
||||
'请输入商品库存数量',
|
||||
'配置库存',
|
||||
{
|
||||
inputPattern: /^[1-9]\d*$/,
|
||||
inputErrorMessage: '请输入有效的正整数库存'
|
||||
}
|
||||
);
|
||||
|
||||
await configureGoodsCellsStock(props.cellId, row.goodsId!, Number(value));
|
||||
ElMessage.success('配置成功');
|
||||
emit('refresh');
|
||||
closeModal();
|
||||
} catch (error) {
|
||||
console.error('配置取消或失败', error);
|
||||
}
|
||||
};
|
||||
|
||||
defineExpose({ getList });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="config-modal">
|
||||
<el-form :inline="true" :model="searchFormParams" class="search-form">
|
||||
<el-form-item label="商品名称:">
|
||||
<el-input v-model="searchFormParams.goodsName" placeholder="请输入商品名称" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态:">
|
||||
<el-select v-model="searchFormParams.status" placeholder="请选择状态" clearable>
|
||||
<el-option label="已上架" :value="1" />
|
||||
<el-option label="已下架" :value="2" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" :icon="useRenderIcon(Search)" @click="getList">
|
||||
搜索
|
||||
</el-button>
|
||||
<el-button :icon="useRenderIcon(Refresh)"
|
||||
@click="searchFormParams = { goodsName: '', status: null }; getList()">
|
||||
重置
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-table v-loading="loading" :data="dataList" border>
|
||||
<el-table-column label="商品图片" width="120">
|
||||
<template #default="{ row }">
|
||||
<el-image :src="row.coverImg" fit="cover" class="rounded" width="60" height="60" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="商品名称" prop="goodsName" />
|
||||
<el-table-column label="价格" prop="price" width="120" />
|
||||
<el-table-column label="库存" prop="stock" width="120" />
|
||||
<el-table-column label="已分配库存" prop="totalStock" width="120" />
|
||||
<el-table-column label="状态" width="120">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.status === 1 ? 'success' : 'danger'">
|
||||
{{ row.status === 1 ? '已上架' : '已下架' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="120" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button type="primary" link @click="handleConfigure(row)">
|
||||
配置
|
||||
</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"
|
||||
:page-sizes="[10, 20, 50]" layout="total, sizes, prev, pager, next" :total="pagination.total"
|
||||
@size-change="getList" @current-change="getList" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.config-modal {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.search-form {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
</style>
|
|
@ -0,0 +1,245 @@
|
|||
<script setup lang="ts">
|
||||
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 { allCabinets, SmartCabinetDTO } from "@/api/cabinet/smart-cabinet";
|
||||
import EditPen from "@iconify-icons/ep/edit-pen";
|
||||
import Delete from "@iconify-icons/ep/delete";
|
||||
import AddFill from "@iconify-icons/ri/add-circle-line";
|
||||
import Search from "@iconify-icons/ep/search";
|
||||
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";
|
||||
|
||||
defineOptions({
|
||||
name: "CabinetGoods"
|
||||
});
|
||||
|
||||
const formRef = ref();
|
||||
const tableRef = ref();
|
||||
|
||||
const searchFormParams = ref({
|
||||
cabinetId: null,
|
||||
cellNo: null,
|
||||
cellType: null
|
||||
});
|
||||
|
||||
const pagination = ref({
|
||||
pageSize: 10,
|
||||
currentPage: 1,
|
||||
total: 0
|
||||
});
|
||||
|
||||
const loading = ref(false);
|
||||
const dataList = ref([]);
|
||||
const multipleSelection = ref<number[]>([]);
|
||||
const currentRow = ref<CabinetCellDTO>();
|
||||
const configVisible = ref(false);
|
||||
const currentCellId = ref<number>();
|
||||
|
||||
const route = useRoute();
|
||||
|
||||
const cabinets = ref<SmartCabinetDTO[]>([]);
|
||||
|
||||
onMounted(async () => {
|
||||
const { data } = await allCabinets();
|
||||
cabinets.value = data;
|
||||
if (data.length > 0) {
|
||||
searchFormParams.value.cabinetId = data[0].cabinetId;
|
||||
getList();
|
||||
}
|
||||
});
|
||||
|
||||
onBeforeRouteUpdate(async () => {
|
||||
const { data } = await allCabinets();
|
||||
cabinets.value = data;
|
||||
if (data.length > 0) {
|
||||
searchFormParams.value.cabinetId = data[0].cabinetId;
|
||||
getList();
|
||||
}
|
||||
});
|
||||
|
||||
const getList = async () => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const { data } = await getCabinetCellList({
|
||||
...searchFormParams.value,
|
||||
pageSize: pagination.value.pageSize,
|
||||
pageNum: pagination.value.currentPage
|
||||
});
|
||||
dataList.value = data.rows;
|
||||
pagination.value.total = data.total;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const onSearch = () => {
|
||||
pagination.value.currentPage = 1;
|
||||
getList();
|
||||
};
|
||||
|
||||
const resetForm = () => {
|
||||
formRef.value.resetFields();
|
||||
onSearch();
|
||||
};
|
||||
|
||||
const onSizeChange = (val: number) => {
|
||||
pagination.value.pageSize = val;
|
||||
getList();
|
||||
};
|
||||
|
||||
const onCurrentChange = (val: number) => {
|
||||
pagination.value.currentPage = val;
|
||||
getList();
|
||||
};
|
||||
|
||||
const handleDelete = async (row: CabinetCellDTO) => {
|
||||
try {
|
||||
await deleteCabinetCell(row.cellId!.toString());
|
||||
ElMessage.success("删除成功");
|
||||
getList();
|
||||
} catch (error) {
|
||||
console.error("删除失败", error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleBulkDelete = async () => {
|
||||
if (multipleSelection.value.length === 0) return;
|
||||
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`确认删除选中的${multipleSelection.value.length}项单元格吗?`,
|
||||
"警告",
|
||||
{ confirmButtonText: "确定", cancelButtonText: "取消", type: "warning" }
|
||||
);
|
||||
|
||||
await deleteCabinetCell(multipleSelection.value.join(","));
|
||||
ElMessage.success("批量删除成功");
|
||||
multipleSelection.value = [];
|
||||
getList();
|
||||
} catch (error) {
|
||||
console.error("删除取消或失败", error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSelectionChange = (rows: CabinetCellDTO[]) => {
|
||||
multipleSelection.value = rows.map(row => row.cellId!);
|
||||
};
|
||||
|
||||
const handleEdit = (row: CabinetCellDTO) => {
|
||||
currentRow.value = row;
|
||||
};
|
||||
|
||||
const handleConfigure = (row: CabinetCellDTO) => {
|
||||
currentCellId.value = row.cellId;
|
||||
configVisible.value = true;
|
||||
};
|
||||
|
||||
const switchCellType = (cellType: number) => {
|
||||
switch (cellType) {
|
||||
case 1:
|
||||
return "小格";
|
||||
case 2:
|
||||
return "中格";
|
||||
case 3:
|
||||
return "大格";
|
||||
case 4:
|
||||
return "超大格";
|
||||
default:
|
||||
return "未知";
|
||||
}
|
||||
};
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="main">
|
||||
<el-form ref="formRef" :inline="true" :model="searchFormParams"
|
||||
class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px]">
|
||||
<el-form-item label="柜机:" prop="cabinetId">
|
||||
<el-select v-model.number="searchFormParams.cabinetId" placeholder="请选择柜机" clearable class="!w-[200px]">
|
||||
<el-option v-for="cabinet in cabinets" :key="cabinet.cabinetId" :label="cabinet.cabinetName"
|
||||
:value="cabinet.cabinetId" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="单元格号:" prop="cellNo">
|
||||
<el-input v-model.number="searchFormParams.cellNo" placeholder="请输入单元格号" clearable class="!w-[180px]" />
|
||||
</el-form-item>
|
||||
<el-form-item label="单元格类型:" prop="cellType">
|
||||
<el-select v-model="searchFormParams.cellType" placeholder="请选择类型" clearable class="!w-[180px]">
|
||||
<el-option label="小格" :value="1" />
|
||||
<el-option label="中格" :value="2" />
|
||||
<el-option label="大格" :value="3" />
|
||||
<el-option label="超大格" :value="4" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" :icon="useRenderIcon(Search)" @click="onSearch">
|
||||
搜索
|
||||
</el-button>
|
||||
<el-button :icon="useRenderIcon(Refresh)" @click="resetForm">
|
||||
重置
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<PureTableBar title="柜体单元格管理" @refresh="getList">
|
||||
<template #buttons>
|
||||
<el-button type="danger" :icon="useRenderIcon(Delete)" :disabled="multipleSelection.length === 0"
|
||||
@click="handleBulkDelete">
|
||||
批量删除
|
||||
</el-button>
|
||||
</template>
|
||||
<el-table ref="tableRef" v-loading="loading" :data="dataList" row-key="cellId"
|
||||
@selection-change="handleSelectionChange" border>
|
||||
<el-table-column type="selection" width="55" />
|
||||
<el-table-column label="商品图片" width="120">
|
||||
<template #default="{ row }">
|
||||
<el-image :src="row.coverImg" :preview-src-list="[row.coverImg]" :z-index="9999" :preview-teleported="true"
|
||||
:hide-on-click-modal="true" fit="cover" class="rounded" width="60" height="60" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="商品名称">
|
||||
<template #default="{ row }">
|
||||
{{ row.goodsId ? row.goodsName : '未配置商品' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="价格" prop="price" width="120" />
|
||||
<el-table-column label="库存" prop="stock" width="120" />
|
||||
<el-table-column label="单元格号" prop="cellNo" width="120" />
|
||||
<el-table-column label="单元格类型" prop="cellType">
|
||||
<template #default="{ row }">
|
||||
{{ switchCellType(row.cellType) }}
|
||||
</template>
|
||||
</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>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-pagination v-model:current-page="pagination.currentPage" v-model:page-size="pagination.pageSize"
|
||||
: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" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
Loading…
Reference in New Issue