<template>
|
<a-card
|
:loading="cardLoading"
|
:bordered="false"
|
title="部门管理"
|
style="height: 100%;"
|
>
|
<a-spin :spinning="loading">
|
<a-alert
|
type="info"
|
:showIcon="true"
|
style="margin-right: 54px;"
|
>
|
<div slot="message">
|
当前:<span v-if="this.currSelected.title">{{ getCurrSelectedTitle() }}</span>
|
<a
|
v-if="this.currSelected.title"
|
style="margin-left: 10px"
|
@click="onClearSelected"
|
>取消</a>
|
</div>
|
</a-alert>
|
<div class="drawer-bootom-button">
|
<a-dropdown
|
:trigger="['click']"
|
placement="bottomCenter"
|
>
|
<a-menu slot="overlay">
|
<a-menu-item
|
key="1"
|
@click="expandAll"
|
>展开所有</a-menu-item>
|
<a-menu-item
|
key="2"
|
@click="closeAll"
|
>合并所有</a-menu-item>
|
<a-menu-item
|
key="3"
|
@click="refreshTree"
|
>刷新</a-menu-item>
|
<a-menu-item
|
type="primary"
|
key="4"
|
@click="showDragRegulation"
|
:style="getEnterpriseOptionStyle('2')"
|
>结点拖拽规则</a-menu-item>
|
</a-menu>
|
<a-button>
|
<a-icon type="bars" />
|
</a-button>
|
</a-dropdown>
|
</div>
|
<a-select
|
style="width:100%;margin-top: 10px"
|
placeholder="选择企业"
|
allowClear
|
v-model="departInfo.enterpriseId"
|
>
|
<a-select-option v-for="item of this.enterpriseList" :value="item.id" :key="item.id">
|
<span :style="getEnterpriseOptionStyle(item.versionStatus)">{{item.name}} <a-icon type="tag" /> {{"V"+item.version+".0"+"("+getVersionStatusDetail(item.versionStatus)+")"}}</span>
|
</a-select-option>
|
</a-select>
|
<a-tree
|
selectable
|
showLine
|
:showIcon="true"
|
:checkStrictly="checkStrictly"
|
:expandedKeys.sync="expandedKeys"
|
:selectedKeys="selectedKeys"
|
:dropdownStyle="{maxHeight:'200px',overflow:'auto'}"
|
:treeData="treeDataSource"
|
:autoExpandParent="autoExpandParent"
|
@select="onSelect"
|
@expand="onExpand"
|
rowKey="id"
|
:draggable="true"
|
@drop="onDrop"
|
style="padding:20px"
|
>
|
<svg slot="total" t="1675650355896" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="17715"><path d="M512 128 128 326.4 896 326.4Z" p-id="17716" fill="#707070"></path><path d="M128 832l768 0 0 64-768 0 0-64Z" p-id="17717" fill="#707070"></path><path d="M230.4 384l0 384c0 19.2 12.8 32 32 32s32-12.8 32-32L294.4 384c0-19.2-12.8-32-32-32S230.4 364.8 230.4 384z" p-id="17718" fill="#707070"></path><path d="M390.4 384l0 384c0 19.2 12.8 32 32 32s32-12.8 32-32L454.4 384c0-19.2-12.8-32-32-32S390.4 364.8 390.4 384z" p-id="17719" fill="#707070"></path><path d="M569.6 384l0 384c0 19.2 12.8 32 32 32s32-12.8 32-32L633.6 384c0-19.2-12.8-32-32-32S569.6 364.8 569.6 384z" p-id="17720" fill="#707070"></path><path d="M736 384l0 384c0 19.2 12.8 32 32 32s32-12.8 32-32L800 384c0-19.2-12.8-32-32-32S736 364.8 736 384z" p-id="17721" fill="#707070"></path></svg>
|
</a-tree>
|
</a-spin>
|
<a-drawer
|
title="结点拖拽规则"
|
placement="right"
|
:closable="true"
|
:visible="dragRugulationVisable"
|
:after-visible-change="afterVisibleChange"
|
@close="closeDragRegulation"
|
:width="500"
|
>
|
<a-descriptions title="限制" :column="1">
|
<a-descriptions-item>
|
1. 只可在编辑状态下才能拖拽树结点,改变树结构。
|
</a-descriptions-item>
|
<a-descriptions-item>
|
2. 不可改变根结点(部门管理)的位置。
|
</a-descriptions-item>
|
<a-descriptions-item>
|
3. 具有继承关系的结点(如父子结点,子孙结点)调换位置只可以互换其数据。
|
</a-descriptions-item>
|
</a-descriptions>
|
<a-descriptions title="两个结点" :column="1">
|
<a-descriptions-item>
|
1.被拖拽结点
|
</a-descriptions-item>
|
<a-descriptions-item >
|
2.目标结点
|
</a-descriptions-item>
|
</a-descriptions>
|
<a-descriptions title="三个目标位置" :column="1">
|
<a-descriptions-item>
|
1.目标结点上方蓝线:表示将被拖拽节点调整为目标结点的兄弟节点,并使其排列到目标结点的上方。
|
</a-descriptions-item>
|
<a-descriptions-item>
|
2.目标结点下方蓝线:表示将被拖拽节点调整为目标结点的兄弟节点,并使其排列到目标结点的下方。
|
</a-descriptions-item>
|
<a-descriptions-item>
|
2.目标结点:表示将被拖拽节点调整为目标结点的最新子节点。
|
</a-descriptions-item>
|
</a-descriptions>
|
</a-drawer>
|
</a-card>
|
</template>
|
<script>
|
import { getAction } from '@/api/manage'
|
import Tooltip from 'ant-design-vue/es/tooltip'
|
import JEllipsis from '@/components/jeecg/JEllipsis'
|
import { deleteAction, postAction } from '../../../../api/manage'
|
export default {
|
name: 'EnterpriseTree',
|
components: {
|
Tooltip,
|
JEllipsis
|
},
|
props: {
|
departInfo:{
|
type:Object,
|
default:{},
|
required:false
|
},
|
versionStatus:{
|
type:String,
|
default:'',
|
required:false
|
}
|
},
|
data() {
|
return {
|
parentId:'',
|
userId:'',
|
enterpriseList:[],
|
searchInput: '',
|
cardLoading: false,
|
loading: false,
|
treeDataSource: [],
|
selectedKeys: [],
|
expandedKeys: [],
|
url: {
|
getEnterpriseId: '/sys/user/getEnterpriseId',
|
loadTree: '/base/depart/departTree',
|
getUsableEnterpriseList:'/base/enterprise/getUsableList',
|
getEnterpriseList:"/base/enterprise/mapList",
|
dropAndChangeNode: '/base/depart/dropAndChangeNode',
|
checkPositionInfo: '/base/depart/checkPositionInfo',
|
|
},
|
searchValue: '',
|
dataList: [],
|
autoExpandParent: true,
|
checkStrictly: true,
|
allTreeKeys: [],
|
currSelected: {},
|
hiding: false,
|
dragRugulationVisable:false
|
|
}
|
|
},
|
created() {
|
this.cardLoading=true;
|
this.getEnterpriseList();
|
},
|
methods: {
|
afterVisibleChange(val) {
|
console.log('visible', val);
|
},
|
showDragRegulation(){
|
this.dragRugulationVisable=true;
|
},
|
closeDragRegulation(){
|
this.dragRugulationVisable=false;
|
},
|
getCurrSelectedTitle() {
|
return !this.currSelected.title ? '' : this.currSelected.title
|
},
|
onClearSelected() {
|
this.hiding = true;
|
this.currSelected = {};
|
this.selectedKeys = [];
|
},
|
onSelect(selectedKeys, e) {
|
this.selectedKeys = selectedKeys;
|
let record = e.node.dataRef;
|
this.currSelected = Object.assign({}, record);
|
this.parentId = selectedKeys[0];
|
},
|
onExpand(expandedKeys) {
|
this.expandedKeys = expandedKeys
|
this.autoExpandParent = false
|
},
|
queryTreeData(enterpriseId,version) {
|
this.loading = true
|
this.cardLoading = true
|
getAction(this.url.loadTree,{enterpriseId:enterpriseId,version:version}).then((res) => {
|
if (res.success) {
|
this.dataList = [];
|
this.allTreeKeys = [];
|
this.generateList(res.result);
|
this.expandAll();
|
this.selectedKeys=[res.result[0].key];
|
this.currSelected = res.result[0];
|
this.parentId = res.result[0].key
|
} else {
|
this.$message.warn(res.message)
|
}
|
}).finally(res=>{
|
this.loading = false;
|
this.cardLoading = false;
|
});
|
},
|
getEnterpriseList(){
|
getAction(this.url.getEnterpriseList).then(res=>{
|
if(res.success){
|
this.enterpriseList = res.result
|
}
|
else{
|
this.$message.error(res.message);
|
}
|
})
|
},
|
getParentKey(key, tree) {
|
let parentKey
|
for (let i = 0; i < tree.length; i++) {
|
const node = tree[i]
|
if (node.children) {
|
if (node.children.some(item => item.key === key)) {
|
parentKey = node.key
|
} else if (
|
this.getParentKey(key, node.children)) {
|
parentKey = this.getParentKey(key, node.children)
|
}
|
}
|
}
|
return parentKey
|
},
|
|
generateList(data) {
|
const list = data;
|
for (let i = 0; i < list.length; i++) {
|
const key = list[i].key
|
list[i].type = 'total';
|
list[i].scopedSlots = {
|
switcherIcon:"total"
|
};
|
this.allTreeKeys.push(key);
|
if (list[i].children) {
|
this.generateList(list[i].children)
|
}
|
}
|
this.treeDataSource=list
|
},
|
expandAll() {
|
this.expandedKeys = this.allTreeKeys
|
},
|
closeAll() {
|
this.expandedKeys = ['-1']
|
},
|
refreshTree() {
|
this.parentId=''
|
this.queryTreeData(this.departInfo.enterpriseId,this.departInfo.version)
|
},
|
reloadUi(){
|
this.loading = true
|
this.cardLoading = true
|
getAction(this.url.loadTree,{
|
enterpriseId:this.departInfo.enterpriseId,
|
version:this.departInfo.version
|
}).then((res) => {
|
if (res.success) {
|
this.dataList = [];
|
this.allTreeKeys = [];
|
this.treeDataSource = res.result
|
this.generateList(res.result);
|
this.expandAll();
|
} else {
|
this.$message.warn(res.message)
|
}
|
}).finally(res=>{
|
this.loading = false;
|
this.cardLoading = false;
|
});
|
},
|
onDrop(info){
|
console.log(info);
|
const {dragNode,dropPosition,dropToGap,node} = info
|
console.log (dragNode.dataRef.key+"===="+node.dataRef.key+"===="+dropPosition)
|
let dropedKey = dragNode.dataRef.key;
|
let changeKey = node.dataRef.key;
|
let dropedTitle = dragNode.dataRef.title;
|
let changeTitle = node.dataRef.title;
|
let dropedParentId = dragNode.dataRef.parentId;
|
let changeParentId = node.dataRef.parentId;
|
var newPosPre = node.pos.substr(0,node.pos.lastIndexOf("-"));
|
var newPos =node.pos.split('-');
|
var realPose = Number(newPos[newPos.length-1]);
|
let posStatus = dropPosition-realPose;
|
var oldPosePre = dragNode.pos.substr(0,dragNode.pos.lastIndexOf("-"));
|
var oldPos = dragNode.pos.split('-');
|
var orgPos = Number(oldPos[oldPos.length-1]);
|
console.log(realPose+"=="+orgPos)
|
var params={
|
dropedKey:dropedKey,
|
changeKey:changeKey,
|
dropedParentId:dropedParentId,
|
changeParentId:changeParentId,
|
dropedTitle:dropedTitle,
|
changeTitle:changeTitle,
|
dropPosition:dropPosition,
|
status:''
|
}
|
if(this.versionStatus!='1'&&this.versionStatus!='0'){
|
this.$message.error("只能在编辑或新增状态下才可以调节树的结构哦!");
|
}else if(dropedKey==this.enterpriseId||changeKey==this.enterpriseId){
|
this.$message.error("不可变动根节点哦!");
|
}else if(!dropToGap){
|
postAction(this.url.checkPositionInfo,params).then(res=>{
|
if(res.success){
|
var that = this;
|
this.$confirm({
|
title:"确认调整",
|
content:res.result?"("+dropedTitle+")和"+"("+changeTitle+")只能交换其数据,确认交换吗?":"确认将("+dropedTitle+")设置为("+changeTitle+")的最新子节点吗",
|
onOk: function () {
|
that.cardLoading=true;
|
if(res.result){
|
params.status='3';
|
}else{
|
params.status='4';
|
}
|
that.changePosition(params);
|
}
|
});
|
}
|
})
|
}
|
// else if((posStatus==1||posStatus==-1)&&dropedKey==changeParentId){
|
// this.$message.warning("不可以将父公司拖至子公司列");
|
// }
|
else if((posStatus==1&&oldPosePre==newPosPre&&realPose+1==orgPos)){
|
this.$message.warning("调整前后无区别,请重新调整");
|
}
|
else if(posStatus==1){
|
var that = this;
|
this.$confirm({
|
title: "确认调整",
|
content:"确认将("+dropedTitle+")调整到("+changeTitle+")后面吗",
|
onOk: function () {
|
that.cardLoading=true;
|
params.status='2';
|
that.changePosition(params);
|
}
|
});
|
|
}else if(posStatus==-1&&oldPosePre==newPosPre&&realPose==orgPos+1){
|
this.$message.warning("调整前后无区别,请重新调整");
|
}else if(posStatus==-1){
|
var that = this;
|
this.$confirm({
|
title: "确认调整",
|
content:"确认将("+dropedTitle+")调整到("+changeTitle+")前面吗",
|
onOk: function () {
|
that.cardLoading=true;
|
params.status='5';
|
that.changePosition(params);
|
}
|
});
|
}
|
|
},
|
changePosition(params){
|
postAction(this.url.dropAndChangeNode,params).then(res=>{
|
if(res.success){
|
this.parentId='';
|
this.queryTreeData(this.enterpriseId,this.version);
|
this.$message.success("树结构调整成功,已经刷新树结构");
|
}
|
else{
|
this.$message.error("树结构调整出现异常");
|
}
|
}).finally(res=>{
|
this.cardLoading=false;
|
});
|
},
|
getVersionStatusDetail(data){
|
if(data=='0'){
|
return '新建'
|
}else if(data=='1'){
|
return '编辑'
|
}else if(data=='2'){
|
return '生效'
|
}else if(data=='3'){
|
return '失效'
|
}else if(data=='4'){
|
return '待生效'
|
}
|
},
|
getEnterpriseOptionStyle(data){
|
if(data=='0'||data=='1'){
|
return {
|
color:"darkOrange !important",
|
}
|
}else if(data=='2'){
|
return {
|
color:"green !important",
|
}
|
}else if(data=='3'){
|
return {
|
color:"red !important",
|
}
|
}else{
|
return {
|
color:"skyblue !important",
|
}
|
}
|
}
|
},
|
// 监听
|
watch: {
|
parentId:{
|
handler(val) {
|
this.$emit('getParentEnterprise',val);
|
}
|
},
|
departInfo:{
|
deep:true,
|
handler(val){
|
this.parentId=''
|
this.queryTreeData(val.enterpriseId,val.version)
|
|
}
|
},
|
'departInfo.enterpriseId'(newval,oldval){
|
for(var i=0;i<this.enterpriseList.length;i++ ){
|
if(this.enterpriseList[i].id==newval&&this.enterpriseList[i].versionStatus=='2'){
|
this.$emit('getUpdatePermission',true);
|
}else if(this.enterpriseList[i].id==newval){
|
this.$emit('getUpdatePermission',false)
|
}
|
}
|
}
|
}
|
}
|
</script>
|
|
<style>
|
.replaceSearch {
|
color: #00090f;
|
font-weight: bold;
|
background-color: rgb(204, 204, 204);
|
}
|
/* .ant-select-disabled {
|
color: rgba(241, 16, 16, 0.25);
|
}
|
.ant-select-disabled .ant-select-selection {
|
background: #a76b6b;
|
} */
|
.ant-card-body .table-operator {
|
margin: 15px;
|
}
|
|
.anty-form-btn {
|
width: 100%;
|
text-align: center;
|
}
|
|
.anty-form-btn button {
|
margin: 0 5px;
|
}
|
|
.anty-node-layout .ant-layout-header {
|
padding-right: 0;
|
}
|
|
.header {
|
padding: 0 8px;
|
}
|
|
.header button {
|
margin: 0 3px;
|
}
|
|
.ant-modal-cust-warp {
|
height: 100%;
|
}
|
|
.ant-modal-cust-warp .ant-modal-body {
|
height: calc(100% - 110px) !important;
|
overflow-y: auto;
|
}
|
|
.ant-modal-cust-warp .ant-modal-content {
|
height: 90% !important;
|
overflow-y: hidden;
|
}
|
|
#app .desktop {
|
height: auto !important;
|
}
|
|
/** Button按钮间距 */
|
.ant-btn {
|
margin-left: 3px;
|
}
|
.ant-alert {
|
padding: 5px 15px 5px 37px;
|
}
|
.drawer-bootom-button {
|
position: absolute;
|
top: 1px;
|
/* padding: 10px 16px; */
|
text-align: left;
|
right: 0;
|
background: #fff;
|
border-radius: 0 0 2px 2px;
|
|
}
|
</style>
|