import React, { useEffect } from 'react';
import { Tabs, Card} from 'antd';
import { connect } from 'umi';
import { dispatchHandle } from '@/utils/publicHandle';
import { dicFindUtils, DictBizType, createSystemTree } from '@/utils/utils';
import Task from './components/Task';
import Abnormal from './components/Abnormal';
import LeakDetection from './components/LeakDetection';

const { TabPane } = Tabs;

const Tally = (props) => {
    const {
        dispatch,
        dict: {
            dicTotalsList,
        },
        statistical: {
            deviceSystemList
        },
    } = props
    /**
     * @页面初始化
     */
     useEffect(() => {
        dispatchHandle(// 设备系统
            dispatch,
            'statistical/device_service_system_node_tree_post',
            {}
        )
        dispatchHandle(// 设备
            dispatch,
            'statistical/device_service_device_simple_list_post',
            {},
        )
        dispatchHandle(// 组织架构
            dispatch,
            'user/account_service_organization_tree_user_post',
            {}
        )
    }, [])
    // 设备系统
    const systemData = (deviceSystemList && createSystemTree(deviceSystemList, 'subList')) || [];
    const deviceType = dicFindUtils(dicTotalsList, DictBizType.deviceType);
    return (
        <Card>
            <Tabs defaultActiveKey='1'>
                <TabPane tab='任务统计' key='1'>
                   <Task 
                    deviceType={deviceType}
                    systemData={systemData}
                   />
                </TabPane>
                <TabPane tab='异常统计' key='2'>
                    <Abnormal 
                        deviceType={deviceType}
                        systemData={systemData}
                    />
                </TabPane>
                <TabPane tab='漏检统计' key='3'>
                    <LeakDetection 
                        deviceType={deviceType}
                        systemData={systemData}
                    />
                </TabPane>
            </Tabs>
        </Card>
    )
}

export default connect(({ statistical, loading, dict, user }) => ({
    statistical, dict, user,
    loading: loading.models.statistical,
}))(Tally);