| | |
| | | import { loginOut, getDistrictInfo } from "@/api/login";
|
| | | import { Session, getUserInfo} from '@/util/storage';
|
| | | import Cookies from "js-cookie";
|
| | | import {getAreaWithUserIfo} from "@/api/user";
|
| | | export default {
|
| | | name: "Home",
|
| | | data() {
|
| | |
| | | })
|
| | | this.addListener()
|
| | | }
|
| | | this.getAreaUsers(getUserInfo().districtId)
|
| | | },
|
| | | watch: {
|
| | | '$route': function(newRoute) {
|
| | |
| | | const path = closePath && closePath.split('?')[0]
|
| | | this.remove(path, nextRoute)
|
| | | },
|
| | | async getAreaUsers(districtId) {
|
| | | let t = this
|
| | | let res = await getAreaWithUserIfo()
|
| | | if (res.data.code == 100) {
|
| | | if (res.data.data) {
|
| | | t.userTitTree(res.data.data)
|
| | | const areaUsers = t.findNodeById(res.data.data, districtId).children
|
| | | localStorage.removeItem('areaUsers')
|
| | | localStorage.setItem('areaUsers',JSON.stringify(areaUsers))
|
| | | } else {
|
| | | console.log('暂无数据')
|
| | | }
|
| | | } else {
|
| | | this.$message.warning(res.data.msg);
|
| | | }
|
| | | },
|
| | |
|
| | | // 根据id查对象
|
| | | findNodeById(data, value) {
|
| | | for (const node of data) {
|
| | | if (node.id === value) {
|
| | | return node;
|
| | | }
|
| | | if (node.children) {
|
| | | const foundNode = this.findNodeById(node.children, value);
|
| | | if (foundNode) {
|
| | | return foundNode;
|
| | | }
|
| | | }
|
| | | }
|
| | | return null;
|
| | | },
|
| | |
|
| | | // 将树状数据name字段放入users的姓名电话
|
| | | userTitTree(treeData) {
|
| | | for (const node of treeData) {
|
| | | if (node.users) {
|
| | | node.users = node.users.filter(i => i.roleId == 3)
|
| | | node.users = node.users.map((i) => {
|
| | | return {
|
| | | ...i,
|
| | | unittype: node.type,
|
| | | districtId: node.id
|
| | | }
|
| | | })
|
| | | node.name = node.name + '(' + node.users.map(i => i.realName + ' ' + i.phone).join(',') + ')'
|
| | | }
|
| | | if (node.children) {
|
| | | this.userTitTree(node.children)
|
| | | }
|
| | | }
|
| | | return treeData
|
| | | }
|
| | | }
|
| | | };
|
| | | </script>
|