提交 d0b38113 作者: wk

组织切换

父级 c2a3aedb
......@@ -779,7 +779,8 @@
this.$http.get({
url: "/api/v1/project/project_list",
data: {
is_all: 1
is_all: 1,
org_no: uni.getStorageInfoSync("org_no")
},
header: {
"access_token": this.getToken()
......
......@@ -62,7 +62,8 @@
loadProject(access_token) {
Api.getProjectList({
data: {
is_all: 1
is_all: 1,
org_no: uni.getStorageInfoSync("org_no")
}
}).then((result) => {
console.log("项目列表:", result);
......
<template>
<view class="content">
<titleBar title="切换组织"></titleBar>
<view class="org-content">
<view class="org-list">
<view class="org-item" v-for="(tree,index) in trees" :key="index">
<view class="org">
<image
:src="tree.isOpen?'../../../static/icon_up_arrow.png':'../../../static/icon_drop_arrow.png'"
class="image" @click="toNextLevel(tree,index)">
</image>
<view class="name" @click="toNextLevel(tree,index)">{{tree.name}}</view>
<view class=" enter" @click="itemClick(tree)">进入</view>
</view>
<view v-if="tree.isOpen" style="margin-top: 20rpx;">
<view class="org-item" v-for="(oneLevel,oneIndex) in tree.children_list" :key="oneIndex">
<view class="org">
<image
:src="oneLevel.isOpen?'../../../static/icon_up_arrow.png':'../../../static/icon_drop_arrow.png'"
class="image" @click="toNextChild(index,oneLevel,oneIndex)"></image>
<view class="name" @click="toNextChild(index,oneLevel,oneIndex)">{{oneLevel.name}}
</view>
<view class="enter" @click="itemClick(oneLevel)">进入</view>
</view>
<view v-if="oneLevel.isOpen" style="margin-top: 20rpx;">
<view class="org-item" v-for="(twoLevel,twoIndex) in oneLevel.children_list"
:key="twoIndex">
<view class="org">
<view class="name">{{twoLevel.name}}</view>
<view class="enter" @click="itemClick(oneLevel)">进入</view>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
</template>
......@@ -9,7 +44,7 @@
export default {
data() {
return {
trees: []
}
},
onLoad() {
......@@ -19,8 +54,89 @@
getOrgTree() {
Api.getOrgTree().then((result) => {
console.log("组织树", result);
if (result.code == 0) {
this.trees = result.data
}
})
}
},
toNextLevel(item, index) {
let children = item.children_list
if (item.isOpen) {
item.isOpen = false
} else {
if (children && children.length > 0) {
item.isOpen = true
} else {
item.isOpen = false
}
}
this.$set(this.trees, index, item)
},
toNextChild(index, item, oneIndex) {
let children = item.children_list
if (item.isOpen) {
item.isOpen = false
} else {
if (children && children.length > 0) {
item.isOpen = true
} else {
item.isOpen = false
}
}
this.$set(this.trees[index].children_list, oneIndex, item)
},
itemClick: function(item) {
let that = this
uni.showModal({
title: '提示',
content: '确定切换到该组织?',
showCancel: true,
confirmText: "切换",
confirmColor: '#1890FF',
success: res => {
if (res.confirm) {
that.switchCompany(item)
}
}
})
},
switchCompany: function(company) {
this.$http.consolePut({
url: "/api/v1/user/user/switch_company",
data: {
company_id: company.company_id
},
header: {
access_token: this.getToken()
}
}).then((res) => {
let result = res.data
if (result.code == 0) {
uni.setStorageSync("token", result.data.access_token)
uni.setStorageSync("refresh_token", result.data.refresh_token)
uni.setStorageSync("company_id", company.company_id)
uni.setStorageSync("org_no", company.org_no)
this.currentCompany = company
uni.setStorageSync("user_info", result.data)
this.getUserInfo()
} else {
this.$toast.showToast(result.msg)
}
})
},
getUserInfo() {
Api.getUserInfo().then((result) => {
if (result.code == 0) {
getApp().globalData.userInfo = result.data
uni.navigateBack({
delta: 1
})
} else {
this.$toast.showToast(result.msg)
}
})
},
}
}
</script>
......@@ -29,5 +145,46 @@
.content {
display: flex;
flex-direction: column;
.org-content {
display: flex;
flex-direction: column;
margin: 30rpx;
}
.org-item {
padding: 30rpx 0 30rpx 30rpx;
display: flex;
flex-direction: column;
border-radius: 30rpx;
background-color: #fff;
}
.org {
display: flex;
flex-direction: row;
align-items: center;
image {
width: 48rpx;
height: 24rpx;
}
.name {
font-size: 28rpx;
color: #333;
margin-left: 20rpx;
flex: 1;
font-weight: 500;
}
.enter {
font-size: 28rpx;
margin-right: 30rpx;
color: #3B73FE;
font-weight: 600;
}
}
}
</style>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
Please register or to comment