2025-04-18 17:13:38 +08:00
|
|
|
|
<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";
|
2025-04-27 10:49:15 +08:00
|
|
|
|
import { getCabinetCellList, deleteCabinetCell, CabinetCellDTO, changeGoodsCellsStock, clearGoodsCells, CabinetCellQuery } from "@/api/cabinet/cabinet-cell";
|
2025-04-18 17:13:38 +08:00
|
|
|
|
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";
|
2025-04-25 11:42:50 +08:00
|
|
|
|
import { getGoodsInfo } from "@/api/shop/goods";
|
2025-04-26 07:59:01 +08:00
|
|
|
|
import { useRouter } from "vue-router";
|
2025-04-18 17:13:38 +08:00
|
|
|
|
|
|
|
|
|
defineOptions({
|
|
|
|
|
name: "CabinetGoods"
|
|
|
|
|
});
|
|
|
|
|
|
2025-04-26 07:59:01 +08:00
|
|
|
|
const router = useRouter();
|
2025-04-18 17:13:38 +08:00
|
|
|
|
const formRef = ref();
|
|
|
|
|
const tableRef = ref();
|
|
|
|
|
|
2025-04-27 10:49:15 +08:00
|
|
|
|
const searchFormParams = ref<CabinetCellQuery>({
|
2025-04-18 17:13:38 +08:00
|
|
|
|
cabinetId: null,
|
|
|
|
|
cellNo: null,
|
|
|
|
|
cellType: null
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const pagination = ref({
|
2025-04-25 09:57:54 +08:00
|
|
|
|
pageSize: 5,
|
2025-04-18 17:13:38 +08:00
|
|
|
|
currentPage: 1,
|
|
|
|
|
total: 0
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const loading = ref(false);
|
2025-04-26 16:09:58 +08:00
|
|
|
|
const dataList = ref<CabinetCellDTO[]>([]);
|
2025-04-18 17:13:38 +08:00
|
|
|
|
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 "未知";
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-19 09:27:58 +08:00
|
|
|
|
const handleStockConfig = async (row: CabinetCellDTO) => {
|
|
|
|
|
try {
|
2025-04-25 11:42:50 +08:00
|
|
|
|
// 获取商品详细信息
|
|
|
|
|
const { data } = await getGoodsInfo(row.goodsId!);
|
|
|
|
|
const remainingStock = data.stock - data.totalStock + row.stock;
|
|
|
|
|
|
2025-04-19 09:27:58 +08:00
|
|
|
|
const { value } = await ElMessageBox.prompt(
|
2025-04-25 11:42:50 +08:00
|
|
|
|
`请输入${row.goodsName || '未配置商品'}的库存数量(本次最多可分配:${remainingStock})。
|
|
|
|
|
若可分配数量不足,请先调整商品列表中的库存。`,
|
2025-04-19 09:27:58 +08:00
|
|
|
|
'配置库存',
|
|
|
|
|
{
|
2025-04-25 11:42:50 +08:00
|
|
|
|
inputPattern: /^0$|^[1-9]\d*$/,
|
2025-04-19 09:27:58 +08:00
|
|
|
|
inputValue: row.stock?.toString(),
|
2025-04-25 11:42:50 +08:00
|
|
|
|
inputErrorMessage: '请输入有效的非负整数',
|
|
|
|
|
inputValidator: (inputValue: string) => {
|
|
|
|
|
const num = Number(inputValue);
|
|
|
|
|
if (num > remainingStock) {
|
|
|
|
|
return '分配数量不能超过剩余库存';
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2025-04-19 09:27:58 +08:00
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2025-04-25 11:42:50 +08:00
|
|
|
|
if (Number(value) > remainingStock) {
|
|
|
|
|
ElMessage.warning('分配数量不能超过剩余库存');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-19 09:27:58 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
};
|
2025-04-18 17:13:38 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
2025-04-22 15:39:45 +08:00
|
|
|
|
<div class="main flex">
|
|
|
|
|
<!-- 左侧柜机列表 -->
|
|
|
|
|
<div class="w-[200px] pr-4 border-r h-full left-list">
|
|
|
|
|
<div class="text-lg font-bold mb-4 px-2">柜机列表</div>
|
|
|
|
|
<div class="h-[calc(100vh-180px)] overflow-y-auto">
|
|
|
|
|
<div class="cabinet-list">
|
|
|
|
|
<div v-for="cabinet in cabinets" :key="cabinet.cabinetId"
|
|
|
|
|
class="cabinet-item p-3 mb-2 cursor-pointer rounded hover:bg-gray-100 transition-colors"
|
|
|
|
|
:class="{ 'bg-blue-50': searchFormParams.cabinetId === cabinet.cabinetId }"
|
|
|
|
|
@click="searchFormParams.cabinetId = cabinet.cabinetId; onSearch()">
|
|
|
|
|
{{ cabinet.cabinetName }}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- 右侧内容 -->
|
|
|
|
|
<div class="flex-1 pl-4">
|
|
|
|
|
<el-form ref="formRef" :inline="true" :model="searchFormParams" class="search-form bg-bg_color w-full pt-[12px]">
|
|
|
|
|
<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>
|
|
|
|
|
|
2025-04-25 09:57:54 +08:00
|
|
|
|
<div title="柜体单元格管理" @refresh="getList" class="cell-list">
|
|
|
|
|
<!-- <template #buttons>
|
2025-04-22 15:39:45 +08:00
|
|
|
|
<el-button type="danger" :icon="useRenderIcon(Delete)" :disabled="multipleSelection.length === 0"
|
|
|
|
|
@click="handleBulkDelete">
|
|
|
|
|
批量删除
|
|
|
|
|
</el-button>
|
2025-04-25 09:57:54 +08:00
|
|
|
|
</template> -->
|
2025-04-22 15:39:45 +08:00
|
|
|
|
<el-table ref="tableRef" v-loading="loading" :data="dataList" row-key="cellId"
|
|
|
|
|
@selection-change="handleSelectionChange" border>
|
2025-04-26 07:59:01 +08:00
|
|
|
|
<el-table-column label="格口ID" prop="cellId" width="80" />
|
2025-05-13 10:42:57 +08:00
|
|
|
|
<el-table-column label="格口号" prop="cellNo" width="80" />
|
2025-04-22 15:39:45 +08:00
|
|
|
|
<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>
|
2025-04-26 07:59:01 +08:00
|
|
|
|
<el-table-column label="价格" prop="price" width="80" />
|
|
|
|
|
<el-table-column label="库存" prop="stock" width="80" />
|
2025-04-26 16:09:58 +08:00
|
|
|
|
<el-table-column label="单元格类型" prop="cellType" width="120">
|
2025-04-22 15:39:45 +08:00
|
|
|
|
<template #default="{ row }">
|
|
|
|
|
{{ switchCellType(row.cellType) }}
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
2025-04-26 16:09:58 +08:00
|
|
|
|
<el-table-column label="购买次数" prop="orderCount" width="100" />
|
2025-04-26 07:59:01 +08:00
|
|
|
|
<el-table-column label="相关信息" width="150" fixed="right">
|
|
|
|
|
<template #default="{ row }">
|
2025-04-26 16:09:58 +08:00
|
|
|
|
<el-button type="success" link :icon="useRenderIcon('document')"
|
2025-04-26 07:59:01 +08:00
|
|
|
|
@click="router.push({ path: '/shop/order/index', query: { cellId: row.cellId } })">
|
|
|
|
|
购买记录
|
|
|
|
|
</el-button>
|
2025-04-26 16:09:58 +08:00
|
|
|
|
<el-button type="warning" link :icon="useRenderIcon('document')"
|
|
|
|
|
@click="router.push({ path: '/cabinet/operation/index', query: { cellId: row.cellId } })">
|
|
|
|
|
开启记录
|
|
|
|
|
</el-button>
|
2025-04-26 07:59:01 +08:00
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
2025-04-22 15:39:45 +08:00
|
|
|
|
<el-table-column label="操作" width="150" fixed="right">
|
|
|
|
|
<template #default="{ row }">
|
|
|
|
|
<el-button type="success" link :icon="useRenderIcon(AddFill)" @click="handleConfigure(row)">
|
|
|
|
|
配置商品
|
|
|
|
|
</el-button>
|
|
|
|
|
<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>
|
|
|
|
|
<el-pagination v-model:current-page="pagination.currentPage" v-model:page-size="pagination.pageSize"
|
2025-04-25 09:57:54 +08:00
|
|
|
|
:page-sizes="[5, 10, 20, 50]" layout="total, sizes, prev, pager, next, jumper" :total="pagination.total"
|
|
|
|
|
@size-change="onSizeChange" @current-change="onCurrentChange" class="pagination" />
|
|
|
|
|
</div>
|
2025-04-22 15:39:45 +08:00
|
|
|
|
<el-dialog v-model="configVisible" title="配置商品" width="80%">
|
|
|
|
|
<CabinetGoodsConfigModal v-model="configVisible" :cell-id="currentCellId" @refresh="getList" />
|
|
|
|
|
</el-dialog>
|
|
|
|
|
</div>
|
2025-04-18 17:13:38 +08:00
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
2025-04-26 16:09:58 +08:00
|
|
|
|
<style lang="scss" scoped>
|
2025-04-22 15:39:45 +08:00
|
|
|
|
.flex {
|
|
|
|
|
display: flex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.border-r {
|
|
|
|
|
border-right: 1px solid #ebeef5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.left-list {
|
|
|
|
|
background: #FFFFFF;
|
|
|
|
|
padding: 15px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.search-form {
|
|
|
|
|
padding-left: 10px;
|
|
|
|
|
}
|
2025-04-25 09:57:54 +08:00
|
|
|
|
|
|
|
|
|
.pagination {
|
|
|
|
|
margin-top: 10px;
|
|
|
|
|
background: #FFFFFF;
|
|
|
|
|
padding: 7px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.cell-list {
|
|
|
|
|
margin-top: 10px;
|
|
|
|
|
}
|
2025-04-22 15:39:45 +08:00
|
|
|
|
</style>
|