

/*
 * @Author: code4eat awesomedema@gmail.com
 * @Date: 2022-12-16 09:42:52
 * @LastEditors: code4eat awesomedema@gmail.com
 * @LastEditTime: 2025-09-23 16:51:23
 * @FilePath: /BudgetManaSystem/src/pages/budgetMana/monthlySet/index.tsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */



import BMSPagecontainer from '@/components/BMSPageContainer';

import { useEffect, useRef, useState } from 'react';
import './style.less';

import { Tree, TreeProps, Tabs, Input, Modal, Transfer, Divider, Select, Popconfirm, message, Button, Skeleton, Popover, Tooltip, InputNumber } from 'antd';
import { DataNode } from 'antd/es/tree';

import expandedIcon from '../../../../static/treenode_open.png';
import closeIcon from '../../../../static/treenode_collapse.png';
import { BMSTable } from '@/components/BMSTable';
import { ActionType, ModalForm, ProColumns, ProColumnType, ProForm, ProFormDependency, ProFormDigit, ProFormInstance, ProFormSelect, ProFormText, ProFormTextArea, ProFormTreeSelect } from '@ant-design/pro-components';
import { createFromIconfontCN } from '@ant-design/icons';
import { addTableData, checkMonthlyReq, delTableDataRequest, downloadTemplateReq, editCheckProject, editManaIndexTableData, editTableData, editTableSalaryRequest, editUnitCostTableData, generateCheckProjectTableData, generateUnitCostTableData, getCheckItemCalcStatus, getCheckProjectTableData, getCostData, getDepLists, getEmps, getHesuanUnits, getIncomeData, getManaIndexGroup, getManaIndexTableData, getManaIndicatorJiangchengCoefficient, getNoCheckTableData, getPageCheckStatus, getProjects, getSalaryInfoTableData, getUnitCostTableData, importMonthlyperformanceRelaFiles, reCalculateReq } from './service';


import editIcon from '../../../../static/editIcon.png';
import conformIcon from '../../../../static/confirmIcon.png';
import { getComputeDate } from '@/pages/Home/service';
import BMSModalForm from '@/components/BMSModalForm';
import { DefaultOptionType } from 'antd/es/select';
import { getTreeData, getTreeDataRespType } from '../monthlyInfoCheck/service';
import DirectoryTree from 'antd/es/tree/DirectoryTree';
import BMSUpload from '@/components/BMSUpload';
import FormItem from 'antd/es/form/FormItem';
import { getDeepestTreeData, searchLeaves } from '@/utils/tooljs';


import '../../../utils/zhongtaiA'
import { formatMoneyNumber } from '@/utils/format';
import { getJiezhuanStatus } from '../monthlySet/service';
import { useAccess } from '@umijs/max';

const IconFont = createFromIconfontCN({
    scriptUrl: '',
});


export type TableListItem = {
    key: number;
    name: string;
};

const tabData = [
    {
        label: `固定工资`,
        key: 'kpi_salary',
    },
    {
        label: `单元成本数据`,
        key: 'kpi_unit_cost',
    },
    {
        label: `非考核项目`,
        key: 'kpi_non_assessment',
    },
    {
        label: `考核项目`,
        key: 'kpi_assessment',
    },
    {
        label: `管理指标`,
        key: 'kpi_manage_indicator',
    },
    {
        label: `收入数据`,
        key: 'kpi_income',
    },
    {
        label: `成本数据`,
        key: 'kpi_cost',
    },
]



