581 lines
26 KiB
HTML
581 lines
26 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>资产分类管理</title>
|
|
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
padding: 20px;
|
|
font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
|
|
}
|
|
.container {
|
|
display: flex;
|
|
border: 1px solid #ebeef5;
|
|
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
|
|
}
|
|
.left-panel {
|
|
width: 280px;
|
|
border-right: 1px solid #e6e6e6;
|
|
padding: 10px;
|
|
overflow: auto;
|
|
height: calc(100vh - 60px);
|
|
}
|
|
.tree-container {
|
|
margin-top: 10px;
|
|
}
|
|
.right-panel {
|
|
flex: 1;
|
|
padding: 10px;
|
|
overflow: auto;
|
|
}
|
|
.search-bar {
|
|
margin-bottom: 15px;
|
|
}
|
|
.action-bar {
|
|
margin-bottom: 15px;
|
|
}
|
|
.status-enabled {
|
|
color: #67C23A;
|
|
}
|
|
.status-disabled {
|
|
color: #F56C6C;
|
|
}
|
|
.custom-tree-node {
|
|
flex: 1;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
font-size: 14px;
|
|
padding-right: 8px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="app">
|
|
<h2>资产分类管理</h2>
|
|
<div class="container">
|
|
<!-- 左侧树形结构 -->
|
|
<div class="left-panel">
|
|
<h3>分类结构</h3>
|
|
<div class="tree-container">
|
|
<el-tree
|
|
ref="tree"
|
|
:data="treeData"
|
|
node-key="id"
|
|
:props="defaultProps"
|
|
:highlight-current="true"
|
|
:expand-on-click-node="false"
|
|
@node-click="handleNodeClick"
|
|
:default-expand-all="false"
|
|
:load="loadNode"
|
|
lazy>
|
|
<span class="custom-tree-node" slot-scope="{ node, data }">
|
|
<span>{{ node.label }}</span>
|
|
</span>
|
|
</el-tree>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 右侧列表 -->
|
|
<div class="right-panel">
|
|
<div class="search-bar">
|
|
<el-form :inline="true" :model="queryParams" size="small">
|
|
<el-form-item label="分类编码">
|
|
<el-input v-model="queryParams.classificationCode" placeholder="请输入分类编码" clearable></el-input>
|
|
</el-form-item>
|
|
<el-form-item label="分类名称">
|
|
<el-input v-model="queryParams.classificationName" placeholder="请输入分类名称" clearable></el-input>
|
|
</el-form-item>
|
|
<el-form-item>
|
|
<el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
|
|
<el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
|
|
</el-form-item>
|
|
</el-form>
|
|
</div>
|
|
|
|
<div class="action-bar">
|
|
<el-button type="primary" size="small" icon="el-icon-plus" @click="handleAdd">新增</el-button>
|
|
<el-button type="danger" size="small" icon="el-icon-delete" :disabled="selectedIds.length === 0" @click="handleBatchDelete">批量删除</el-button>
|
|
</div>
|
|
|
|
<el-table v-loading="loading" :data="classificationList" border @selection-change="handleSelectionChange">
|
|
<el-table-column type="selection" width="55" align="center"></el-table-column>
|
|
<el-table-column label="分类编码" prop="classificationCode" width="150"></el-table-column>
|
|
<el-table-column label="分类名称" prop="classificationName" width="150"></el-table-column>
|
|
<el-table-column label="上级分类" prop="parentName" width="150">
|
|
<template slot-scope="scope">
|
|
<span>{{ getParentName(scope.row.parentId) }}</span>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column label="状态" align="center" width="100">
|
|
<template slot-scope="scope">
|
|
<el-tag :type="scope.row.status === '1' ? 'success' : 'danger'">
|
|
{{ scope.row.status === '1' ? '启用' : '禁用' }}
|
|
</el-tag>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column label="备注" prop="remark" :show-overflow-tooltip="true"></el-table-column>
|
|
<el-table-column label="操作" align="center" width="200">
|
|
<template slot-scope="scope">
|
|
<el-button size="mini" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)">修改</el-button>
|
|
<el-button size="mini" type="text" :icon="scope.row.status === '1' ? 'el-icon-close' : 'el-icon-check'"
|
|
@click="handleStatusChange(scope.row)">{{ scope.row.status === '1' ? '禁用' : '启用' }}</el-button>
|
|
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
|
|
</template>
|
|
</el-table-column>
|
|
</el-table>
|
|
|
|
<div class="pagination-container" style="margin-top: 15px;">
|
|
<el-pagination
|
|
background
|
|
@size-change="handleSizeChange"
|
|
@current-change="handleCurrentChange"
|
|
:current-page="queryParams.pageNum"
|
|
:page-sizes="[10, 20, 50, 100]"
|
|
:page-size="queryParams.pageSize"
|
|
layout="total, sizes, prev, pager, next, jumper"
|
|
:total="total">
|
|
</el-pagination>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 添加/编辑对话框 -->
|
|
<el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="500px" append-to-body>
|
|
<el-form ref="form" :model="form" :rules="rules" label-width="100px">
|
|
<el-form-item label="分类编码" prop="classificationCode">
|
|
<el-input v-model="form.classificationCode" placeholder="请输入分类编码"></el-input>
|
|
</el-form-item>
|
|
<el-form-item label="分类名称" prop="classificationName">
|
|
<el-input v-model="form.classificationName" placeholder="请输入分类名称"></el-input>
|
|
</el-form-item>
|
|
<el-form-item label="上级分类" prop="parentId">
|
|
<el-cascader
|
|
v-model="form.parentId"
|
|
:options="classificationOptions"
|
|
:props="{ checkStrictly: true, value: 'id', label: 'classificationName' }"
|
|
clearable
|
|
placeholder="请选择上级分类">
|
|
</el-cascader>
|
|
</el-form-item>
|
|
<el-form-item label="状态">
|
|
<el-radio-group v-model="form.status">
|
|
<el-radio label="1">启用</el-radio>
|
|
<el-radio label="0">禁用</el-radio>
|
|
</el-radio-group>
|
|
</el-form-item>
|
|
<el-form-item label="备注">
|
|
<el-input v-model="form.remark" type="textarea" rows="3" placeholder="请输入备注"></el-input>
|
|
</el-form-item>
|
|
</el-form>
|
|
<div slot="footer" class="dialog-footer">
|
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
|
<el-button type="primary" @click="submitForm">确 定</el-button>
|
|
</div>
|
|
</el-dialog>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
|
|
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
|
<script>
|
|
new Vue({
|
|
el: '#app',
|
|
data() {
|
|
return {
|
|
// 遮罩层
|
|
loading: false,
|
|
// 选中数组
|
|
selectedIds: [],
|
|
// 非单个禁用
|
|
single: true,
|
|
// 非多个禁用
|
|
multiple: true,
|
|
// 显示搜索条件
|
|
showSearch: true,
|
|
// 总条数
|
|
total: 0,
|
|
// 资产分类表格数据
|
|
classificationList: [],
|
|
// 弹出层标题
|
|
dialogTitle: "",
|
|
// 是否显示弹出层
|
|
dialogVisible: false,
|
|
// 树形数据
|
|
treeData: [],
|
|
// 当前选中的节点
|
|
currentNode: null,
|
|
// 分类选项树
|
|
classificationOptions: [],
|
|
// 表单参数
|
|
form: {
|
|
id: null,
|
|
classificationCode: null,
|
|
classificationName: null,
|
|
parentId: null,
|
|
status: "1",
|
|
remark: null,
|
|
createUserId: "admin", // 默认创建人
|
|
tenantId: "T001" // 默认租户ID
|
|
},
|
|
// 查询参数
|
|
queryParams: {
|
|
pageNum: 1,
|
|
pageSize: 10,
|
|
classificationCode: null,
|
|
classificationName: null,
|
|
parentId: null,
|
|
status: null,
|
|
tenantId: "T001" // 默认租户ID
|
|
},
|
|
// 表单校验
|
|
rules: {
|
|
classificationCode: [
|
|
{ required: true, message: "分类编码不能为空", trigger: "blur" }
|
|
],
|
|
classificationName: [
|
|
{ required: true, message: "分类名称不能为空", trigger: "blur" }
|
|
]
|
|
},
|
|
defaultProps: {
|
|
children: 'children',
|
|
label: 'label',
|
|
isLeaf: 'leaf'
|
|
}
|
|
};
|
|
},
|
|
created() {
|
|
this.getList();
|
|
},
|
|
methods: {
|
|
/** 查询资产分类列表 */
|
|
getList() {
|
|
this.loading = true;
|
|
axios.get('/asset/classification/list', {
|
|
params: this.queryParams
|
|
}).then(response => {
|
|
this.classificationList = response.data.list;
|
|
this.total = response.data.total;
|
|
this.loading = false;
|
|
}).catch(error => {
|
|
this.loading = false;
|
|
console.error("获取资产分类列表失败:", error);
|
|
this.$message.error("获取资产分类列表失败");
|
|
});
|
|
},
|
|
/** 加载树节点数据 */
|
|
loadNode(node, resolve) {
|
|
if (node.level === 0) {
|
|
// 加载根节点
|
|
axios.get('/asset/classification/tree', {
|
|
params: {
|
|
tenantId: this.queryParams.tenantId
|
|
}
|
|
}).then(response => {
|
|
resolve(response.data);
|
|
}).catch(error => {
|
|
console.error("获取资产分类树失败:", error);
|
|
this.$message.error("获取资产分类树失败");
|
|
resolve([]);
|
|
});
|
|
} else {
|
|
// 加载子节点
|
|
if (node.data.hasChildren) {
|
|
axios.get('/asset/classification/tree', {
|
|
params: {
|
|
parentId: node.data.id,
|
|
tenantId: this.queryParams.tenantId
|
|
}
|
|
}).then(response => {
|
|
resolve(response.data);
|
|
}).catch(error => {
|
|
console.error("获取资产分类子节点失败:", error);
|
|
this.$message.error("获取资产分类子节点失败");
|
|
resolve([]);
|
|
});
|
|
} else {
|
|
resolve([]);
|
|
}
|
|
}
|
|
},
|
|
/** 获取上级分类名称 */
|
|
getParentName(parentId) {
|
|
if (!parentId) {
|
|
return "无上级分类";
|
|
}
|
|
const found = this.classificationList.find(item => item.id === parentId);
|
|
return found ? found.classificationName : "未知分类";
|
|
},
|
|
/** 树节点点击事件 */
|
|
handleNodeClick(data) {
|
|
this.currentNode = data;
|
|
this.queryParams.parentId = data.id;
|
|
this.queryParams.classificationCode = null;
|
|
this.queryParams.classificationName = null;
|
|
this.getChildrenList();
|
|
},
|
|
/** 获取选中节点的所有子节点列表 */
|
|
getChildrenList() {
|
|
if (this.currentNode) {
|
|
this.loading = true;
|
|
axios.get(`/asset/classification/children/${this.currentNode.id}`, {
|
|
params: {
|
|
tenantId: this.queryParams.tenantId,
|
|
pageNum: this.queryParams.pageNum,
|
|
pageSize: this.queryParams.pageSize
|
|
}
|
|
}).then(response => {
|
|
this.classificationList = response.data.list;
|
|
this.total = response.data.total;
|
|
this.loading = false;
|
|
}).catch(error => {
|
|
this.loading = false;
|
|
console.error("获取子节点列表失败:", error);
|
|
this.$message.error("获取子节点列表失败");
|
|
});
|
|
}
|
|
},
|
|
/** 搜索按钮操作 */
|
|
handleQuery() {
|
|
this.queryParams.pageNum = 1;
|
|
this.queryParams.parentId = null; // 清空父节点ID
|
|
this.currentNode = null; // 清空当前选中节点
|
|
this.getList();
|
|
},
|
|
/** 重置按钮操作 */
|
|
resetQuery() {
|
|
this.queryParams = {
|
|
pageNum: 1,
|
|
pageSize: 10,
|
|
classificationCode: null,
|
|
classificationName: null,
|
|
parentId: null,
|
|
status: null,
|
|
tenantId: "T001"
|
|
};
|
|
this.currentNode = null;
|
|
this.getList();
|
|
},
|
|
/** 多选框选中数据 */
|
|
handleSelectionChange(selection) {
|
|
this.selectedIds = selection.map(item => item.id);
|
|
},
|
|
/** 新增按钮操作 */
|
|
handleAdd() {
|
|
this.resetForm();
|
|
if (this.currentNode) {
|
|
this.form.parentId = this.currentNode.id;
|
|
}
|
|
this.dialogTitle = "添加资产分类";
|
|
this.dialogVisible = true;
|
|
// 获取分类选项树
|
|
this.getClassificationOptions();
|
|
},
|
|
/** 获取分类选项树 */
|
|
getClassificationOptions() {
|
|
axios.get('/asset/classification/list', {
|
|
params: {
|
|
tenantId: this.queryParams.tenantId,
|
|
pageSize: 1000 // 获取所有数据
|
|
}
|
|
}).then(response => {
|
|
this.classificationOptions = this.buildClassificationTree(response.data.list);
|
|
}).catch(error => {
|
|
console.error("获取分类选项失败:", error);
|
|
this.$message.error("获取分类选项失败");
|
|
});
|
|
},
|
|
/** 构建分类选项树 */
|
|
buildClassificationTree(classifications) {
|
|
const result = [];
|
|
const map = {};
|
|
|
|
// 将所有分类添加到map
|
|
classifications.forEach(item => {
|
|
map[item.id] = {
|
|
id: item.id,
|
|
classificationName: item.classificationName,
|
|
parentId: item.parentId,
|
|
children: []
|
|
};
|
|
});
|
|
|
|
// 构建树结构
|
|
classifications.forEach(item => {
|
|
const mapItem = map[item.id];
|
|
if (item.parentId && map[item.parentId]) {
|
|
map[item.parentId].children.push(mapItem);
|
|
} else {
|
|
result.push(mapItem);
|
|
}
|
|
});
|
|
|
|
return result;
|
|
},
|
|
/** 表单重置 */
|
|
resetForm() {
|
|
this.form = {
|
|
id: null,
|
|
classificationCode: null,
|
|
classificationName: null,
|
|
parentId: null,
|
|
status: "1",
|
|
remark: null,
|
|
createUserId: "admin",
|
|
tenantId: "T001"
|
|
};
|
|
},
|
|
/** 修改按钮操作 */
|
|
handleEdit(row) {
|
|
this.resetForm();
|
|
const id = row.id || this.selectedIds[0];
|
|
axios.get(`/asset/classification/${id}`).then(response => {
|
|
this.form = response.data;
|
|
this.dialogTitle = "修改资产分类";
|
|
this.dialogVisible = true;
|
|
// 获取分类选项树
|
|
this.getClassificationOptions();
|
|
}).catch(error => {
|
|
console.error("获取资产分类详情失败:", error);
|
|
this.$message.error("获取资产分类详情失败");
|
|
});
|
|
},
|
|
/** 提交表单 */
|
|
submitForm() {
|
|
this.$refs["form"].validate(valid => {
|
|
if (valid) {
|
|
if (this.form.id) {
|
|
// 修改
|
|
this.form.lastModUserId = "admin"; // 设置修改人ID
|
|
axios.put('/asset/classification', this.form).then(response => {
|
|
if (response.data > 0) {
|
|
this.$message.success("修改成功");
|
|
this.dialogVisible = false;
|
|
this.getList();
|
|
// 刷新树
|
|
this.$refs.tree.store.load();
|
|
} else {
|
|
this.$message.error("修改失败");
|
|
}
|
|
}).catch(error => {
|
|
console.error("修改资产分类失败:", error);
|
|
this.$message.error("修改资产分类失败");
|
|
});
|
|
} else {
|
|
// 新增
|
|
axios.post('/asset/classification', this.form).then(response => {
|
|
if (response.data > 0) {
|
|
this.$message.success("新增成功");
|
|
this.dialogVisible = false;
|
|
this.getList();
|
|
// 刷新树
|
|
this.$refs.tree.store.load();
|
|
} else {
|
|
this.$message.error("新增失败");
|
|
}
|
|
}).catch(error => {
|
|
console.error("新增资产分类失败:", error);
|
|
this.$message.error("新增资产分类失败");
|
|
});
|
|
}
|
|
}
|
|
});
|
|
},
|
|
/** 删除按钮操作 */
|
|
handleDelete(row) {
|
|
const id = row.id;
|
|
this.$confirm('是否确认删除该资产分类?', "警告", {
|
|
confirmButtonText: "确定",
|
|
cancelButtonText: "取消",
|
|
type: "warning"
|
|
}).then(() => {
|
|
return axios.delete(`/asset/classification/${id}`, {
|
|
params: { lastModUserId: "admin" }
|
|
});
|
|
}).then(response => {
|
|
if (response.data > 0) {
|
|
this.$message.success("删除成功");
|
|
this.getList();
|
|
// 刷新树
|
|
this.$refs.tree.store.load();
|
|
} else {
|
|
this.$message.error("删除失败");
|
|
}
|
|
}).catch(error => {
|
|
console.error("删除资产分类失败:", error);
|
|
this.$message.error("删除资产分类失败");
|
|
});
|
|
},
|
|
/** 批量删除操作 */
|
|
handleBatchDelete() {
|
|
if (this.selectedIds.length === 0) {
|
|
this.$message.warning("请选择要删除的资产分类");
|
|
return;
|
|
}
|
|
this.$confirm('是否确认批量删除选中的资产分类?', "警告", {
|
|
confirmButtonText: "确定",
|
|
cancelButtonText: "取消",
|
|
type: "warning"
|
|
}).then(() => {
|
|
return axios.delete(`/asset/classification/batch/${this.selectedIds.join(',')}`, {
|
|
params: { lastModUserId: "admin" }
|
|
});
|
|
}).then(response => {
|
|
if (response.data > 0) {
|
|
this.$message.success("批量删除成功");
|
|
this.getList();
|
|
// 刷新树
|
|
this.$refs.tree.store.load();
|
|
} else {
|
|
this.$message.error("批量删除失败");
|
|
}
|
|
}).catch(error => {
|
|
console.error("批量删除资产分类失败:", error);
|
|
this.$message.error("批量删除资产分类失败");
|
|
});
|
|
},
|
|
/** 状态修改操作 */
|
|
handleStatusChange(row) {
|
|
const id = row.id;
|
|
const status = row.status === "1" ? "0" : "1";
|
|
const text = status === "1" ? "启用" : "禁用";
|
|
this.$confirm(`确认要${text}该资产分类吗?`, "警告", {
|
|
confirmButtonText: "确定",
|
|
cancelButtonText: "取消",
|
|
type: "warning"
|
|
}).then(() => {
|
|
return axios.put('/asset/classification', {
|
|
id: id,
|
|
status: status,
|
|
lastModUserId: "admin"
|
|
});
|
|
}).then(response => {
|
|
if (response.data > 0) {
|
|
this.$message.success(`${text}成功`);
|
|
this.getList();
|
|
} else {
|
|
this.$message.error(`${text}失败`);
|
|
}
|
|
}).catch(error => {
|
|
console.error(`${text}资产分类失败:`, error);
|
|
this.$message.error(`${text}资产分类失败`);
|
|
});
|
|
},
|
|
/** 页面大小改变事件处理 */
|
|
handleSizeChange(val) {
|
|
this.queryParams.pageSize = val;
|
|
this.getList();
|
|
},
|
|
/** 页码改变事件处理 */
|
|
handleCurrentChange(val) {
|
|
this.queryParams.pageNum = val;
|
|
this.getList();
|
|
}
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html> |