zhgdyun/src/components/userChange.vue

384 lines
11 KiB
Vue
Raw Normal View History

2024-03-21 19:30:54 +08:00
<template>
<div class="header-btn">
<el-popover
placement="bottom"
2024-04-11 19:15:19 +08:00
trigger="hover"
2024-04-10 16:18:11 +08:00
popper-class="user-group-popover"
:visible-arrow="false"
2024-03-21 19:30:54 +08:00
v-model="visible"
>
<div class="changeBox">
2024-04-03 18:19:28 +08:00
<div class="title-content">
2024-04-10 16:18:11 +08:00
<span>{{ isUserList ? "切换用户" : "所选组织架构" }}</span>
<img
src="@/assets/images/headerImg/icon5-active.png"
v-if="!isUserList"
2024-04-11 19:15:19 +08:00
@click="showGroup"
2024-04-10 16:18:11 +08:00
/>
<img
src="@/assets/images/headerImg/icon6.png"
v-if="!isUserList"
@click="isUserList = true"
/>
<img
src="@/assets/images/headerImg/icon5.png"
v-if="isUserList"
2024-04-11 19:15:19 +08:00
@click="showGroup"
2024-04-10 16:18:11 +08:00
/>
<img
src="@/assets/images/headerImg/icon6-active.png"
v-if="isUserList"
@click="isUserList = true"
/>
<!-- <i
2024-04-03 18:19:28 +08:00
class="el-icon-arrow-left"
style="cursor: pointer;"
@click="isUserList = true"
></i>
<i
class="el-icon-arrow-right"
style="cursor: pointer;"
@click="isUserList = false"
2024-04-10 16:18:11 +08:00
></i> -->
2024-04-03 18:19:28 +08:00
</div>
2024-04-20 19:07:58 +08:00
<div class="content-list" :style="{height: groupListData.length > 4?'300px':'auto'}" v-if="isUserList">
<vue-scroll style="height: 100%;">
2024-04-03 18:19:28 +08:00
<div
class="content-list-item"
v-for="(item, index) in groupListData"
:key="index"
@click="selectGroup(item)"
>
2024-04-10 16:18:11 +08:00
<!-- <i class="el-icon-trophy-1"></i> -->
<img src="@/assets/images/headerImg/icon3.png" />
2024-04-03 18:19:28 +08:00
<span>{{ item.companyName }}</span>
<i class="el-icon-arrow-right"></i>
2024-03-21 19:30:54 +08:00
</div>
2024-04-20 19:07:58 +08:00
</vue-scroll>
2024-04-11 19:15:19 +08:00
<!-- <div class="content-list-item" @click="selectGroup()">
2024-04-10 16:18:11 +08:00
<img src="@/assets/images/headerImg/icon4.png" />
<span>{{ $store.state.userInfo.account }}</span>
<div>个人租户</div>
<i class="el-icon-arrow-right"></i>
2024-04-11 19:15:19 +08:00
</div> -->
2024-04-03 18:19:28 +08:00
</div>
<div class="tree-group" v-else>
<div class="select-list">
<el-input
placeholder="输入关键字进行查找"
v-model="filterText"
style="width: 98%;"
suffix-icon="el-icon-search"
size="medium"
>
</el-input>
<el-tree
:data="selectedGroupData"
2024-04-20 19:07:58 +08:00
:default-expanded-keys="expandKey"
:default-expand-all="false"
2024-04-03 18:19:28 +08:00
node-key="sn"
ref="tree"
2024-04-11 19:15:19 +08:00
:props="selectTreeProps"
2024-04-03 18:19:28 +08:00
:filter-node-method="filterNode"
:highlight-current="true"
2024-04-11 19:15:19 +08:00
:check-on-click-node="false"
2024-04-03 18:19:28 +08:00
style="margin:10px 5px;"
2024-04-11 19:15:19 +08:00
>
<span class="custom-tree-node" slot-scope="{ node, data }">
<span
style="
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
display: inline-block;
"
@click="treeClick(data)"
:class="
data.projectSn
? 'projectStyle'
: 'companyStyle'
"
:title="node.label"
>{{ node.label }}</span
>
</span>
</el-tree>
2024-03-30 11:51:22 +08:00
</div>
2024-04-03 18:19:28 +08:00
</div>
2024-03-21 19:30:54 +08:00
</div>
<!-- 点击内容 -->
<div slot="reference" class="click-content">
2024-04-10 16:18:11 +08:00
<!-- <i class="el-icon-trophy-1"></i> -->
<img src="@/assets/images/headerImg/icon1.png" />
<span
v-if="
$store.state.currentProDetail && $store.state.currentProDetail.name
"
:title="$store.state.currentProDetail.name"
>{{ $store.state.currentProDetail.name }}</span
>
<span v-else :title="$store.state.userInfo.account">{{
$store.state.userInfo.account
}}</span>
2024-03-21 19:30:54 +08:00
<i class="el-icon-arrow-down"></i>
</div>
</el-popover>
</div>
</template>
<script>
2024-04-20 19:07:58 +08:00
import { getGroupListApi } from "@/assets/js/api/loginSign.js";
2024-03-21 19:30:54 +08:00
export default {
data() {
return {
2024-03-30 11:51:22 +08:00
visible: false,
isUserList: true,
filterText: "",
selectTreeProps: {
2024-04-03 18:19:28 +08:00
children: "list",
label: "name",
2024-03-30 11:51:22 +08:00
},
2024-04-03 18:19:28 +08:00
groupListData: [],
selectedGroupData: [],
2024-04-10 16:18:11 +08:00
selectedProjectSn: "",
2024-04-20 19:07:58 +08:00
expandKey: []
2024-04-03 18:19:28 +08:00
};
2024-03-21 19:30:54 +08:00
},
created() {
2024-04-20 19:07:58 +08:00
console.log(this.$store.state.groupTreeList,'测试进入123456')
2024-04-03 18:19:28 +08:00
this.getGroupTreeData();
2024-04-13 22:51:12 +08:00
if(this.$store.state.projectSn){
this.selectedProjectSn = this.$store.state.projectSn
2024-04-20 19:07:58 +08:00
this.expandKey = [this.selectedProjectSn]
2024-04-13 22:51:12 +08:00
}
2024-03-21 19:30:54 +08:00
},
2024-04-03 18:19:28 +08:00
mounted() {},
2024-03-21 19:30:54 +08:00
methods: {
2024-04-11 19:15:19 +08:00
// 处理组织架构树形数据
filterTreeData(tree){
tree.forEach(node => {
if(!node.projectSn){
node.disabled = true;
}
if (node.list && node.list.length) {
this.filterTreeData(node.list);
}
});
},
// 展示组织架构内容
showGroup(){
this.isUserList = false;
this.setTreeActive();
},
2024-04-03 18:19:28 +08:00
// 选中组织中的项目级
selectProject(obj) {
2024-04-10 16:18:11 +08:00
console.log(obj, "111222333");
2024-04-11 19:15:19 +08:00
if (!obj) return;
2024-04-03 18:19:28 +08:00
if (obj.list && obj.list.length > 0) {
obj.list.map((item) => {
this.selectProject(item);
});
} else {
2024-04-13 22:51:12 +08:00
if (!this.selectedProjectSn || !this.$store.state.currentProDetail) {
2024-04-10 16:18:11 +08:00
// 加判断是为了在循环中只选中第一个
2024-04-03 18:19:28 +08:00
this.selectedProjectSn = obj.sn;
2024-04-20 19:07:58 +08:00
this.expandKey = [this.selectedProjectSn]
2024-04-03 18:19:28 +08:00
// 修改全局projectSn
this.$store.commit("setProjectSn", obj.sn);
2024-04-08 19:12:10 +08:00
this.$store.commit("setProDetail", obj);
2024-04-03 18:19:28 +08:00
}
2024-04-12 21:02:09 +08:00
this.setTreeActive();
2024-04-03 18:19:28 +08:00
}
},
2024-04-11 19:15:19 +08:00
// 设置树形的选中项目样式
setTreeActive(){
this.$nextTick(() => {
2024-04-13 22:51:12 +08:00
let activeSn = this.$store.state.projectSn || this.selectedProjectSn
2024-04-11 19:15:19 +08:00
if(activeSn){
this.$refs.tree.setCurrentKey(activeSn);
}
})
},
2024-04-03 18:19:28 +08:00
// 选中组织
selectGroup(item) {
2024-04-10 16:18:11 +08:00
if (item) {
2024-04-11 19:15:19 +08:00
this.selectedGroupData = [item]
2024-04-12 21:32:41 +08:00
this.$store.commit("setSelectedGroupSn", item.sn); // 存储选中的组织Sn
2024-04-11 19:15:19 +08:00
this.filterTreeData(this.selectedGroupData);
console.log(this.selectedGroupData)
2024-04-10 16:18:11 +08:00
} else {
this.selectedGroupData = [];
this.$store.commit("setProjectSn", "");
this.$store.commit("setProDetail", null);
}
2024-04-03 18:19:28 +08:00
this.isUserList = false;
this.$nextTick(() => {
this.selectProject(item);
});
},
// 获取组织树数据
getGroupTreeData() {
this.groupListData = this.$store.state.groupTreeList;
2024-04-20 19:07:58 +08:00
console.log(this.groupListData,'我的组织机构123456')
2024-04-10 16:18:11 +08:00
if (!this.groupListData) return;
2024-04-03 18:19:28 +08:00
this.isUserList = false;
2024-04-20 19:07:58 +08:00
let requestData = {
userId: this.$store.state.userInfo.userId,
headquartersSn: this.$store.state.userInfo.headquartersSn
2024-04-10 16:18:11 +08:00
}
2024-04-20 19:07:58 +08:00
getGroupListApi(requestData).then(res => {
console.log(res,'我的组织机构')
if(res && res.result){
this.selectedGroupData = res.result
this.filterTreeData(this.selectedGroupData);
this.$nextTick(() => {
// 默认选中项目
this.selectProject(this.selectedGroupData[0]);
});
}
})
// 以前的版本处理方法
// let findItem = this.groupListData.find((item) => {
// return item.sn == this.$store.state.selectedGroupSn;
// });
// if (findItem) {
// this.$store.commit("setSelectedGroupSn", findItem.sn); // 存储选中的组织Sn
// this.selectedGroupData = [findItem]
// this.filterTreeData(this.selectedGroupData);
// this.$nextTick(() => {
// this.selectProject(findItem);
// });
// }
2024-04-03 18:19:28 +08:00
},
2024-03-30 11:51:22 +08:00
// 树形控件点击
treeClick(data) {
console.log(data);
2024-04-10 16:18:11 +08:00
if (data.projectSn) {
2024-04-03 18:19:28 +08:00
this.selectedProjectSn = data.projectSn;
// 修改全局projectSn
this.$store.commit("setProjectSn", data.projectSn);
2024-04-10 16:18:11 +08:00
this.$store.commit("setProDetail", data);
2024-04-03 18:19:28 +08:00
// 收起popover
this.visible = false;
}
2024-04-13 16:49:55 +08:00
this.$router.push("/workSpace")
2024-03-30 11:51:22 +08:00
},
filterNode(value, data) {
if (!value) return true;
return data.name.indexOf(value) !== -1;
},
},
watch: {
filterText(val) {
this.$refs.tree.filter(val);
},
},
2024-04-03 18:19:28 +08:00
};
2024-03-21 19:30:54 +08:00
</script>
<style lang="less" scoped>
2024-04-03 18:19:28 +08:00
.flexStyle() {
display: flex;
align-items: center;
2024-03-21 19:30:54 +08:00
}
.changeBox {
padding: 0px 10px;
2024-04-03 18:19:28 +08:00
.title-content {
2024-03-21 19:30:54 +08:00
.flexStyle();
2024-04-03 18:19:28 +08:00
> span {
2024-03-21 19:30:54 +08:00
font-size: 16px;
font-family: PingFang SC, PingFang SC;
font-weight: 400;
color: #000000;
margin-right: auto;
}
2024-04-10 16:18:11 +08:00
img {
width: 15px;
height: 15px;
cursor: pointer;
margin-left: 5px;
}
2024-03-21 19:30:54 +08:00
}
2024-04-03 18:19:28 +08:00
.content-list {
2024-03-21 19:30:54 +08:00
margin-top: 15px;
2024-04-03 18:19:28 +08:00
&-item {
2024-03-21 19:30:54 +08:00
.flexStyle();
padding: 10px 15px;
2024-04-03 18:19:28 +08:00
border: 1px solid #dadbdb;
2024-03-21 19:30:54 +08:00
border-radius: 5px;
cursor: pointer;
2024-04-10 16:18:11 +08:00
img {
width: 30px;
height: 30px;
}
// >div{
// border: 1px solid #7299F8;
// border-radius: 5px;
// background-color: #E3F6FF;
// padding: 5px 15px;
// color: #5A88F7;
// }
2024-04-03 18:19:28 +08:00
> span:nth-child(2) {
2024-03-21 19:30:54 +08:00
margin: 2px 10px 0px 10px;
}
2024-04-10 16:18:11 +08:00
> div {
2024-04-03 18:19:28 +08:00
padding: 3px 10px;
color: #79acfa;
background-color: #e4f5ff;
border: 1px solid #99c3fb;
2024-03-21 19:30:54 +08:00
border-radius: 5px;
2024-04-10 16:18:11 +08:00
margin-top: 2px;
2024-03-21 19:30:54 +08:00
font-size: 10px;
}
2024-04-03 18:19:28 +08:00
/deep/.el-icon-arrow-right {
2024-03-21 19:30:54 +08:00
margin-left: auto;
}
}
2024-04-03 18:19:28 +08:00
&-item:not(:last-child) {
2024-03-21 19:30:54 +08:00
margin-bottom: 10px;
}
}
2024-04-03 18:19:28 +08:00
.tree-group {
2024-03-30 11:51:22 +08:00
margin-top: 15px;
background-color: #fff;
.select-list {
2024-04-11 19:15:19 +08:00
.custom-tree-node {
width: 100%;
.flexStyle();
.projectStyle{
font-family: Source Han Sans CN, Source Han Sans CN;
font-weight: 400;
color: #272D45;
}
.companyStyle{
font-family: Source Han Sans CN, Source Han Sans CN;
font-weight: 400;
color: #A2A4AF;
}
2024-03-30 11:51:22 +08:00
}
}
2024-03-21 19:30:54 +08:00
}
2024-04-11 19:15:19 +08:00
}
2024-04-03 18:19:28 +08:00
.click-content {
2024-03-21 19:30:54 +08:00
cursor: pointer;
.flexStyle();
2024-04-10 16:18:11 +08:00
img {
width: 20px;
height: 20px;
}
2024-04-03 18:19:28 +08:00
> span {
2024-04-08 19:12:10 +08:00
display: inline-block;
2024-04-10 16:18:11 +08:00
max-width: 77px;
2024-04-08 19:12:10 +08:00
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
2024-03-21 19:30:54 +08:00
margin: 0px 10px;
}
}
</style>
<style>
2024-04-10 16:18:11 +08:00
.user-group-popover {
min-width: 300px;
2024-03-21 19:30:54 +08:00
box-sizing: content-box !important;
}
2024-04-03 18:19:28 +08:00
</style>