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;
|