This commit is contained in:
xuyuncong 2025-10-15 17:39:54 +08:00
parent c91ebc3135
commit 8d0b878eec
2 changed files with 611 additions and 285 deletions

View File

@ -1,296 +1,627 @@
<template>
<div class="app-container">
<doc-alert title="功能权限" url="https://doc.iocoder.cn/resource-permission"/>
<doc-alert title="菜单路由" url="https://doc.iocoder.cn/vue2/route/"/>
<!-- 搜索工作栏 -->
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
<el-form-item label="菜单名称" prop="name">
<el-input v-model="queryParams.name" placeholder="请输入菜单名称" clearable @keyup.enter.native="handleQuery"/>
</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>
<template>
<div class="app-container">
<el-card>
<!-- 搜索区域 -->
<div style="display: flex; justify-content: space-between; align-items: center;">
<div class="filter-container">
<el-input
v-model="listQuery.name"
placeholder="业务渠道名称"
style="width: 200px;"
class="filter-item"
@keyup.enter.native="handleFilter"
/>
<el-button
class="filter-item"
type="primary"
icon="el-icon-search"
@click="handleFilter"
>
搜索
</el-button>
<el-button
class="filter-item"
style="margin-left: 10px;"
type="primary"
icon="el-icon-plus"
@click="handleAdd"
>
新增业务渠道
</el-button>
</div>
<div class="filter-container">
<el-button
class="filter-item"
style="margin-left: auto;"
icon="el-icon-refresh"
:loading="refreshing"
:disabled="refreshing"
@click="handleRefresh"
/>
</div>
</div>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增
</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="info" plain icon="el-icon-sort" size="mini" @click="toggleExpandAll">展开/折叠</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<!-- 表格 -->
<el-table
:data="menuList"
border
fit
highlight-current-row
style="width: 100%; margin-top: 20px;"
:expand-row-keys="expandedRows"
@expand-change="handleExpandChange"
>
<el-table-column type="expand">
<template slot-scope="{row}">
<div class="source-container">
<div class="source-header">
<span class="source-title">子项列表</span>
<el-button
type="primary"
size="medium"
icon="el-icon-plus"
@click="handleAddChild(row)"
>
添加子项
</el-button>
</div>
<el-table
:data="row.children || []"
size="medium"
style="width: 100%; margin-top: 10px;"
v-loading="row.loading"
border
>
<el-table-column label="名称" prop="name">
<template slot-scope="{row: child}">
<span class="bold-text">{{ child.name }}</span>
</template>
</el-table-column>
<el-table-column label="类型" width="120">
<template slot-scope="{row: child}">
<el-tag
:type="child.type === 0 ? 'primary' : 'success'"
size="small"
>
{{ child.type === 0 ? '业务渠道' : '客户来源' }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="{row: child}">
<el-button
type="primary"
size="small"
icon="el-icon-edit"
@click="handleUpdate(child)"
>
编辑
</el-button>
<el-button
type="danger"
size="small"
icon="el-icon-delete"
@click="handleDelete(child)"
>
删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
</template>
</el-table-column>
<el-table v-if="refreshTable" v-loading="loading" :data="menuList" row-key="id" :default-expand-all="isExpandAll"
:tree-props="{children: 'children', hasChildren: 'hasChildren'}">
<el-table-column prop="name" label="名称" :show-overflow-tooltip="true" width="250"></el-table-column>
<el-table-column prop="type" label="类型" width="100">
<template v-slot="scope">
<span>
{{ scope.row.type === 0 ? '业务渠道' : scope.row.type === 1 ? '客户来源' : '未知类型' }}
</span>
</template>
</el-table-column>
<el-table-column prop="sort" label="排序" width="100">
<template v-slot="scope">
<el-input v-model="scope.row.sort" @change="updateSort(scope.row)"></el-input>
</template>
</el-table-column>
<el-table-column label="渠道名称" prop="name">
<template slot-scope="{row}">
<div class="tree-node-content">
<!-- 对于顶级业务渠道添加拖拽手柄 -->
<span
class="drag-handle"
:draggable="true"
@dragstart="handleDragStart($event, row)"
@dragover="handleDragOver($event)"
@dragenter="handleDragEnter($event)"
@drop="handleDrop($event, row)"
@dragend="handleDragEnd"
>
<i class="el-icon-rank"></i>
</span>
<span class="bold-text">{{ row.name }}</span>
</div>
</template>
<template slot="header">
<span class="bold-header">渠道名称</span>
</template>
</el-table-column>
<el-table-column label="类型" width="120">
<template slot-scope="{row}">
<el-tag
:type="row.type === 0 ? 'primary' : 'success'"
size="small"
>
{{ row.type === 0 ? '业务渠道' : '客户来源' }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="{row}">
<el-button
type="primary"
size="small"
icon="el-icon-edit"
@click="handleUpdate(row)"
>
编辑
</el-button>
<el-button
type="danger"
size="small"
icon="el-icon-delete"
@click="handleDelete(row)"
>
删除
</el-button>
</template>
</el-table-column>
</el-table>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template v-slot="scope">
<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">修改
<!-- 分页 -->
<pagination
v-show="total>0"
:total="total"
:page.sync="listQuery.page"
:limit.sync="listQuery.limit"
@pagination="getList"
/>
</el-card>
<!-- 业务渠道对话框 -->
<el-dialog
:title="dialogTitle"
:visible.sync="dialogVisible"
width="500px"
>
<el-form
ref="form"
:rules="rules"
:model="form"
label-position="left"
label-width="80px"
style="width: 400px; margin-left:50px;"
>
<el-form-item label="名称" prop="name">
<el-input v-model="form.name" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">
取消
</el-button>
<el-button size="mini" v-if="scope.row.pid == 0" type="text" icon="el-icon-plus"
@click="handleAdd(scope.row)">新增
<el-button type="primary" @click="save">
确认
</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>
</el-dialog>
</div>
</template>
<!-- 添加或修改菜单对话框 -->
<el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="100px">
<el-row>
<el-col :span="12">
<el-form-item label="名称" prop="name">
<el-input v-model="form.name" placeholder="请输入名称"/>
</el-form-item>
</el-col>
<!-- <el-col :span="12" v-if="form.pid != 0">-->
<!-- <el-form-item label="人员" prop="postId">-->
<!-- <el-select multiple filterable v-model="form.userIdList" placeholder="请选择人员">-->
<!-- <el-option v-for="item in staffList" :key="item.id" :label="item.nickname" :value="item.id"/>-->
<!-- </el-select>-->
<!-- </el-form-item>-->
<!-- </el-col>-->
</el-row>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import Pagination from '@/components/Pagination'
import {
listBusiness,
getBusiness,
addBusiness,
updateBusiness,
delBusiness
} from './api'
import { getLastPathSegment } from "@/utils/ruoyi"
<script>
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import IconSelect from "@/components/IconSelect";
import {getDictDatas, DICT_TYPE} from '@/utils/dict'
import {
addBusiness,
delBusiness,
getBusiness,
listBusiness,
updateBusiness
} from "@/views/company/businessChannel/api";
import {listUser} from "@/views/inspection/staff/api/staff";
import {getLastPathSegment} from "@/utils/ruoyi";
export default {
name: "BusinessChannel",
components: {Treeselect, IconSelect},
data() {
return {
//
loading: true,
//
showSearch: true,
//
menuList: [],
staffList: [],
//
menuOptions: [],
//
title: "",
//
open: false,
//
isExpandAll: false,
//
refreshTable: true,
//
queryParams: {
name: undefined,
visible: undefined,
systemCode: undefined
},
//
form: {},
//
rules: {
},
//
menuTypeDictDatas: getDictDatas(DICT_TYPE.SYSTEM_MENU_TYPE),
statusDictDatas: getDictDatas("ins_business")
};
},
created() {
const servicePackageId = getLastPathSegment(this.$route.path); //
console.log('服务套餐', servicePackageId)
this.queryParams.systemCode = servicePackageId;
this.getList();
this.getStaff();
},
methods: {
//
selected(name) {
this.form.icon = name;
},
/** 查询菜单列表 */
getList() {
this.loading = true;
listBusiness(this.queryParams).then(response => {
this.menuList = this.handleTree(response.data, "id", "pid");
this.loading = false;
});
},
getStaff() {
const params = {
pageNo: 1,
pageSize: 99999
export default {
name: 'BusinessChannel',
components: { Pagination },
filters: {
parseTime(time) {
if (!time) return ''
return new Date(time).toLocaleString()
}
listUser(params).then(response => {
this.staffList = response.data.records;
});
},
/** 转换菜单数据结构 */
normalizer(node) {
if (node.children && !node.children.length) {
delete node.children;
}
data() {
return {
id: node.id,
label: node.name,
children: node.children
};
},
/** 查询菜单下拉树结构 */
getTreeselect() {
listBusiness().then(response => {
this.menuOptions = [];
const menu = {id: 0, name: '主类目', children: []};
if (!Array.isArray(response.data)) {
console.warn("handleTree error: data 不是数组", response.data);
return;
}
if (response.data.length === 0) {
console.warn("handleTree warning: data 是空数组");
return;
}
// data
debugger
menu.children = this.handleTree(response.data, "id", 'pid');
this.menuOptions.push(menu);
});
},
//
updateSort(data) {
updateBusiness(data).then(response => {
this.$modal.msgSuccess("修改成功");
this.getList();
});
},
//
cancel() {
this.open = false;
this.reset();
},
//
reset() {
this.form = {
id: undefined,
pid: 0,
name: undefined,
type: undefined,
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
/** 展开/折叠操作 */
toggleExpandAll() {
this.refreshTable = false;
this.isExpandAll = !this.isExpandAll;
this.$nextTick(() => {
this.refreshTable = true;
});
},
/** 新增按钮操作 */
handleAdd(row) {
this.reset();
this.getTreeselect();
if (row != null && row.id) {
this.form.pid = row.id;
this.form.type = 1;
this.title = "添加客户来源";
} else {
this.form.pid = 0;
this.form.type = 0;
this.title = "添加业务渠道";
//
list: [],
menuList: [],
total: 0,
listQuery: {
page: 1,
limit: 20,
name: undefined,
systemCode: undefined
},
//
expandedRows: [],
//
form: {
id: undefined,
pid: 0,
name: '',
type: 0
},
//
dialogVisible: false,
dialogTitle: '',
refreshing: false,
loading: false,
//
rules: {
name: [{ required: true, message: '名称不能为空', trigger: 'blur' }]
},
//
dragNode: null,
dragState: 'normal',
dragTargetNode: null
}
this.open = true;
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
this.getTreeselect();
getBusiness(row.id).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改";
});
created() {
const servicePackageId = getLastPathSegment(this.$route.path);
this.listQuery.systemCode = servicePackageId;
this.getList()
},
/** 提交按钮 */
submitForm: function () {
this.$refs["form"].validate(valid => {
this.form.systemCode = this.queryParams.systemCode;
if (valid) {
//
if (this.form.id !== undefined) {
updateBusiness(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addBusiness(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
methods: {
//
async getList() {
this.loading = true
try {
const response = await listBusiness(this.listQuery)
this.menuList = this.handleTree(response.data, "id", "pid")
this.total = response.data.length || 0
console.log('menuList:', this.menuList);
//
this.expandedRows = []
} catch (error) {
console.error('获取列表失败:', error)
} finally {
this.loading = false
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
this.$modal.confirm('是否确认删除名称为"' + row.name + '"的数据项?').then(function () {
return delBusiness(row.id);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {
});
},
// //
// handleTree(data, id, parentId, children) {
// const result = [];
// const hash = {};
// const len = data.length;
// for (let i = 0; i < len; i++) {
// hash[data[i][id]] = data[i];
// }
// for (let i = 0; i < len; i++) {
// const parent = hash[data[i][parentId]];
// if (parent) {
// !parent[children] && (parent[children] = []);
// parent[children].push(data[i]);
// } else {
// result.push(data[i]);
// }
// }
// return result;
// },
// /
handleExpandChange(row, expandedRows) {
//
},
//
handleFilter() {
this.listQuery.page = 1
//
this.expandedRows = []
this.getList()
},
//
async handleRefresh() {
this.refreshing = true
try {
await this.getList()
this.$message.success('刷新成功')
} catch (error) {
console.error('刷新失败:', error)
} finally {
this.refreshing = false
}
},
//
handleAdd() {
this.form = {
id: undefined,
pid: 0,
name: '',
type: 0
}
this.dialogTitle = '新增业务渠道'
this.dialogVisible = true
this.$nextTick(() => {
this.$refs.form?.clearValidate()
})
},
//
handleAddChild(row) {
this.form = {
id: undefined,
pid: row.id,
name: '',
type: 1
}
this.dialogTitle = '添加子项'
this.dialogVisible = true
this.$nextTick(() => {
this.$refs.form?.clearValidate()
})
},
//
handleUpdate(row) {
this.form = { ...row }
this.dialogTitle = '编辑'
this.dialogVisible = true
this.$nextTick(() => {
this.$refs.form?.clearValidate()
})
},
//
async save() {
this.$refs.form.validate(async(valid) => {
if (valid) {
try {
this.form.systemCode = this.listQuery.systemCode;
if (this.form.id) {
await updateBusiness(this.form)
} else {
await addBusiness(this.form)
}
this.dialogVisible = false
this.$message.success('保存成功')
this.getList()
} catch (error) {
console.error('保存失败:', error)
}
}
})
},
//
async handleDelete(row) {
this.$confirm(`确定要删除"${row.name}"吗?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(async() => {
try {
await delBusiness(row.id)
this.$message.success('删除成功!')
this.getList()
} catch (error) {
console.error('删除失败:', error)
}
}).catch(() => {})
},
//
handleDragStart(event, row) {
//
this.dragNode = row
this.dragState = 'dragging'
//
event.dataTransfer.setData('application/json', JSON.stringify(row))
//
event.dataTransfer.effectAllowed = 'move'
//
setTimeout(() => {
if (event.target) {
event.target.classList.add('dragging')
}
}, 0)
},
//
handleDragEnd(event) {
//
if (event.target) {
event.target.classList.remove('dragging')
}
//
setTimeout(() => {
this.dragNode = null
this.dragTargetNode = null
this.dragState = 'normal'
}, 300)
},
//
handleDrop(event, targetRow) {
//
event.preventDefault()
event.stopPropagation()
// pid === 0
if (targetRow.pid !== 0 || !this.dragNode || this.dragNode.id === targetRow.id) {
return
}
try {
this.dragTargetNode = targetRow
//
const dragIndex = this.menuList.findIndex(item => item.id === this.dragNode.id)
const targetIndex = this.menuList.findIndex(item => item.id === targetRow.id)
if (dragIndex === -1 || targetIndex === -1) return
//
const newList = [...this.menuList]
newList.splice(dragIndex, 1)
newList.splice(targetIndex, 0, this.dragNode)
// 使10便
const updateList = newList.map((item, index) => ({
id: item.id,
sort: (index + 1) * 10,
//
pid: item.pid,
name: item.name,
type: item.type,
systemCode: this.listQuery.systemCode
}))
//
this.batchUpdateSort(updateList)
this.dragState = 'success'
} catch (error) {
console.error('拖拽排序出错:', error)
this.dragState = 'error'
this.$message.error('排序失败,请重试')
}
},
//
handleDragOver(event) {
event.preventDefault()
event.dataTransfer.dropEffect = 'move'
},
//
handleDragEnter(event) {
event.preventDefault()
},
//
batchUpdateSort(updateList) {
this.loading = true
const promises = updateList.map(item => updateBusiness(item))
Promise.all(promises)
.then(() => {
this.$message.success("排序更新成功")
this.getList()
})
.catch(error => {
console.error('批量更新排序失败:', error)
this.$message.error("排序更新失败")
this.getList()
})
.finally(() => {
// loading
this.loading = false
})
}
}
}
};
</script>
</script>
<style scoped>
.filter-container {
margin-bottom: 20px;
}
.filter-item {
margin-right: 10px;
}
/* 加粗样式 */
.bold-header {
font-weight: bold;
font-size: 14px;
color: black;
}
.bold-text {
font-weight: bold;
color: black;
}
/* 来源容器样式 */
.source-container {
padding: 10px;
background: #fafafa;
}
.source-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
}
.source-title {
font-weight: bold;
color: #606266;
}
/* 树形节点内容 */
.tree-node-content {
display: flex;
align-items: center;
}
/* 拖拽样式 */
.drag-handle {
display: inline-flex;
align-items: center;
justify-content: center;
width: 24px;
height: 24px;
margin-right: 8px;
cursor: move;
color: #909399;
border-radius: 4px;
transition: all 0.3s;
user-select: none;
}
.drag-handle:hover {
background-color: #ecf5ff;
color: #409eff;
}
.drag-handle.dragging {
background-color: #409eff;
color: white;
opacity: 0.8;
}
/* 排序数字样式 */
.sort-number {
display: inline-block;
padding: 2px 8px;
background-color: #ecf5ff;
color: #409eff;
border-radius: 4px;
font-size: 12px;
font-weight: 500;
}
.sub-sort-number {
display: inline-block;
padding: 2px 8px;
background-color: #f0f9eb;
color: #67c23a;
border-radius: 4px;
font-size: 12px;
}
/* 全局样式,确保表头也加粗 */
.el-table .bold-header {
font-weight: bold !important;
}
.el-table .bold-text {
font-weight: bold !important;
}
</style>

View File

@ -121,11 +121,6 @@
<el-input v-model="form.mobile" placeholder="请输入手机号码" maxlength="11"/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="邮箱" prop="email">
<el-input v-model="form.email" placeholder="请输入邮箱" maxlength="50"/>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">