广州矛调粤政易端
xusd
7 days ago d27794814b69d18aeb8ee96a46cae91d5613570c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import React from 'react';
import { useHistory, useLocation } from 'react-router-dom';
import qs from 'qs';
import * as $$ from '../../utils/utility';
import './index.less';
 
export function getCurrentTabKeyByLocation(location) {
  const query = qs.parse(location.search, { ignoreQueryPrefix: true });
  const userInfo = $$.getSessionStorage('customerSystemUser');
  if (location.pathname === '/gzdyh/areaStatistics') return '区域工作统计';
  if (location.pathname === '/gzdyh/workStatistics') {
    if (query.type === '2') return '部门工作统计';
    return userInfo?.trueName ? `${userInfo.trueName}工作统计` : '个人工作统计';
  }
  return '';
}
 
 
export function getCurrentTabKeyByLocation1(location) {
  const query = qs.parse(location.search, { ignoreQueryPrefix: true });
  const userInfo = $$.getSessionStorage('customerSystemUser');
  if (location.pathname === '/gzdyh/areaStatistics') return '区域工作统计';
  if (location.pathname === '/gzdyh/workStatistics') {
    if (query.type === '2') return '部门工作统计';
    return '个人工作统计';
  }
  return '';
}
 
const WorkStatisticsTabs = () => {
  const history = useHistory();
  const location = useLocation();
  const query = qs.parse(location.search, { ignoreQueryPrefix: true });
  const userInfo = $$.getSessionStorage('customerSystemUser');
  const isAdmin = userInfo?.ctUseroleList?.some(item => item.roleCode === '22_00024-2' || item.roleCode === '22_00024-3');
 
  if (!isAdmin) {
    return null;
  }
 
  const tabs = [
    {
      label: '个人工作统计',
      path: '/gzdyh/workStatistics',
      workType: '1',
      isArea: false
    },
    {
      label: '部门工作统计',
      path: '/gzdyh/workStatistics',
      workType: '2',
      isArea: false
    },
    {
      label: '区域工作统计',
      path: '/gzdyh/areaStatistics',
      workType: '',
      isArea: true
    }
  ];
 
  const currentTabKey = getCurrentTabKeyByLocation1(location);
 
  const handleTabClick = (tab) => {
    if (tab.isArea) {
      if (location.pathname !== tab.path) {
        history.push(tab.path);
      }
    } else {
      if (query.type !== tab.workType || location.pathname !== tab.path) {
        history.push(`${tab.path}?type=${tab.workType}`);
      }
    }
  };
 
  return (
    <div className="work-statistics-tabs">
      {tabs.map((tab) => (
        <div
          key={tab.label}
          className={`work-statistics-tab${currentTabKey == tab.label ? ' work-statistics-tab-active' : ''}`}
          onClick={() => handleTabClick(tab)}
        >
          {tab.label}
        </div>
      ))}
    </div>
  );
};
 
export default WorkStatisticsTabs;