2025-03-21 16:59:44 +08:00
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { ref, onMounted } from "vue";
|
|
|
|
|
import { PureTableBar } from "@/components/RePureTableBar";
|
2025-03-31 09:41:56 +08:00
|
|
|
|
import { onBeforeRouteUpdate, useRoute } from "vue-router";
|
2025-03-21 16:59:44 +08:00
|
|
|
|
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
|
|
|
|
|
import { getCabinetCellList, deleteCabinetCell, CabinetCellDTO } from "@/api/cabinet/cabinet-cell";
|
2025-05-13 10:42:57 +08:00
|
|
|
|
import { allCabinets, SmartCabinetDTO } from "@/api/cabinet/smart-cabinet";
|
2025-03-21 16:59:44 +08:00
|
|
|
|
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 CellFormModal from "./cell-form-modal.vue";
|
|
|
|
|
import CellEditModal from "./cell-edit-modal.vue";
|
|
|
|
|
import { ElMessage, ElMessageBox } from "element-plus";
|
2025-03-31 09:41:56 +08:00
|
|
|
|
import { on } from "events";
|
2025-03-21 16:59:44 +08:00
|
|
|
|
|
2025-05-13 10:42:57 +08:00
|
|
|
|
// 定义组件选项
|
2025-03-21 16:59:44 +08:00
|
|
|
|
defineOptions({
|
2025-05-13 10:42:57 +08:00
|
|
|
|
name: "CabinetCell" // 组件名称
|
2025-03-21 16:59:44 +08:00
|
|
|
|
});
|
|
|
|
|
|
2025-05-13 10:42:57 +08:00
|
|
|
|
// 表单引用
|
2025-03-21 16:59:44 +08:00
|
|
|
|
const formRef = ref();
|
2025-05-13 10:42:57 +08:00
|
|
|
|
// 表格引用
|
2025-03-21 16:59:44 +08:00
|
|
|
|
const tableRef = ref();
|
2025-05-13 10:42:57 +08:00
|
|
|
|
// 新增单元格模态框显示状态
|
2025-03-21 16:59:44 +08:00
|
|
|
|
const modalVisible = ref(false);
|
|
|
|
|
|
2025-05-13 10:42:57 +08:00
|
|
|
|
// 搜索表单参数
|
2025-03-21 16:59:44 +08:00
|
|
|
|
const searchFormParams = ref({
|
2025-05-13 10:42:57 +08:00
|
|
|
|
cabinetId: null, // 柜体ID
|
|
|
|
|
cellNo: null, // 单元格号
|
|
|
|
|
cellType: null // 单元格类型
|
2025-03-21 16:59:44 +08:00
|
|
|
|
});
|
|
|
|
|
|
2025-05-13 10:42:57 +08:00
|
|
|
|
// 分页参数
|
2025-03-21 16:59:44 +08:00
|
|
|
|
const pagination = ref({
|
2025-05-13 10:42:57 +08:00
|
|
|
|
pageSize: 10, // 每页显示数量
|
|
|
|
|
currentPage: 1, // 当前页码
|
|
|
|
|
total: 0 // 总条数
|
2025-03-21 16:59:44 +08:00
|
|
|
|
});
|
|
|
|
|
|
2025-05-13 10:42:57 +08:00
|
|
|
|
// 加载状态
|
2025-03-21 16:59:44 +08:00
|
|
|
|
const loading = ref(false);
|
2025-05-13 10:42:57 +08:00
|
|
|
|
// 表格数据列表
|
2025-03-21 16:59:44 +08:00
|
|
|
|
const dataList = ref([]);
|
2025-05-13 10:42:57 +08:00
|
|
|
|
// 多选选中项
|
2025-03-21 16:59:44 +08:00
|
|
|
|
const multipleSelection = ref<number[]>([]);
|
2025-05-13 10:42:57 +08:00
|
|
|
|
// 编辑单元格模态框显示状态
|
2025-03-21 16:59:44 +08:00
|
|
|
|
const editVisible = ref(false);
|
2025-05-13 10:42:57 +08:00
|
|
|
|
// 当前编辑行数据
|
2025-03-21 16:59:44 +08:00
|
|
|
|
const currentRow = ref<CabinetCellDTO>();
|
|
|
|
|
|
2025-05-13 10:42:57 +08:00
|
|
|
|
// 路由实例
|
2025-03-21 16:59:44 +08:00
|
|
|
|
const route = useRoute();
|
|
|
|
|
|
2025-05-13 10:42:57 +08:00
|
|
|
|
// 柜机列表数据
|
|
|
|
|
const cabinets = ref<SmartCabinetDTO[]>([]);
|
|
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
const { data } = await allCabinets();
|
|
|
|
|
cabinets.value = data;
|
2025-03-21 16:59:44 +08:00
|
|
|
|
if (route.query.cabinetId) {
|
|
|
|
|
searchFormParams.value.cabinetId = Number(route.query.cabinetId);
|
|
|
|
|
}
|
2025-05-13 10:42:57 +08:00
|
|
|
|
getList();
|
2025-03-21 16:59:44 +08:00
|
|
|
|
});
|
2025-03-31 09:41:56 +08:00
|
|
|
|
onBeforeRouteUpdate(() => {
|
|
|
|
|
if (route.query.cabinetId) {
|
|
|
|
|
searchFormParams.value.cabinetId = Number(route.query.cabinetId);
|
|
|
|
|
getList();
|
|
|
|
|
}
|
|
|
|
|
});
|
2025-03-21 16:59:44 +08:00
|
|
|
|
|
2025-05-13 10:42:57 +08:00
|
|
|
|
/**
|
|
|
|
|
* 获取单元格列表数据
|
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
|
*/
|
2025-03-21 16:59:44 +08:00
|
|
|
|
const getList = async () => {
|
|
|
|
|
try {
|
2025-05-13 10:42:57 +08:00
|
|
|
|
loading.value = true; // 显示加载状态
|
|
|
|
|
// 调用API获取单元格列表
|
2025-03-21 16:59:44 +08:00
|
|
|
|
const { data } = await getCabinetCellList({
|
2025-05-13 10:42:57 +08:00
|
|
|
|
...searchFormParams.value, // 搜索参数
|
|
|
|
|
pageSize: pagination.value.pageSize, // 每页数量
|
|
|
|
|
pageNum: pagination.value.currentPage // 当前页码
|
2025-03-21 16:59:44 +08:00
|
|
|
|
});
|
2025-05-13 10:42:57 +08:00
|
|
|
|
dataList.value = data.rows; // 更新表格数据
|
|
|
|
|
pagination.value.total = data.total; // 更新总条数
|
2025-03-21 16:59:44 +08:00
|
|
|
|
} finally {
|
2025-05-13 10:42:57 +08:00
|
|
|
|
loading.value = false; // 隐藏加载状态
|
2025-03-21 16:59:44 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-05-13 10:42:57 +08:00
|
|
|
|
/**
|
|
|
|
|
* 搜索按钮点击事件
|
|
|
|
|
* 重置页码为第一页并重新获取数据
|
|
|
|
|
*/
|
2025-03-21 16:59:44 +08:00
|
|
|
|
const onSearch = () => {
|
2025-05-13 10:42:57 +08:00
|
|
|
|
pagination.value.currentPage = 1; // 重置页码
|
|
|
|
|
getList(); // 重新获取数据
|
2025-03-21 16:59:44 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const resetForm = () => {
|
|
|
|
|
formRef.value.resetFields();
|
|
|
|
|
onSearch();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onSizeChange = (val: number) => {
|
|
|
|
|
pagination.value.pageSize = val;
|
|
|
|
|
getList();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onCurrentChange = (val: number) => {
|
|
|
|
|
pagination.value.currentPage = val;
|
|
|
|
|
getList();
|
|
|
|
|
};
|
|
|
|
|
|
2025-05-13 10:42:57 +08:00
|
|
|
|
/**
|
|
|
|
|
* 删除单元格
|
|
|
|
|
* @param {CabinetCellDTO} row - 要删除的单元格数据
|
|
|
|
|
*/
|
2025-03-21 16:59:44 +08:00
|
|
|
|
const handleDelete = async (row: CabinetCellDTO) => {
|
|
|
|
|
try {
|
2025-05-13 10:42:57 +08:00
|
|
|
|
// 调用API删除单元格
|
2025-03-21 16:59:44 +08:00
|
|
|
|
await deleteCabinetCell(row.cellId!.toString());
|
2025-05-13 10:42:57 +08:00
|
|
|
|
ElMessage.success("删除成功"); // 显示成功消息
|
|
|
|
|
getList(); // 刷新列表
|
2025-03-21 16:59:44 +08:00
|
|
|
|
} catch (error) {
|
2025-05-13 10:42:57 +08:00
|
|
|
|
console.error("删除失败", error); // 打印错误信息
|
2025-03-21 16:59:44 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
editVisible.value = true;
|
|
|
|
|
};
|
|
|
|
|
|
2025-05-13 10:42:57 +08:00
|
|
|
|
/**
|
|
|
|
|
* 转换单元格类型为中文描述
|
|
|
|
|
* @param {number} cellType - 单元格类型编号
|
|
|
|
|
* @returns {string} 单元格类型中文描述
|
|
|
|
|
*/
|
2025-03-21 16:59:44 +08:00
|
|
|
|
const switchCellType = (cellType: number) => {
|
|
|
|
|
switch (cellType) {
|
|
|
|
|
case 1:
|
|
|
|
|
return "小格";
|
|
|
|
|
case 2:
|
|
|
|
|
return "中格";
|
|
|
|
|
case 3:
|
|
|
|
|
return "大格";
|
|
|
|
|
case 4:
|
|
|
|
|
return "超大格";
|
|
|
|
|
default:
|
|
|
|
|
return "未知";
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
2025-05-13 10:42:57 +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-[99/100] pl-8 pt-[12px]">
|
|
|
|
|
<el-form-item label="柜体ID:" prop="cabinetId">
|
|
|
|
|
<el-input v-model.number="searchFormParams.cabinetId" placeholder="请输入柜体ID" clearable class="!w-[200px]" />
|
|
|
|
|
</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="primary" :icon="useRenderIcon(AddFill)" @click="modalVisible = true">
|
|
|
|
|
新增单元格
|
|
|
|
|
</el-button>
|
|
|
|
|
<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="柜体ID" prop="cabinetId" width="100" />
|
|
|
|
|
<el-table-column label="单元格号" prop="cellNo" width="120" />
|
|
|
|
|
<el-table-column label="针脚号" prop="pinNo" width="120" />
|
|
|
|
|
<el-table-column label="单元格类型" prop="cellType">
|
|
|
|
|
<template #default="{ row }">
|
|
|
|
|
{{ switchCellType(row.cellType) }}
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column label="使用状态" prop="usageStatus" width="120">
|
|
|
|
|
<template #default="{ row }">
|
|
|
|
|
{{ { 1: '空闲', 2: '已占用' }[row.usageStatus] || '未知' }}
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column label="可用状态" prop="availableStatus" width="120">
|
|
|
|
|
<template #default="{ row }">
|
|
|
|
|
<el-tag :type="row.availableStatus === 1 ? 'success' : 'danger'">
|
|
|
|
|
{{ { 1: '正常', 2: '故障' }[row.availableStatus] || '未知' }}
|
|
|
|
|
</el-tag>
|
|
|
|
|
</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-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>
|
|
|
|
|
<cell-form-modal v-model:visible="modalVisible" :initial-cabinet-id="searchFormParams.cabinetId"
|
|
|
|
|
@refresh="getList" />
|
|
|
|
|
<cell-edit-modal v-model:visible="editVisible" :row="currentRow" @refresh="getList" />
|
|
|
|
|
</div>
|
2025-03-21 16:59:44 +08:00
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
2025-05-13 10:42:57 +08:00
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.flex {
|
|
|
|
|
display: flex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.border-r {
|
|
|
|
|
border-right: 1px solid #ebeef5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.left-list {
|
|
|
|
|
background: #FFFFFF;
|
|
|
|
|
padding: 15px;
|
|
|
|
|
}
|
|
|
|
|
</style>
|