const MonthlyDataCheck: React.FC = () => {

    const [treeData, set_treeData] = useState<getTreeDataRespType[]>([]);

    const [ifShowTip, set_ifShowTip] = useState(false);
    const [unitSearchKeywords, set_unitSearchKeywords] = useState<string | undefined>(undefined); //核算单元搜素关键词
    const [expandedKeys, setExpandedKeys] = useState<React.Key[]>([]);
    const [searchValue, setSearchValue] = useState('');
    const [autoExpandParent, setAutoExpandParent] = useState(true);
    const [auditType, set_auditType] = useState('0');

    const [tableColumn, set_tableColumn] = useState<ProColumns & { [key: string]: any }[]>([]);
    const [currentSelectedTreeNode, set_currentSelectedTreeNode] = useState<any | undefined>();
    const [currentSelectedTabKey, set_currentSelectedTabKey] = useState<string>('');

    const [currentComputeDate, set_currentComputeDate] = useState<string | undefined>(undefined);

    const [editTableCellId, set_editTableCellId] = useState<number | undefined>(undefined);

    const [tableDataSearchKeywords, set_tableDataSearchKeywords] = useState<string>('');

    const [tableDataFilterParams, set_tableDataFilterParams] = useState<any | undefined>(undefined);

    const [editModalVisible, set_editModalVisible] = useState(false);

    const [loading, set_loading] = useState(false);

    const [currentEditRecord, set_currentEditRecord] = useState<undefined | any>(undefined);

    const [inputSalaryNum, set_inputSalaryNum] = useState<undefined | number>(undefined);  //固定工资金额

    const [checkItemvalNum, set_checkItemvalNum] = useState(0); //考核项目数值

    const [isTableEdit, set_isTableEdit] = useState(false);

    const [totalNum, set_totalNum] = useState(0);  //收入和成本数据的总和数值

    const [tableH, set_tableH] = useState(0);

    const access = useAccess();

    const [tabs, set_tabs] = useState<any[]>([]);

    const [ifBanAllAction, set_ifBanAllAction] = useState(true);  //是否掩藏所有操作

    const [computeMethod, set_computeMethod] = useState('1'); //1按考核分级 2按总分

    const [unitCostComputeData, set_unitCostComputeData] = useState({ unitCostTotal: 0, unitCostCtrlTotal: 0 })

    const [manaIndexGroups, set_manaIndexGroups] = useState<{
        depiction: any; id: number, groupCode: string, groupName: string, hospId: number
    }[]>([]); //管理指标分组
    const [currentSelectedManaGroup, set_currentSelectedManaGroup] = useState<{ id: number, groupCode: string, groupName: string, hospId: number }>();

    const formRef = useRef<ProFormInstance>();

    const tableRef = useRef<ActionType>();

    const tableColumnOne: ProColumns[] = [
        {
            title: '职类',
            dataIndex: 'unitTypeName',
            key: 'unitTypeName',
        },
        {
            title: '核算单元名称',
            dataIndex: 'unitName',
            key: 'unitName',

        },
        {
            title: '科室',
            dataIndex: 'deptName',
            key: 'deptName',

        },
        {
            title: '工号',
            dataIndex: 'empNo',
            key: 'empNo',

        },
        {
            title: '姓名',
            dataIndex: 'empName',
            key: 'empName',

        },
        {
            title: '工资类型',
            dataIndex: 'salaryType',
            key: 'salaryType',
        },

    ]

    const tableColumnTwo = [
        {
            title: '职类',
            dataIndex: 'unitTypeName',
            key: 'unitTypeName',

        },
        {
            title: '核算单元名称',
            dataIndex: 'unitName',
            key: 'unitName',

        },
        {
            title: '科室',
            dataIndex: 'deptName',
            key: 'deptName',

        },
        {
            title: '项目名称',
            dataIndex: 'assessmentName',
            key: 'assessmentName',

        },
        {
            title: '分配方式',
            dataIndex: 'distributionType',
            key: 'distributionType',

            render: (record: any) => {

                if (record == 1) return '占比'
                if (record == 2) return '绝对数'
                if (record == 3) return '自动计算'
            }
        },
        {
            title: '数值',
            dataIndex: 'value',
            key: 'value',

        },
        {
            title: '工号',
            dataIndex: 'targetValue',
            key: 'targetValue',

        },
        {
            title: '姓名',
            dataIndex: 'targetValueName',
            key: 'targetValueName',

        },
        {
            title: '说明',
            dataIndex: 'description',
            key: 'description',

        }

    ];

    const tableColumnThree = [
        {
            title: '项目名称',
            dataIndex: 'itemName',
            key: 'itemName',

        },
        {
            title: '类型',
            dataIndex: 'itemTypeName',
            key: 'itemTypeName',


        },
        {
            title: '点值',
            dataIndex: 'orderPointValue',
            key: 'orderPointValue',

        },
    ];

    const tableColumnFive = [
        {
            title: '年度',
            dataIndex: 'year',
            key: 'year',

        },
        {
            title: '月份',
            dataIndex: 'month',
            key: 'month',

        },
        {
            title: '项目名称',
            dataIndex: 'itemName',
            key: 'itemName',

        },
        {
            title: '项目类型',
            dataIndex: 'itemTypeName',
            key: 'itemTypeName',

        },
        {
            title: '金额',
            dataIndex: 'cost',
            key: 'cost',

        },
        // {
        //     title: '操作人',
        //     dataIndex: 'unitType',
        //     key: 'unitType',
        //     align: 'center'
        // },
        // {
        //     title: '操作时间',
        //     dataIndex: 'unitType',
        //     key: 'unitType',
        //     align: 'center'
        // },
    ]
    const tableColumnSeven = [
        {
            title: '项目名称',
            dataIndex: 'name',
        },
        {
            title: '项目类型',
            dataIndex: 'costType',
        },
        {
            title: '金额',
            dataIndex: 'amount',
            width: 200, 

            render: (text: any, record: any) => {

                if (ifBanAllAction) return formatMoneyNumber(text);

                return (
                    <div style={{ display: 'flex', flexDirection: 'row', width: '100%', justifyContent: 'flex-start', alignItems: 'center' }}>

                        <div style={{ width: '80px', height: 16, display: 'flex', flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'center' }}>
                            {
                                (currentEditRecord ? currentEditRecord.id : -1) == record.id ? <InputNumber size='small' defaultValue={record.amount} placeholder='请输入' onChange={(value) => { set_currentEditRecord({ ...currentEditRecord, amount: value }) }} style={{ width: '80px' }} /> : <span>{formatMoneyNumber(text)}</span>
                            }
                        </div>
                        {(auditType == '0' && record.summaryFlag == 0) && <img onClick={() => editHandleTwo(record)} style={{ width: 16, height: 16, cursor: 'pointer', marginLeft: 8 }} src={(currentEditRecord ? currentEditRecord.id : -1) == record.id ? conformIcon : editIcon} alt="" />}
                    </div>
                )
            }   
        },
        {
            title: '汇总',
            dataIndex: 'summaryFlag',
            render: (num: any, record: any) => {
                return record.summaryFlag == 0 ? '否' : '是'
            }
        },
        {
            title: '统计',
            dataIndex: 'statFlag',
            render: (num: any, record: any) => {
                return num == 0 ? '否' : '是'
            }
        },
        {
            title: '可控',
            dataIndex: 'ctrlFlag',
            render: (num: any, record: any) => {
                return num == 0 ? '否' : '是'
            }
        }
    ]

    let inervalhander = undefined;

    const getCurrentComputeDate = async () => {
        const resp = await getComputeDate();
        set_currentComputeDate(resp);
    }

    const onSelectHandle: TreeProps['onSelect'] = (selectedKeys, info) => {

        const { node } = info;
        if (!node.children) {
            set_currentSelectedTreeNode(node);
        }
    };


    const onExpand = (newExpandedKeys: React.Key[]) => {
        setExpandedKeys(newExpandedKeys);
        setAutoExpandParent(false);
    };

    //编辑单元成本金额
    const editHandleTwo = async (record: any) => {  
        const { id, deptCode, salaryType, unitCode, userId } = record;
        if (currentEditRecord && id == currentEditRecord.id) {
            const resp = await editUnitCostTableData({
                amount: currentEditRecord.amount,
                id

            });
            if (resp) {
                tableRef.current?.reload();
            }
            set_currentEditRecord(undefined);
        } else {
            set_currentEditRecord(record);
        }
    }

    //固定金额编辑金额
    const editHandle = async (record: any, curTabKey: string) => {
        const { id, deptCode, salaryType, unitCode, userId } = record;
        if (id == editTableCellId) {
            //保存
            //console.log({currentEditRecord,curTabKey });

            if (inputSalaryNum != undefined) {

                if (curTabKey == 'kpi_salary') {
                    const resp = await editTableSalaryRequest({
                        computeDate: currentComputeDate as string,
                        unitCode,
                        deptCode, salaryType,
                        salary: inputSalaryNum,
                        userId: `${userId}`,
                        id

                    });
                    if (resp) {
                        tableRef.current?.reload();
                    }
                }
            }
            set_editTableCellId(undefined);
        } else {
            //编辑
            set_editTableCellId(id);
        }

    }


    //考核项目编辑数值
    const editCheckItemValHandle = async (record: any) => {
        const { id, itemCode, itemName, itemType, orderPointValue, executePointValue, hospId, unitCode } = record;
        if (id == editTableCellId) {
            //保存
            if (checkItemvalNum) {
                const resp = await editCheckProject({
                    computeDate: currentComputeDate as string,
                    itemCode,
                    itemName,
                    itemType,
                    orderPointValue,
                    value: checkItemvalNum,
                    executePointValue,
                    hospId,
                    unitCode,
                    id

                });
                if (resp) {
                    tableRef.current?.reload();
                }
            }

            set_editTableCellId(undefined);
        } else {
            //编辑
            set_editTableCellId(id);
        }

    }


    const tableDataAddHandle = () => {
        set_editModalVisible(true);
    }

    //表格行编辑
    const tableEditActHandle = (record: any) => {
        //console.log({'edit':record});
        set_isTableEdit(true);
        set_currentEditRecord(record);
        set_editModalVisible(true);
    }

    const getJiezhuanStatusHandle = async () => {
        const resp = await getJiezhuanStatus(currentComputeDate as string);
        if (resp == 2) {
            set_ifBanAllAction(true);
        } else {
            set_ifBanAllAction(false);
        }
    }


    //管理指标row编辑
    const EditManaIndexTableRow = ({ record }: { record: any }) => {

        const { value, columns, unitName, id, unitCode, totalScore, computeDate, groupId } = record;
        return (
            <ModalForm
                title={`编辑${unitName}实际值`}
                width={500}
                // layout='inline'
                trigger={
                    <a key={'1'} style={{ textAlign: 'center', width: '100%' }}>编辑</a>
                }
                initialValues={record}
                // style={{maxHeight:600,overflowY:'scroll'}}
                onFinish={async (values) => {
                
                    // console.log({values,value,columns});
                    const editResult = columns.map((a: any) => {
                        const needItem = value.filter((b:any)=>b.code == a.key);
                        if(needItem.length>0){
                            return {
                                ...needItem[0],
                                value: values[`value${a.key}`]
                            }
                        }else{
                           return {
                            code:a.key,value:values[`value${a.key}`]
                           }
                        }
                        
                    })

                    const data = {
                        id,
                        unitCode,
                        unitName,
                        totalScore,
                        computeDate,
                        groupId,
                        value: editResult
                    }
                    const resp = await editManaIndexTableData(data);
                    if (resp) {
                        tableRef.current?.reload();
                    }
                    return true
                }}
            >
                {
                    columns.map((item: any, index: any) => {
                        //const findTitle = columns.filter((a: any) => a.key == item.code);
                        return (
                            <ProFormDigit key={index} min={-1000000} label={`${item.dataIndex}`}  name={`value${item.key}`} />
                        )
                    })
                }
            </ModalForm>
        )
    }


    const onTabChange = (activeKey: string) => {
        set_currentSelectedTabKey(activeKey);
    }

    //获取核算单元树结构
    const getCheckUnitTreeDataFunc = async (computeDate: string) => {
        const resp = await getTreeData(computeDate);
        if (resp) {
            set_treeData(resp);
        }
    }


    const getCalcStatus = async () => {
        const resp = await getCheckItemCalcStatus(currentComputeDate as string, 'ASSESSMENT');
        if (resp) {
            if (resp.calculating) {
                //继续计算
                set_loading(true);
                return false
            } else {
                //计算已完成
                set_loading(false);
                return true
            }
        } else {
            tableRef.current?.reload();
            return true
        }
    }

    const func = (str: string) => str && str.replace(/(?:\.0*|(\.\d+?)0+)$/, '$1') + '%';

    const getTableData = async (type: string, params: any, sort: any, filter: any) => {

        if (currentComputeDate) {
            if (type == 'kpi_salary') {
                const resp = await getSalaryInfoTableData({
                    computeDate: currentComputeDate,
                    ...params
                });
                if (resp) {
                    return {
                        data: resp.list,
                        total: resp.totalCount,
                        pageSize: resp.pageSize,
                        totalPage: resp.totalPage,
                        success: true
                    }
                }
            }
            if (type == 'kpi_non_assessment') {
                const resp = await getNoCheckTableData({
                    computeDate: currentComputeDate,
                    ...params
                });
                if (resp) {
                    return {
                        data: resp.list,
                        total: resp.totalCount,
                        pageSize: resp.pageSize,
                        totalPage: resp.totalPage,
                        success: true
                    }
                }
            }
            if (type == 'kpi_assessment') {



                if (!loading) {
                    //计算完和未计算

                    const resp = await getCheckProjectTableData({
                        computeDate: currentComputeDate,
                        unitCode: currentSelectedTreeNode.code,
                        ...params
                    });
                    if (resp) {
                        return {
                            data: resp.list,
                            success: true,
                            total: resp.totalCount,
                            pageSize: resp.pageSize,
                            totalPage: resp.totalPage,
                        }
                    }
                }
            }
            if (type == 'kpi_manage_indicator') {
                if (currentSelectedManaGroup) {

                    const resp = await getManaIndexTableData({ ...params, computeDate: currentComputeDate, groupId: currentSelectedManaGroup.id });
                    if (resp) {
                        const columns = resp.title.map((item: any, titleIndex: number) => {

                            return (item.children ? {
                                title: () => {
                                    return <div>{item.name} <span style={{ fontSize: 14, fontFamily: 'SourceHanSansCN-Medium, SourceHanSansCN', fontWeight: 500, color: item.arrow == 'up' ? '#00BF8F' : '#FF4060' }}>{item.arrow == 'up' ? '↑' : '↓'}</span></div>
                                },
                                key: item.code,
                                dataIndex: item.name,
                                children: item.children.map((a: any, aindex: number) => {
                                    return {
                                        title: a.name,
                                        dataIndex: `${a.code}${item.code}`,
                                        key: `${a.code}${item.code}`,
                                        width: 100,
                                        align: 'center',
                                        renderText(num: any, record: any, index: any, action: any) {
                                            //console.log({record,a,titleIndex})
                                            return (item.dataType == 1 || a.name == '得分') ? a.name == '得分' ? <span style={{ color: record[`veto${titleIndex + 1}`] ? '#FF8C19' : '#17181A' }}>{num}</span> : num : num ? func((num * 100).toFixed(2)) : '-'
                                        },
                                    }

                                })
                            } : {
                                title: item.name,
                                dataIndex: item.code,
                                key: item.code,
                                width: 100,
                                align: 'center',
                                renderText(num: any, record: any, index: any, action: any) {
                                    return (item.dataType == 1) ? num : num ? func((num * 100).toFixed(2) + '%') : '-'
                                },
                            })
                        });




                        set_tableColumn([{
                            title: '核算单元',
                            dataIndex: 'unitName',
                            key: 'unitName',

                            width: 120,
                            fixed: 'left',
                        }, ...columns,
                        {
                            title: '总得分',
                            dataIndex: 'totalScore',
                            key: 'totalScore',

                            width: 100,
                            fixed: 'right',
                        },
                        {
                            title: '分级',
                            dataIndex: 'level',
                            key: 'level',
                            width: 100,
                            fixed: 'right',
                            hideInTable: computeMethod == '2' ? true : false
                        },
                        {
                            title: '系数',
                            dataIndex: 'kpi',
                            key: 'kpi',

                            width: 100,
                            fixed: 'right',
                        },
                        ]);

                        const data = resp.managerData.map((item: any) => {

                            let rowData: { [key: string]: any } = {};

                            for (let index = 0; index < item.value.length; index++) {
                                for (const key in item.value[index]) {
                                    if (key == 'veto') {
                                        //${key}${item.value[index].code}-${index} 中的index用于指定是该列的哪一格
                                        rowData[`${key}${item.value[index].code}`] = item.value[index][`${key}`]
                                    } else {
                                        rowData[`${key}${item.value[index].code}`] = item.value[index][`${key}`]
                                    }
                                }
                            }

                            return { ...item, ...rowData, id: item.id, columns }
                        });

                        return {
                            data: data,
                            success: true,
                            total: resp.totalCount,
                            pageSize: resp.pageSize,
                            totalPage: resp.totalPage,
                        }
                    }
                }

            }

            if (type == 'kpi_income') {
                const resp = await getIncomeData({
                    computeDate: currentComputeDate,
                    ...params
                });
                if (resp) {
                    set_totalNum(resp.sum);
                    return {
                        data: resp.pageList.list,
                        success: true,
                        total: resp.pageList.totalCount,
                        pageSize: resp.pageList.pageSize,
                        totalPage: resp.pageList.totalPage,
                    }
                }
            }
            if (type == 'kpi_cost') {
                const resp = await getCostData({
                    computeDate: currentComputeDate,
                    ...params
                });
                if (resp) {
                    set_totalNum(resp.sum);
                    return {
                        data: resp.pageList.list,
                        success: true,
                        total: resp.pageList.totalCount,
                        pageSize: resp.pageList.pageSize,
                        totalPage: resp.pageList.totalPage,
                    }
                }
            }
            if (type == 'kpi_unit_cost' && currentSelectedTreeNode) {
                const resp = await getUnitCostTableData({
                    unitCode: currentSelectedTreeNode.code,
                    ...params
                });

                let unitCostTotal = 0;
                let unitCostCtrlTotal = 0;

                const traverseTree = (node: any) => {
                    if (node == null) return;

                    if (!node.summaryFlag) {
                        //summaryFlag 汇总
                        unitCostTotal = unitCostTotal + node.amount
                        if (node.ctrlFlag) {
                            unitCostCtrlTotal = unitCostCtrlTotal + node.amount
                        }
                    }

                    if (node.children) {
                        node.children.forEach(traverseTree);
                    }
                }



                resp.forEach((a: any) => {
                    traverseTree(a);
                });

                set_unitCostComputeData({
                    unitCostTotal, unitCostCtrlTotal
                })

                if (resp) {

                    return {
                        data: resp,
                        success: true,
                        total: 0,
                        pageSize: 10,
                        totalPage: 0,
                    }
                }
            }
        }

        return []
    }

    const tableDataSearchHandle = (paramName: string) => {


        set_tableDataFilterParams({
            ...tableDataFilterParams,
            [`${paramName}`]: tableDataSearchKeywords
        })
    }

    //表格删除确认
    const delActionHandle = async (record: any, index: number) => {

        const { id } = record;
        const resp = await delTableDataRequest({
            computeDate: currentComputeDate as string,
            id,
            index
        });
        if (resp) {
            tableRef.current?.reload();
            message.success('删除成功！')
        }

    };


    const dataList: any[] = [];

    const generateList = (data: getTreeDataRespType[]) => {
        for (let i = 0; i < data.length; i++) {
            const node = data[i];
            const { code, name } = node;
            dataList.push({ code: code, name: name });
            if (node.child) {
                generateList(node.child);
            }
        }
    };

    generateList(treeData as any);

    const getParentKey = (key: React.Key, tree: any[]): React.Key => {
        let parentKey: React.Key;
        for (let i = 0; i < tree.length; i++) {
            const node = tree[i];
            if (node.child) {
                if (node.child.some((item: { code: React.Key; }) => item.code === key)) {
                    parentKey = node.code;
                } else if (getParentKey(key, node.child)) {
                    parentKey = getParentKey(key, node.child);
                }
            }
        }
        return parentKey!;
    };
    //考核项目树结构搜索
    const onTreeSearchKeyChange = (e: React.ChangeEvent<HTMLInputElement>) => {
        const { value } = e.target;
        const newExpandedKeys = dataList
            .map((item) => {
                if (item.name.indexOf(value) > -1) {
                    return getParentKey(item.code, treeData);
                }
                return null;
            });

        const b = newExpandedKeys.filter((item, i, self) => item && self.indexOf(item) === i);

        setExpandedKeys(newExpandedKeys as React.Key[]);
        setSearchValue(value);
        setAutoExpandParent(true);
    }


    //获取数据
    const confirmGenerateHandle: any = async (code: string, others?: any) => {


        if (code == 'kpi_assessment') {
            const resp = await generateCheckProjectTableData({
                computeDate: currentComputeDate as string,
                unitCode: others ? currentSelectedTreeNode.code : ''
            });

            set_loading(false);

            if (resp) {
                tableRef.current?.reload();
            }
            return Promise.resolve(true);

        }
        if (code == 'kpi_cost') {
            const resp = await generateUnitCostTableData(
                currentComputeDate as string,
                currentSelectedTreeNode.code
            );

            set_loading(false);

            if (resp) {
                tableRef.current?.reload();
            }
            return Promise.resolve(true);

        }
    }

    const generateFunc = (code: string, others?: any) => {
        /**
         * index 获取的表格类型下标
         */

        if ((code == 'kpi_assessment' || code == 'kpi_cost') && !loading) {
            Modal.confirm({
                title: '注意',
                cancelText: '',
                okText: '确定',
                closable: true,
                content: others ? '获取单个操作会覆盖上次获取的该核算单元的数据，确定要继续操作？' : `${code == 'kpi_cost' ? '获取' : '获取所有'}操作会覆盖所有已获取的数据，确定要继续操作？`,
                onOk: () => { set_loading(true); confirmGenerateHandle(code, others) }
            })
        }
    }

    const onVisibleChangeHandle = (bool: boolean) => {
        set_editModalVisible(bool);
        if (!bool) {
            set_isTableEdit(false);
        }
    }

    const onManaIndexGroupClick = (manaIndexGroup: any) => {
        set_currentSelectedManaGroup(manaIndexGroup);
    }

    const tableFormCommit = async (formData: any, type: 'edit' | 'add') => {

        if (type == 'edit') {
            //编辑
            const body = {
                id: currentEditRecord.id,
                computeDate: currentComputeDate as string,
                unitCode: formData.unitCode,
                deptCode: formData.deptCode,
                nonAssessmentCode: typeof formData.assessmentCode == 'number' ? formData.assessmentCode : formData.assessmentCode.value,
                targetValue: `${formData.userId ? formData.userId : ''}`,
                value: `${formData.value}`,
                description: formData.description
            }

            const resp = await editTableData(body);

            if (resp) {
                tableRef.current?.reload();
            }
            set_isTableEdit(false);

        } else if (type == 'add') {
            //新增
            const body = {

                computeDate: currentComputeDate as string,
                unitCode: formData.unitCode,
                deptCode: formData.deptCode,
                nonAssessmentCode: formData.assessmentCode.value,
                targetValue: `${formData.userId ? formData.userId : ''}`,
                value: `${formData.value}`,
                description: formData.description

            }

            const resp = await addTableData(body);
            if (resp) {
                tableRef.current?.reload();
            }
        }

        // set_editModalVisible(false);
        set_currentEditRecord(undefined);
        return true;
    }

    //获取管理指标分组
    const getManaIndiGroupRequest = async () => {

        const resp = await getManaIndexGroup();
        if (resp) {
            set_manaIndexGroups(resp);
            if (resp.length > 0) {
                set_currentSelectedManaGroup(resp[0])
            }
        }
    }

    const importData = (code: string, name: string) => {
        // console.log({ code, name });
        if (ifBanAllAction) return;
        return (
            <ModalForm
                width={360}
                title={`导入${name}数据`}
                trigger={
                    <span key="3">导入</span>
                }
                submitter={{
                    render: (props, defaultDoms) => {
                        const needBtn = defaultDoms.filter((b) => {
                            return b.key != 'rest'
                        })
                        return [
                            // <Button
                            //     key="ok"
                            //     onClick={auditType == '0' ? () => downloadTemplate(index) : () => { }}
                            // >
                            //     下载模板
                            // </Button>,
                            ...needBtn,
                        ];
                    },
                }}
                onFinish={async (values) => {
                    // console.log({values});
                    const { importFile: { fileList } } = values;

                    let formData = new FormData();
                    if (code == 'kpi_unit_cost') {
                        formData.append('file', fileList[0].originFileObj);
                        formData.append('computeDate', currentComputeDate as string);
                        formData.append('unitCode', currentSelectedTreeNode.code);
                    } else {
                        formData.append('file', fileList[0].originFileObj);
                        formData.append('computeDate', currentComputeDate as string);
                        formData.append('groupId', currentSelectedManaGroup?.id as any);
                    }


                    const resp = await importMonthlyperformanceRelaFiles(code, formData);

                    if (resp) {
                        tableRef.current?.reload();
                        return true;
                    }

                }}
            >
                <FormItem name={'importFile'}>
                    <BMSUpload downloadTemplateFile={auditType == '0' ? () => code == 'kpi_assessment' || code == 'kpi_unit_cost' ? downloadTemplate(code, code == 'kpi_unit_cost' ? currentSelectedTreeNode.code : currentSelectedManaGroup?.id) : downloadTemplate(code, currentSelectedManaGroup?.id) : () => { }} />
                </FormItem>

            </ModalForm>
        )
    }

    const checkHandle = async (type: string) => {

        const resp = await checkMonthlyReq(
            currentComputeDate as string,
            type == '0' ? '1' : '0',   //审核类型  1审核 0取消审核
        );

        if (resp) {
            if (type == '0') {
                message.success('审核提交成功！');
                set_auditType('1');
            }
            if (type == '1') {
                message.success('取消审核提交成功！');  
                set_auditType('0');
            }
        }
    }


    const pageCheckStatusFunc = async (time: string) => {
        const resp = await getPageCheckStatus(time);
        if (resp) {
            set_auditType(`${resp}`);  //0 未审核 1 已审核
        }
    }

    const downloadTemplate = async (code: string, id?: number) => {
        await downloadTemplateReq(code, id);


        // if(index == 4){
        //       //管理指标
        //       await downloadTemplateReq(index,currentSelectedManaGroup?.groupCode);
        // }else{

        // }

    }

    const getComputeMethod = async () => {
        const resp = await getManaIndicatorJiangchengCoefficient();
        if (resp) {
            const need = resp.list.filter((a: any) => (a.code == '1670618922728169472'));
            if (need.length > 0) {
                set_computeMethod(need[0].value);
            }
        }
    }


    const handleResize = (e: any) => {
        const wH = e.target.innerHeight;
        const tableHeight = wH - 320;
        set_tableH(tableHeight);
    }

    function doResize() {
        setTimeout(() => {
            const ev: any = new Event('resize');
            window.dispatchEvent(ev);
        }, 0)
    }

    const reCalcuteHandle = async () => {
        Modal.confirm({
            title: '注意',
            content: '确定要将当前分组下所有核算单元的管理指标进行重算？',
            onOk: async () => {
                const resp = await reCalculateReq(`${currentSelectedManaGroup?.id}`, currentComputeDate as string);
                if (resp) {
                    tableRef.current?.reload();
                    return true
                }
            },
        })
    }


    useEffect(() => {
        if (loading) {
            inervalhander = setInterval(() => {
                getCalcStatus();
            }, 60000)
        }
    }, [loading])



    useEffect(() => {

        set_tableDataFilterParams({
            ...tableDataFilterParams,
            id: currentSelectedManaGroup?.id,
        });
    }, [currentSelectedManaGroup]);

    useEffect(() => {
        tableRef.current?.reloadAndRest && tableRef.current?.reloadAndRest();
    }, [currentSelectedTreeNode]);

    useEffect(() => {
        //清空表格筛选项

        set_tableDataFilterParams(undefined);
        set_currentSelectedTreeNode(undefined);

        if (currentSelectedTabKey == 'kpi_salary') {
            set_tableColumn(tableColumnOne as ProColumns[]);
        }
        if (currentSelectedTabKey == 'kpi_non_assessment') {
            set_tableColumn(tableColumnTwo as ProColumns[]);
        }
        if (currentSelectedTabKey == 'kpi_assessment') {
            if (currentComputeDate) {
                getCheckUnitTreeDataFunc(currentComputeDate as string);
            }
            set_tableColumn(tableColumnThree as ProColumns[]);
        }
        if (currentSelectedTabKey == 'kpi_manage_indicator') {
            getManaIndiGroupRequest();   //获取分组
        }
        if (currentSelectedTabKey == 'kpi_income') {
            set_tableColumn(tableColumnFive as ProColumns[]);
        }
        if (currentSelectedTabKey == 'kpi_cost') {
            set_tableColumn(tableColumnFive as ProColumns[]);
        }
        if (currentSelectedTabKey == 'kpi_unit_cost') {
            if (currentComputeDate) {
                getCheckUnitTreeDataFunc(currentComputeDate as string);
            }
            set_tableColumn(tableColumnSeven as ProColumns[]);
        }

    }, [currentSelectedTabKey]);

    useEffect(() => {
        if (currentSelectedTabKey == 'kpi_cost' || currentSelectedTabKey == 'kpi_unit_cost') {
            // if (currentComputeDate) {
            //     getCheckUnitTreeDataFunc(currentComputeDate as string);
            // }
            set_tableColumn(tableColumnSeven as ProColumns[]);
        }

    }, [currentEditRecord, auditType, ifBanAllAction])



    useEffect(() => {
        //初始化左侧树结构数据后

        if (treeData?.length > 0) {

            if (treeData[0].child && treeData[0].child.length > 0) {
                const [node, nodeParent] = getDeepestTreeData(treeData[0], 'child');
                set_currentSelectedTreeNode(node);
                setExpandedKeys([nodeParent.code]);
            }

        }

    }, [treeData]);


    useEffect(() => {

        if (currentComputeDate) {
            pageCheckStatusFunc(currentComputeDate);  //获取页面查核状态
            getCalcStatus();
            getJiezhuanStatusHandle();
        }

    }, [currentComputeDate]);


    useEffect(() => {

        getCurrentComputeDate();
        set_tableColumn(tableColumnOne as ProColumns[]);
        getComputeMethod();

        const tabs = access.whatCanIDoInThisPage(location.pathname.replace('/budgetManaSystem', ''));
        const tabsNameArr = tabs.map((a: any) => a.code);
        const needShowTabs = tabData.filter(a => tabsNameArr.includes(a.key));

        set_tabs(needShowTabs);
        needShowTabs.length > 0 && set_currentSelectedTabKey(needShowTabs[0].key);
        window.addEventListener('resize', (e) => handleResize(e)) //监听窗口大小改变
        doResize();
        return () => {
            window.removeEventListener('resize', (e) => handleResize(e));
        }

    }, [])

    return (
        <div className='MonthlyDataCheck'>
            {
                true && (
                    <BMSModalForm formRef={formRef} open={editModalVisible} initialValues={isTableEdit ? { ...currentEditRecord } : { unitCode: 'A010101' }} title={isTableEdit ? '编辑' : '新增'}
                        size="middle" width={737} onOpenChange={onVisibleChangeHandle}
                        modalProps={{
                            destroyOnClose: true
                        }}
                        onFinish={(val: any) => tableFormCommit(val, isTableEdit ? 'edit' : 'add')}
                    >
                        {
                            currentSelectedTabKey == 'kpi_salary' && (
                                <>
                                    <ProFormText width="md" name="itemName" label="项目名" disabled />
                                    <ProFormText width="md" name="itemTypeName" label="类型" disabled />
                                    <ProFormDigit width="md" label="点值" name="pointValue" min={0} />
                                    <ProFormText width="md" name="createUser" label="操作人" disabled />
                                </>
                            )
                        }
                        {
                            currentSelectedTabKey == 'kpi_non_assessment' && (
                                <>
                                    <ProForm.Group >
                                        <ProFormTreeSelect
                                            name="unitCode"
                                            label="核算单元"
                                            placeholder="请选择"
                                            colProps={{ span: 12 }}
                                            rules={[{ required: true }]}
                                            request={async () => {
                                                const resp = await getHesuanUnits(currentComputeDate as string);
                                                if (resp) {
                                                    return resp
                                                }
                                                return []
                                            }}
                                            fieldProps={{
                                                showSearch: true,
                                                treeDefaultExpandedKeys: ['A010101'],
                                                filterTreeNode(inputValue, treeNode) {
                                                    const match = `${treeNode.name}`.indexOf(inputValue) != -1;

                                                    if (match && !treeNode.isLeaf && !treeNode.children) {
                                                        // Do some loading logic
                                                    }

                                                    return match;
                                                },
                                                fieldNames: {
                                                    label: 'name',
                                                    value: 'code',
                                                    children: 'child'
                                                },
                                                treeExpandAction: false,
                                                switcherIcon: (props: any) => {
                                                    const { expanded } = props;
                                                    return !expanded ? <img style={{ width: 20, height: 20, position: 'relative', top: 2 }} src={expandedIcon} /> : <img style={{ width: 20, height: 20, position: 'relative', top: 2 }} src={closeIcon} />
                                                },
                                                onChange: (value) => {
                                                    formRef.current?.setFieldValue('deptCode', '');
                                                }
                                            }}
                                        />

                                        <ProFormDependency name={['unitCode']}>
                                            {
                                                ({ unitCode }) => {
                                                    // console.log({deptCode});
                                                    return (
                                                        <ProFormSelect
                                                            name="deptCode"
                                                            label="科室名称"
                                                            colProps={{ span: 12 }}
                                                            placeholder="请选择"
                                                            // rules={[{ required: true }]}
                                                            params={unitCode}
                                                            request={async () => {
                                                                if (unitCode) {

                                                                    const resp = await getDepLists(unitCode);
                                                                    if (resp) {
                                                                        return resp.list.map((a: any) => ({
                                                                            label: a.deptName, value: a.deptCode, d: a
                                                                        }))
                                                                    }
                                                                }
                                                                return []
                                                            }}
                                                            fieldProps={{
                                                                showSearch: true,
                                                                onChange: (value) => {
                                                                    formRef.current?.setFieldValue('targetValue', '');
                                                                }
                                                            }}
                                                        />
                                                    )
                                                }
                                            }
                                        </ProFormDependency>

                                    </ProForm.Group>
                                    <ProForm.Group>
                                        <ProFormSelect
                                            name="assessmentCode"
                                            label="项目名称"
                                            placeholder="请选择"
                                            colProps={{ span: 12 }}
                                            rules={[{ required: true }]}
                                            request={async () => {
                                                const resp = await getProjects();
                                                if (resp) {
                                                    return resp.map((a: any) => ({
                                                        label: a.name, value: a.code, d: a
                                                    }))
                                                }
                                                return []
                                            }}
                                            fieldProps={{
                                                labelInValue: true,
                                                onChange: (value: any) => {
                                                    const { d: { distributionTypeName } } = value;
                                                    formRef.current?.setFieldValue('distributionTypeName', distributionTypeName);
                                                }
                                            }}
                                        />
                                        <ProFormDependency name={['assessmentCode']}>
                                            {
                                                ({ assessmentCode }) => {
                                                    return (
                                                        <ProFormText disabled name="distributionTypeName" label="分配方式" colProps={{ span: 12 }} />
                                                    )
                                                }
                                            }
                                        </ProFormDependency>

                                    </ProForm.Group>
                                    <ProForm.Group>
                                        <ProFormDigit label="数值" name="value" colProps={{ span: 12 }} min={-1000000000000000} />
                                        <ProFormDependency name={['unitCode', 'distributionTypeName']}>
                                            {
                                                ({ unitCode, distributionTypeName }) => {

                                                    return (
                                                        <ProFormSelect
                                                            name="userId"
                                                            label="人员姓名"
                                                            colProps={{ span: 12 }}
                                                            placeholder="请选择"
                                                            rules={[{ required: distributionTypeName != '占比' ? true : false }]}
                                                            params={unitCode}
                                                            fieldProps={{
                                                                showSearch: true,
                                                            }}
                                                            request={async () => {
                                                                if (unitCode) {
                                                                    const resp = await getEmps(unitCode);

                                                                    if (resp) {
                                                                        return resp.map((a: any) => ({
                                                                            label: `${a.name}-${a.userId}`, value: a.userId, d: a
                                                                        }))
                                                                    }
                                                                }

                                                                return []
                                                            }}
                                                        />
                                                    )
                                                }
                                            }
                                        </ProFormDependency>

                                    </ProForm.Group>
                                    <ProForm.Group >
                                        <ProFormTextArea
                                            name="description"
                                            label="说明"
                                            colProps={{ span: 24 }}
                                            placeholder="请输入"
                                        />
                                    </ProForm.Group>
                                </>
                            )
                        }
                    </BMSModalForm>
                )

            }

            <>
                {
                    (
                        <div className='rightContent'>
                            <BMSPagecontainer title={`核算年月：${currentComputeDate}`} ghost>
                                {
                                    !ifBanAllAction && <div className='checkBtn' onClick={() => checkHandle(`${auditType}`)}>{auditType == '0' ? '审核' : '取消审核'}</div>
                                }

                                {/* <div className='midLine'>
                            <span>点击检查</span>
                            是否有未对照的人员信息、未对照的科室信息及未设置的收费项目信息
                        </div> */}
                                {
                                    tabs.length > 0 && <Tabs
                                        defaultActiveKey={tabs[0].key}
                                        onChange={onTabChange}
                                        items={tabs}
                                    />
                                }

                                {
                                    currentSelectedTabKey == 'kpi_salary' && (
                                        <div className='tabContent'>
                                            <div className='tableToolbar'>
                                                <div className='filter'>
                                                    <div className='search'>
                                                        <span>核算单元名称：</span><Input className='searchInput' allowClear placeholder="请输入" onChange={(e) => {
                                                            set_tableDataSearchKeywords(e.target.value);
                                                            if (e.target.value.length == 0) {
                                                                set_tableDataFilterParams({
                                                                    ...tableDataFilterParams,
                                                                    deptName: ''
                                                                });
                                                            }
                                                        }} suffix={
                                                            <IconFont type="iconsousuo" onClick={() => tableDataSearchHandle('deptName')} />
                                                        } />

                                                    </div>
                                                </div>
                                                <Popover open={ifShowTip} content={'当前处于审核中，无法操作！'} placement='topRight'>
                                                    <div className={auditType == '1' ? 'btnGroup disabled' : 'btnGroup'}
                                                        onMouseEnter={() => auditType == '0' ? set_ifShowTip(false) : set_ifShowTip(true)}
                                                        onMouseLeave={() => set_ifShowTip(false)}
                                                    >
                                                        {/* <span key="1">调整</span> */}
                                                        {/* <span key="2" onClick={() => generateFunc()}>获取</span> */}
                                                        {importData('kpi_salary', '固定工资')}
                                                    </div>
                                                </Popover>
                                            </div>
                                            {currentComputeDate && <BMSTable actionRef={tableRef} params={tableDataFilterParams} rowKey='id'
                                                columns={(auditType == '0' && !ifBanAllAction) ? [...tableColumn, {
                                                    title: '金额',
                                                    dataIndex: 'salary',
                                                    key: 'salary',
                                                    align: 'center',
                                                    width: '10%',
                                                    render: (text: any, record: any) => {
                                                        if (ifBanAllAction) return formatMoneyNumber(text);
                                                        return (
                                                            <div style={{ display: 'flex', flexDirection: 'row', width: '100%', justifyContent: 'center', alignItems: 'center' }}>

                                                                <div style={{ width: '80px', height: 16, display: 'flex', flexDirection: 'row', justifyContent: 'center', alignItems: 'center' }}>
                                                                    {
                                                                        editTableCellId == record.id ? <Input size='small' defaultValue={record.salary} placeholder='请输入' onChange={(e) => { set_inputSalaryNum(Number(e.target.value)) }} style={{ width: '80px' }} /> : <span>{formatMoneyNumber(text)}</span>
                                                                    }
                                                                </div>
                                                                {auditType == '0' && <img onClick={() => editHandle(record, 'kpi_salary')} style={{ width: 16, height: 16, cursor: 'pointer', marginLeft: 8 }} src={editTableCellId == record.id ? conformIcon : editIcon} alt="" />}
                                                            </div>
                                                        )
                                                    }
                                                },

                                                {
                                                    title: '操作',
                                                    key: 'option',
                                                    valueType: 'option',
                                                    render: (_: any, record) => [
                                                        <Popconfirm
                                                            key={'del'}
                                                            title="是否确认删除？"
                                                            onConfirm={() => delActionHandle(record, 1)}
                                                            // onCancel={()=>{}}
                                                            okText="是"
                                                            cancelText="否"
                                                        >
                                                            <a >删除</a>
                                                        </Popconfirm>
                                                    ],
                                                },] : [

                                                    ...tableColumn, {
                                                        title: '金额',
                                                        dataIndex: 'salary',
                                                        key: 'salary',

                                                        width: '10%',
                                                        // shouldCellUpdate:(record:any, prevRecord:any) => true,
                                                        render: (text: any, record: any) => {
                                                            if (ifBanAllAction) return formatMoneyNumber(text);
                                                            return (
                                                                <div style={{ display: 'flex', flexDirection: 'row', width: '100%', justifyContent: 'center', alignItems: 'center' }}>

                                                                    <div style={{ width: '80px', height: 16, display: 'flex', flexDirection: 'row', justifyContent: 'center', alignItems: 'center' }}>
                                                                        {
                                                                            editTableCellId == record.id ? <Input size='small' defaultValue={record.salary} placeholder='请输入' onChange={(e) => { set_inputSalaryNum(Number(e.target.value)) }} style={{ width: '80px' }} /> : <span>{formatMoneyNumber(text)}</span>
                                                                        }
                                                                    </div>
                                                                    {auditType == '0' && <img onClick={() => editHandle(record, 'kpi_salary')} style={{ width: 16, height: 16, cursor: 'pointer', marginLeft: 8 }} src={editTableCellId == record.id ? conformIcon : editIcon} alt="" />}
                                                                </div>
                                                            )
                                                        }
                                                    },

                                                ]} request={(params, sort, filter) => getTableData('kpi_salary', params, sort, filter)} />}
                                        </div>
                                    )
                                }

                                {
                                    currentSelectedTabKey == 'kpi_non_assessment' && (
                                        <div className='tabContent'>
                                            <div className='tableToolbar'>
                                                <div className='filter'>
                                                    <div className='search'>
                                                        <span>核算单元名称：</span><Input className='searchInput' allowClear placeholder="请输入" onChange={(e) => {
                                                            set_tableDataSearchKeywords(e.target.value);
                                                            if (e.target.value.length == 0) {
                                                                set_tableDataFilterParams({
                                                                    ...tableDataFilterParams,
                                                                    deptName: ''
                                                                });
                                                            }
                                                        }} suffix={
                                                            <IconFont type="iconsousuo" onClick={() => tableDataSearchHandle('deptName')} />
                                                        } />
                                                    </div>
                                                </div>
                                                <Popover open={ifShowTip} content={'当前处于审核中，无法操作！'} >
                                                    <div className={auditType == '1' ? 'btnGroup disabled' : 'btnGroup'}
                                                        onMouseEnter={() => auditType == '0' ? set_ifShowTip(false) : set_ifShowTip(true)}
                                                        onMouseLeave={() => set_ifShowTip(false)}
                                                    >
                                                        {/* <span key="1" onClick={() => generateFunc(2)} >获取</span>
                                            <span key="2" >导入</span> */}
                                                        {importData('kpi_non_assessment', '非考核项目')}
                                                        {!ifBanAllAction && <span key="3" onClick={auditType == '0' ? () => tableDataAddHandle() : () => { }}>添加</span>}
                                                    </div>
                                                </Popover>
                                            </div>
                                            {currentComputeDate && <BMSTable scroll={{ x: 120 * 10, y: 500 }} actionRef={tableRef} rowKey='id' params={tableDataFilterParams}
                                                columns={(auditType == '0' && !ifBanAllAction) ? [...tableColumn, {
                                                    title: '操作',
                                                    fixed: 'right',
                                                    key: 'option',

                                                    width: 130,
                                                    valueType: 'option',
                                                    render: (_: any, record: any) => [
                                                        <a key={'edit'} onClick={() => tableEditActHandle(record)}>编辑</a>,
                                                        <Divider type='vertical' key='line' />,
                                                        <Popconfirm
                                                            key={'del'}
                                                            title="是否确认删除？"
                                                            onConfirm={() => delActionHandle(record, 2)}
                                                            // onCancel={()=>{}}
                                                            okText="是"
                                                            cancelText="否"
                                                        >
                                                            <a >删除</a>
                                                        </Popconfirm>
                                                    ],
                                                }] : [...tableColumn]} request={(params, sort, filter) => getTableData('kpi_non_assessment', params, sort, filter)} />}
                                        </div>
                                    )
                                }

                                {
                                    currentSelectedTabKey == 'kpi_assessment' && (
                                        <div className='tabContent'>

                                            <div className='tabContentInner'>
                                                <div className='leftTree'>
                                                    <div className='search'>
                                                        <Input className='searchInput' allowClear onChange={onTreeSearchKeyChange} placeholder="请输入名称" suffix={
                                                            <IconFont type="iconsousuo" />
                                                        } />
                                                    </div>
                                                    <div className='treeWrap'>
                                                        {
                                                            treeData && treeData.length > 0 && currentSelectedTreeNode && (
                                                                <DirectoryTree
                                                                    fieldNames={{ title: 'name', key: 'code', children: 'child' }}
                                                                    rootStyle={{ height: '100%', paddingBottom: 50, overflowY: 'scroll', overflowX: 'hidden' }}
                                                                    onSelect={onSelectHandle}
                                                                    onExpand={onExpand}
                                                                    expandedKeys={expandedKeys}
                                                                    autoExpandParent={autoExpandParent}
                                                                    selectedKeys={[currentSelectedTreeNode.code]}
                                                                    blockNode={true}
                                                                    icon={() => null}
                                                                    titleRender={
                                                                        (nodeData: any) => {
                                                                            const strTitle = nodeData.name as string;
                                                                            const index = strTitle.indexOf(searchValue);
                                                                            const beforeStr = strTitle.substring(0, index);
                                                                            const afterStr = strTitle.slice(index + searchValue.length);
                                                                            const title =
                                                                                index > -1 ? (
                                                                                    <span>
                                                                                        {beforeStr}
                                                                                        <span className="site-tree-search-value" style={{ color: 'red', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{searchValue}</span>
                                                                                        {afterStr}
                                                                                    </span>
                                                                                ) : (
                                                                                    <span className='strTitle'>{strTitle}</span>
                                                                                );
                                                                            return <div style={{
                                                                                display: 'flex', flexDirection: 'row',
                                                                                width: '100%',
                                                                                justifyContent: 'flex-start', alignItems: 'center', height: 32,
                                                                                borderRadius: '4px',
                                                                                overflow: 'hidden',
                                                                                color: '#17181A',
                                                                                textOverflow: 'ellipsis',
                                                                                whiteSpace: 'nowrap'

                                                                            }}>{title}</div>
                                                                        }
                                                                    }
                                                                    defaultSelectedKeys={[treeData[0].child[0].code]}
                                                                    treeData={treeData as unknown as DataNode[]}
                                                                    // treeData={treeDataNew}
                                                                    switcherIcon={(props: any) => {
                                                                        const { expanded } = props;
                                                                        return !expanded ? <img style={{ width: 20, height: 20, position: 'relative', top: 5 }} src={expandedIcon} /> : <img style={{ width: 20, height: 20, position: 'relative', top: 5 }} src={closeIcon} />
                                                                    }}
                                                                />
                                                            )
                                                        }
                                                    </div>
                                                </div>
                                                <div className='rightTable'>
                                                    <div className='tableToolbar'>
                                                        <div className='filter'>
                                                            {/* <div className='search' style={{ marginRight: 24 }}>
                                                        <span>类型：</span><Input className='searchInput' allowClear placeholder="请输入" onChange={(e) => {
                                                            set_tableDataSearchKeywords(e.target.value);
                                                            if (e.target.value.length == 0) {
                                                                set_tableDataFilterParams({
                                                                    ...tableDataFilterParams,
                                                                    itemType: ''
                                                                });
                                                            }
                                                        }} suffix={
                                                            <IconFont type="iconsousuo" onClick={() => tableDataSearchHandle('itemType')} />
                                                        } />
                                                    </div> */}
                                                            <div className='search'>
                                                                <span>项目名称：</span><Input className='searchInput' allowClear placeholder="请输入" onChange={(e) => {
                                                                    set_tableDataSearchKeywords(e.target.value);
                                                                    if (e.target.value.length == 0) {
                                                                        set_tableDataFilterParams({
                                                                            ...tableDataFilterParams,
                                                                            itemName: ''
                                                                        });
                                                                    }
                                                                }} suffix={
                                                                    <IconFont type="iconsousuo" onClick={() => tableDataSearchHandle('itemName')} />
                                                                } />
                                                            </div>
                                                        </div>
                                                        {
                                                            !ifBanAllAction && (
                                                                <Popover open={ifShowTip} content={'当前处于审核中，无法操作！'} >
                                                                    <div className={auditType == '1' || loading ? 'btnGroup disabled' : 'btnGroup'}
                                                                        onMouseEnter={() => auditType == '0' ? set_ifShowTip(false) : set_ifShowTip(true)}
                                                                        onMouseLeave={() => set_ifShowTip(false)}
                                                                    >
                                                                        <span key="1" onClick={auditType == '0' ? () => generateFunc('kpi_assessment', true) : () => { }}>获取单个</span>
                                                                        <span key="2" onClick={auditType == '0' ? () => generateFunc('kpi_assessment') : () => { }}>获取所有</span>
                                                                    </div>
                                                                </Popover>
                                                            )
                                                        }

                                                    </div>
                                                    {currentComputeDate && <BMSTable actionRef={tableRef} loading={{ spinning: loading, tip: '正在计算数据...' }} rowKey='id' params={tableDataFilterParams} columns={(auditType == '0' && !ifBanAllAction) ? [...tableColumn, {
                                                        title: '数值',
                                                        dataIndex: 'value',
                                                        key: 'value',

                                                        render: (text: any, record: any) => {

                                                            return (
                                                                <div key={'editCheckitem'} style={{ display: 'flex', flexDirection: 'row', width: '100%', justifyContent: 'flex-start', alignItems: 'center' }}>

                                                                    <div style={{ width: '80px', height: 16, display: 'flex', flexDirection: 'row', justifyContent: 'center', alignItems: 'center' }}>
                                                                        {
                                                                            editTableCellId == record.id ? <Input size='small' defaultValue={record.value} placeholder='请输入' onChange={(e) => { set_checkItemvalNum(Number(e.target.value)) }} style={{ width: '80px' }} /> : <span>{text}</span>
                                                                        }
                                                                    </div>
                                                                    <img onClick={() => editCheckItemValHandle(record)} style={{ width: 16, height: 16, cursor: 'pointer', marginLeft: 8 }} src={editTableCellId == record.id ? conformIcon : editIcon} alt="" />
                                                                </div>
                                                            )
                                                        }
                                                    },
                                                    {
                                                        title: '操作',
                                                        key: 'option',
                                                        valueType: 'option',
                                                        render: (_: any, record: any) => [
                                                            <Popconfirm
                                                                key={'del'}
                                                                title="是否确认删除？"
                                                                onConfirm={() => delActionHandle(record, 3)}
                                                                // onCancel={()=>{}}
                                                                okText="是"
                                                                cancelText="否"
                                                            >
                                                                <a >删除</a>
                                                            </Popconfirm>
                                                        ],
                                                    }] : [
                                                        ...tableColumn, {
                                                            title: '数值',
                                                            dataIndex: 'value',
                                                            key: 'value',

                                                        }
                                                    ]} request={(params, sort, filter) => getTableData('kpi_assessment', params, sort, filter)} />}
                                                </div>

                                            </div>

                                        </div>
                                    )
                                }
                                {
                                    currentSelectedTabKey == 'kpi_manage_indicator' && (
                                        <div className='tabContent'>
                                            <div className='tableToolbar'>
                                                <div className='filter'>
                                                    <div className='tabs'>
                                                        {
                                                            manaIndexGroups.map((item, index) => {
                                                                return (
                                                                    <Tooltip placement="top" title={item.depiction ? item.depiction : item.groupName}>
                                                                        <div key={index} className={currentSelectedManaGroup?.id == item.id ? 'tab on' : 'tab'} onClick={() => onManaIndexGroupClick(item)}>{item.groupName}</div>
                                                                    </Tooltip>
                                                                )
                                                            })
                                                        }

                                                    </div>
                                                    <div className='search'>
                                                        {/* <span>核算单元名称：</span><Input className='searchInput' allowClear placeholder="请输入" onChange={(e) => {
                                                    set_tableDataSearchKeywords(e.target.value);
                                                    if (e.target.value.length == 0) {
                                                        set_tableDataFilterParams({
                                                            ...tableDataFilterParams,
                                                            unitName: ''
                                                        });
                                                    }
                                                }} suffix={
                                                    <IconFont type="iconsousuo" onClick={() => tableDataSearchHandle()} />
                                                } /> */}
                                                    </div>
                                                </div>
                                                <Popover open={ifShowTip} content={'当前处于审核中，无法操作！'} placement='topRight'>
                                                    <div className={auditType == '1' ? 'btnGroup disabled' : 'btnGroup'}
                                                        onMouseEnter={() => auditType == '0' ? set_ifShowTip(false) : set_ifShowTip(true)}
                                                        onMouseLeave={() => set_ifShowTip(false)}
                                                    >
                                                        <span key="1" onClick={() => reCalcuteHandle()}>重算</span>
                                                        {importData('kpi_manage_indicator', '管理指标')}
                                                    </div>
                                                </Popover>
                                            </div>
                                            {currentComputeDate && tableColumn && <BMSTable className='BMS-ManaIndextable' rowClassName={() => 'BMS-ManaIndextable-row'} bordered actionRef={tableRef} scroll={{ x: (100 * (tableColumn.length - 2)) + 120 + 300, y: tableH }} rowKey='unitCode' columns={(auditType == '0' && !ifBanAllAction) ? [...tableColumn,
                                            {
                                                title: '操作',
                                                key: 'option',
                                                valueType: 'option',
                                                width: 100,

                                                fixed: 'right',
                                                render: (_: any, record: any) => [
                                                    <EditManaIndexTableRow record={record} key={'edit'} />
                                                ],
                                            }] : [...tableColumn]} pagination={false} params={tableDataFilterParams} request={(params, sort, filter) => getTableData('kpi_manage_indicator', params, sort, filter)} />}
                                        </div>
                                    )
                                }
                                {
                                    currentSelectedTabKey == 'kpi_income' && (
                                        <div className='tabContent' >
                                            <div className='tableToolbar'>
                                                <div className='filter'>
                                                    <div className='search'>
                                                        <span>项目名称：</span><Input className='searchInput' allowClear placeholder="请输入" onChange={(e) => {
                                                            set_tableDataSearchKeywords(e.target.value);
                                                            if (e.target.value.length == 0) {
                                                                set_tableDataFilterParams({
                                                                    ...tableDataFilterParams,
                                                                    itemName: ''
                                                                });
                                                            }
                                                        }} suffix={
                                                            <IconFont type="iconsousuo" onClick={() => tableDataSearchHandle('itemName')} />
                                                        } />
                                                    </div>
                                                </div>
                                                <Popover open={ifShowTip} content={'当前处于审核中，无法操作！'} placement='topRight'>
                                                    <div className={auditType == '1' ? 'btnGroup disabled' : 'btnGroup'}
                                                        onMouseEnter={() => auditType == '0' ? set_ifShowTip(false) : set_ifShowTip(true)}
                                                        onMouseLeave={() => set_ifShowTip(false)}
                                                    >
                                                        {/* <span key="1">获取</span> */}
                                                        {importData('kpi_income', '收入')}
                                                    </div>
                                                </Popover>
                                            </div>
                                            {currentComputeDate && <BMSTable actionRef={tableRef} rowKey='id' params={tableDataFilterParams} columns={tableColumn} request={(params, sort, filter) => getTableData('kpi_income', params, sort, filter)} />}
                                            <div className='totalCount'>合计：{totalNum}</div>
                                        </div>
                                    )
                                }
                                {
                                    currentSelectedTabKey == 'kpi_cost' && (
                                        <div className='tabContent'>
                                            <div className='tableToolbar'>
                                                <div className='filter'>
                                                    <div className='search'>
                                                        <span>项目名称：</span><Input className='searchInput' allowClear placeholder="请输入" onChange={(e) => {
                                                            set_tableDataSearchKeywords(e.target.value);
                                                            if (e.target.value.length == 0) {
                                                                set_tableDataFilterParams({
                                                                    ...tableDataFilterParams,
                                                                    itemName: ''
                                                                });
                                                            }
                                                        }} suffix={
                                                            <IconFont type="iconsousuo" onClick={() => tableDataSearchHandle('itemName')} />
                                                        } />
                                                    </div>
                                                </div>
                                                <Popover open={ifShowTip} content={'当前处于审核中，无法操作！'} placement='topRight'>
                                                    <div className={auditType == '1' ? 'btnGroup disabled' : 'btnGroup'}
                                                        onMouseEnter={() => auditType == '0' ? set_ifShowTip(false) : set_ifShowTip(true)}
                                                        onMouseLeave={() => set_ifShowTip(false)}
                                                    >
                                                        {/* <span key="1">获取</span> */}
                                                        {importData('kpi_cost', '成本')}
                                                    </div>
                                                </Popover>
                                            </div>
                                            {currentComputeDate && <BMSTable actionRef={tableRef} rowKey='id' params={tableDataFilterParams} columns={tableColumn} request={(params, sort, filter) => getTableData('kpi_cost', params, sort, filter)} />}
                                            <div className='totalCount'>合计：{totalNum}</div>
                                        </div>
                                    )
                                }
                                {
                                    currentSelectedTabKey == 'kpi_unit_cost' && (
                                        <div className='tabContent'>

                                            <div className='tabContentInner'>
                                                <div className='leftTree'>
                                                    <div className='search'>
                                                        <Input className='searchInput' allowClear onChange={onTreeSearchKeyChange} placeholder="请输入名称" suffix={
                                                            <IconFont type="iconsousuo" />
                                                        } />
                                                    </div>
                                                    <div className='treeWrap'>
                                                        {
                                                            treeData && treeData.length > 0 && currentSelectedTreeNode && (
                                                                <DirectoryTree
                                                                    fieldNames={{ title: 'name', key: 'code', children: 'child' }}
                                                                    rootStyle={{ height: '100%', paddingBottom: 50, overflowY: 'scroll', overflowX: 'hidden' }}
                                                                    onSelect={onSelectHandle}
                                                                    onExpand={onExpand}
                                                                    expandedKeys={expandedKeys}
                                                                    autoExpandParent={autoExpandParent}
                                                                    selectedKeys={[currentSelectedTreeNode.code]}
                                                                    blockNode={true}
                                                                    icon={() => null}
                                                                    titleRender={
                                                                        (nodeData: any) => {
                                                                            const strTitle = nodeData.name as string;
                                                                            const index = strTitle.indexOf(searchValue);
                                                                            const beforeStr = strTitle.substring(0, index);
                                                                            const afterStr = strTitle.slice(index + searchValue.length);
                                                                            const title =
                                                                                index > -1 ? (
                                                                                    <span>
                                                                                        {beforeStr}
                                                                                        <span className="site-tree-search-value" style={{ color: 'red', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{searchValue}</span>
                                                                                        {afterStr}
                                                                                    </span>
                                                                                ) : (
                                                                                    <span className='strTitle'>{strTitle}</span>
                                                                                );
                                                                            return <div style={{
                                                                                display: 'flex', flexDirection: 'row',
                                                                                width: '100%',
                                                                                justifyContent: 'flex-start', alignItems: 'center', height: 32,
                                                                                borderRadius: '4px',
                                                                                overflow: 'hidden',
                                                                                color: '#17181A',
                                                                                textOverflow: 'ellipsis',
                                                                                whiteSpace: 'nowrap'

                                                                            }}>{title}</div>
                                                                        }
                                                                    }
                                                                    defaultSelectedKeys={[treeData[0].child[0].code]}
                                                                    treeData={treeData as unknown as DataNode[]}
                                                                    // treeData={treeDataNew}
                                                                    switcherIcon={(props: any) => {
                                                                        const { expanded } = props;
                                                                        return !expanded ? <img style={{ width: 20, height: 20, position: 'relative', top: 5 }} src={expandedIcon} /> : <img style={{ width: 20, height: 20, position: 'relative', top: 5 }} src={closeIcon} />
                                                                    }}
                                                                />
                                                            )
                                                        }
                                                    </div>
                                                </div>
                                                <div className='rightTable'>
                                                    <div className='tableToolbar'>
                                                        <div className='filter'>
                                                            {/* <div className='search' style={{ marginRight: 24 }}>
                                                        <span>类型：</span><Input className='searchInput' allowClear placeholder="请输入" onChange={(e) => {
                                                            set_tableDataSearchKeywords(e.target.value);
                                                            if (e.target.value.length == 0) {
                                                                set_tableDataFilterParams({
                                                                    ...tableDataFilterParams,
                                                                    itemType: ''
                                                                });
                                                            }
                                                        }} suffix={
                                                            <IconFont type="iconsousuo" onClick={() => tableDataSearchHandle('itemType')} />
                                                        } />
                                                    </div> */}
                                                            <div className='search'>
                                                                <span>项目名称：</span><Input className='searchInput' allowClear placeholder="请输入" onChange={(e) => {
                                                                    set_tableDataSearchKeywords(e.target.value);
                                                                    if (e.target.value.length == 0) {
                                                                        set_tableDataFilterParams({
                                                                            ...tableDataFilterParams,
                                                                            itemName: ''
                                                                        });
                                                                    }
                                                                }} suffix={
                                                                    <IconFont type="iconsousuo" onClick={() => tableDataSearchHandle('itemName')} />
                                                                } />
                                                            </div>
                                                        </div>
                                                        <>
                                                            {/* <span className='compelted'>已分配总额: <i>{pageData.completedTotal}</i></span>
                                <span className='left'>剩余分配总额: <i>{pageData.leftTotal}</i></span> */}
                                                            <div className='count'><span className='compelted' style={{ display: 'inline-block', marginRight: 20 }}>总成本:<i>{formatMoneyNumber(Number(unitCostComputeData.unitCostTotal.toFixed(2)))}</i></span><span className='left'>可控成本:<i>{formatMoneyNumber(Number(unitCostComputeData.unitCostCtrlTotal.toFixed(2)))}</i></span></div>
                                                            {
                                                                !ifBanAllAction && (
                                                                    <Popover open={ifShowTip} content={'当前处于审核中，无法操作！'} >
                                                                        <div className={auditType == '1' || loading ? 'btnGroup disabled' : 'btnGroup'}
                                                                            onMouseEnter={() => auditType == '0' ? set_ifShowTip(false) : set_ifShowTip(true)}
                                                                            onMouseLeave={() => set_ifShowTip(false)}
                                                                        >
                                                                            <span key="1" onClick={auditType == '0' ? () => generateFunc('kpi_unit_cost', false) : () => { }}>获取</span>
                                                                            <>{importData('kpi_unit_cost', '单元成本')}</>
                                                                        </div>
                                                                    </Popover>
                                                                )
                                                            }

                                                        </>

                                                    </div>
                                                    {currentComputeDate && <BMSTable actionRef={tableRef} scroll={{ y: 666 }} loading={{ spinning: loading, tip: '正在获取数据...' }} rowKey='id' params={tableDataFilterParams} columns={[...tableColumn]} pagination={false} request={(params, sort, filter) => getTableData('kpi_unit_cost', params, sort, filter)} />}
                                                </div>

                                            </div>

                                        </div>
                                    )
                                }


                            </BMSPagecontainer>
                        </div>
                    )
                }
            </>

        </div>
    );

};

export default MonthlyDataCheck;

