<template>
|
<a-card
|
:loading="cardLoading"
|
:bordered="false"
|
title="工厂模型"
|
style="height: 100%;"
|
>
|
<div
|
class="table-operator"
|
style="margin-top: 5px"
|
>
|
</div>
|
<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="factoryInfo.enterpriseId"
|
>
|
<a-select-option v-for="item of this.enterpriseList" :value="item.id" :key="item.id" >
|
<span id="enterprisestyle" :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
|
:showIcon="true"
|
selectable
|
showLine
|
: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="1675649233812" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="10262"><path d="M839.91992188 863.47460938c-19.42382813 0-35.15625-15.73242188-35.15625001-35.15625001V584.94921875c0-19.42382813-15.73242188-35.15625-35.15625-35.15625H556.6484375v272.19726563c0 19.42382813-15.73242188 35.15625-35.15625 35.15624999s-35.15625-15.73242188-35.15625-35.15625v-533.49609375c0-19.42382813-15.73242188-35.15625-35.15625-35.15625H254.04101562c-19.42382813 0-35.15625 15.73242188-35.15624999 35.15625v533.40820313c0 19.42382813-15.73242188 35.15625-35.15625 35.15625s-35.15625-15.73242188-35.15625-35.15625V288.49414062c0-58.18359375 47.28515625-105.46875 105.46874999-105.46874999h197.13867188c58.18359375 0 105.46875 47.28515625 105.46875 105.46875V479.48046875h212.95898438c58.18359375 0 105.46875 47.28515625 105.46874999 105.46875v243.36914063c0 19.42382813-15.73242188 35.15625-35.15625 35.15624999z" p-id="10263" fill="#8a8a8a"></path><path d="M382.53710937 414.96875h-59.94140624c-9.66796875 0-17.578125-7.91015625-17.578125-17.578125v-59.94140625c0-9.66796875 7.91015625-17.578125 17.578125-17.578125h59.94140625c9.66796875 0 17.578125 7.91015625 17.578125 17.578125v59.94140625c0 9.66796875-7.91015625 17.578125-17.578125 17.578125z m17.57812501 140.625v-59.94140625c0-9.66796875-7.91015625-17.578125-17.578125-17.578125h-59.94140625c-9.66796875 0-17.578125 7.91015625-17.578125 17.578125v59.94140625c0 9.66796875 7.91015625 17.578125 17.578125 17.578125h59.94140625c9.66796875 0 17.578125-7.91015625 17.578125-17.578125zM875.42773438 876.74609375H149.1875c-16.96289063 0-30.76171875-13.79882813-30.76171875-30.76171875s13.79882813-30.76171875 30.76171875-30.76171875h726.24023438c16.96289063 0 30.76171875 13.79882813 30.76171875 30.76171875s-13.79882813 30.76171875-30.76171875 30.76171875zM732.4296875 762.13671875H629.86132813c-16.96289063 0-30.76171875-13.79882813-30.76171876-30.76171875s13.79882813-30.76171875 30.76171875-30.76171875h102.48046876c16.96289063 0 30.76171875 13.79882813 30.76171875 30.76171875s-13.7109375 30.76171875-30.67382813 30.76171875z m0-105.46875H629.86132813c-16.96289063 0-30.76171875-13.79882813-30.76171876-30.76171875s13.79882813-30.76171875 30.76171875-30.76171875h102.48046876c16.96289063 0 30.76171875 13.79882813 30.76171875 30.76171875s-13.7109375 30.76171875-30.67382813 30.76171875z" p-id="10264" fill="#8a8a8a"></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: 'FactoryLeft',
|
components: {
|
Tooltip,
|
JEllipsis
|
},
|
props: {
|
factoryInfo:{
|
type:Object,
|
default:{},
|
required:false
|
},
|
versionStatus:{
|
type:String,
|
default:'',
|
required:false
|
}
|
},
|
data() {
|
return {
|
userId: '',
|
enterpriseId:'',
|
parentId:'',
|
enterpriseList:[],
|
searchInput: '',
|
cardLoading: false,
|
loading: false,
|
treeDataSource: [],
|
selectedKeys: [],
|
expandedKeys: [],
|
url: {
|
getUsableEnterpriseList:'/base/enterprise/getUsableList',
|
getEnterpriseList:"/base/enterprise/mapList",
|
loadTree: '/base/factoryModel/loadTree',
|
getTreeByEid: '/base/factoryModel/loadTreeByEid',
|
getInitVersion: '/base/factoryModel/getInitVersion',
|
dropAndChangeNode: '/base/factoryModel/dropAndChangeNode',
|
checkPositionInfo: '/base/factoryModel/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];
|
},
|
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
|
},
|
onExpand(expandedKeys) {
|
this.expandedKeys = expandedKeys
|
this.autoExpandParent = false
|
},
|
expandAll() {
|
this.expandedKeys = this.allTreeKeys
|
},
|
closeAll() {
|
this.expandedKeys = ['-1']
|
},
|
refreshTree() {
|
this.parentId=''
|
this.queryTreeData(this.factoryInfo.enterpriseId,this.factoryInfo.version)
|
},
|
reloadUi(){
|
this.loading = true
|
this.cardLoading = true
|
getAction(this.url.loadTree,{
|
enterpriseId:this.factoryInfo.enterpriseId,
|
version:this.factoryInfo.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.factoryInfo.enterpriseId,this.factoryInfo.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);
|
}
|
},
|
factoryInfo:{
|
deep:true,
|
handler(val){
|
this.parentId=''
|
this.queryTreeData(val.enterpriseId,val.version)
|
}
|
},
|
'factoryInfo.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;
|
} */
|
/*隐藏树的默认icon*/
|
/* .ant-tree-switcher-noop {
|
display: none !important;
|
} */
|
/*隐藏树的默认竖线*/
|
/* .ant-tree.ant-tree-show-line li:not(:last-child):before {
|
border-left: 2px;
|
} */
|
|
.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>
|