/**
 * Ant Design Pro v4 use `@ant-design/pro-layout` to handle Layout.
 *
 * @see You can view component api by: https://github.com/ant-design/ant-design-pro-layout
 */
import type {
	MenuDataItem,
	BasicLayoutProps as ProLayoutProps,
	Settings
} from '@ant-design/pro-layout';
import ProLayout, { DefaultFooter } from '@ant-design/pro-layout';

import { Dropdown, Menu, Tabs, Tooltip } from 'antd';

import React, { Suspense, useEffect, useMemo, useRef, useState } from 'react';
import type { Dispatch, tabsRoute } from 'umi';
import { Link, connect, useIntl, history } from 'umi';
// import { GithubOutlined } from '@ant-design/icons';
import { Result, Button } from 'antd';
import Authorized from '@/utils/Authorized';
import RightContent from '@/components/GlobalHeader/RightContent';
import type { ConnectState } from '@/models/connect';
import { getMatchMenu } from '@umijs/route-utils';
import logo from '../assets/logo.png';
import './BasicLayout.less'
import PageLoading from '@/components/PageLoading';
import { SimplePageTransition } from '@/components/PageTransition';
import { DoubleRightOutlined } from '@ant-design/icons';
import * as Icon from '@ant-design/icons'
import IconFont from '@/components/IconFont';
import type { CurrentUser } from '@/models/user'
import session from '@/utils/session';
import upMenu from '../assets/tab/upMenu.png'
import { getFieldEnum, getFieldEnumTree, getFieldGetFieEnumList } from "@/services/options";
import { handleGetServerpartTree } from '@/pages/basicManage/serverpartAssets/service';
import list from '@/pages/Invoicing/list';


const { TabPane } = Tabs;

const noMatch = (
	<Result
		status={403}
		title="403"
		subTitle="Sorry, you are not authorized to access this page."
		extra={
			<Button type="primary">
				<Link to="/user/login">去登录</Link>
			</Button>
		}
	/>
);
export type BasicLayoutProps = {
	breadcrumbNameMap: Record<string, MenuDataItem>;
	route: ProLayoutProps['route'] & {
		authority: string[];
	};
	currentUser: CurrentUser | undefined;
	settings: Settings;
	dispatch: Dispatch;
	menuData: any;
	moduleMap: MenuDataItem[];
	tabsPanes: tabsRoute[];
} & ProLayoutProps;
export type BasicLayoutContext = { [K in 'location']: BasicLayoutProps[K] } & {
	breadcrumbNameMap: Record<string, MenuDataItem>;
};
/** Use Authorized check all menu item */

const defaultFooterDom = (
	<DefaultFooter
		style={{ background: "#f0f2f5" }}
		copyright={`Copyright © 2013-${new Date().getFullYear()} Eshang Cloud. All Rights Reserved. 驿商云 版权所有`}
	/>
);


const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
	const {
		dispatch,
		children,
		settings,
		currentUser,
		location = {
			pathname: '/',
		},
		menuData,
		moduleMap,
		tabsPanes,
	} = props;

	console.log('props', props);


	const [activeKey, setActiveKey] = useState<string>(location?.pathname || '/')
	const [isFromMenu, setIsFromMenu] = useState<boolean>(true) // 默认为true，首次加载显示动画
	const menuDataRef = useRef<MenuDataItem[]>([]);
	const { formatMessage } = useIntl();

	useEffect(() => {
		const sessiontUser = session.get("currentUser")
		/** 免登逻辑 */
		if (!currentUser && sessiontUser) {
			dispatch({ type: 'user/saveCurrentUser', payload: { ...sessiontUser } }) // 直接把seession赋值
			// 或者可以在这里做一次登录

		} else if (!currentUser && dispatch) {
			dispatch({
				type: 'user/fetch', callback: (user) => { // 登录超时 需要重新登录
					if (user.code && location.pathname !== '/user/login') {
						history.push('/user/login');
						return
					}
					dispatch({ type: 'global/getMenuData', payload: user.ID })
				}
			})
		}


	}, [currentUser, location, dispatch]);
	/** Init variables */
	// 用户行为记录
	const recordUserbeHavi = (record: { pathname: string, name: string }) => {
		if (dispatch) {
			// 用户行为记录
			const obj: any = {
				BEHAVIORRECORD_ROUT: record?.pathname,
				USER_ID: currentUser?.ID,
				USER_MOBILEPHONE: currentUser?.UserMobilephone,
				USER_PASSPORT: currentUser?.UserName,
				USER_NAME: currentUser?.Name,
				BEHAVIORRECORD_ROUTNAME: record.name,
				BEHAVIORRECORD_TIME: new Date()
			}
			dispatch({
				type: 'user/addUserRecord', payload: obj
			})
			session.set('moduleObj', obj)
		}
	}

	// 改变panes
	const handleTabsPanes = (payload: any): void => {
		if (dispatch) {
			dispatch({
				type: 'global/changeTabsRoutes',
				payload: { data: payload, action: 'add' },
			});
		}
	};


	// 关闭当前标签
	const handleEdit = (targetKey: string | React.MouseEvent<Element, MouseEvent> | React.KeyboardEvent<Element>, action: "add" | "remove"): void => {

		if (action === 'remove' && dispatch) {
			const index = tabsPanes.findIndex((n: { path: string }) => n.path === targetKey)

			// 定位关闭当前标签后，需要选中的下一个标签
			// eslint-disable-next-line no-nested-ternary
			const nextkey = tabsPanes[index + 1] ? tabsPanes[index + 1].path : (tabsPanes[index - 1] ? tabsPanes[index - 1].path : '')
			history.push(nextkey || '/')
			setActiveKey(nextkey)

			// 缓存路由栈数据
			dispatch({
				type: 'global/changeTabsRoutes',
				payload: { data: [targetKey], action },
			})

		}
	}
	const handleMenuCollapse = (payload: boolean): void => {
		if (dispatch) {
			dispatch({
				type: 'global/changeLayoutCollapsed',
				payload,
			});
		}
	};

	// get children authority
	const authorized = useMemo(
		() =>
			getMatchMenu(location.pathname || '/', menuDataRef.current).pop() || {
				authority: undefined,
			},
		[location.pathname],
	);

	// const testTime = ()=>{
	//   setTimeout(()=>{
	//     testTime()
	//   },60000)
	// }
	// useEffect(()=>{
	//   testTime()
	// },[])

	// 数组变成对象 可以取到中文名字
	const handleGetLabel = (list: any) => {
		const obj: any = {}
		list.forEach((item: any) => {
			obj[item.value] = item.label
		})
		return obj
	}

	// 把树形的数据 全部层级的value 和label都匹配上
	const flattenGrowthType = (list: any[], nameKey: string, valueKey: any) => {
		const result: Record<string, string> = {}

		function traverse(items: any[]) {
			items.forEach(item => {
				result[item[valueKey]] = item[nameKey]
				if (Array.isArray(item.children) && item.children.length > 0) {
					traverse(item.children)
				}
			})
		}

		traverse(list)
		return result
	}

	// 拿到所有枚举的方法
	const handleGetAllFieldEnum = async () => {
		// 景区状态
		getFieldEnumTree({ FieldExplainField: 'BUSINESSSTATE' }).then((BUSINESSSTATE: any) => {
			if (BUSINESSSTATE && BUSINESSSTATE.length > 0) {
				const obj: any = {}
				const list: any = []
				BUSINESSSTATE.forEach((item: any) => {
					list.push({ label: item.label, value: item.value })
					obj[item.value] = item.label
				})
				session.set('BUSINESSSTATEList', list);
				session.set('BUSINESSSTATEObj', obj);
				session.set('BUSINESSSTATETree', BUSINESSSTATE);
			}
		})

		// 景区类型
		getFieldEnumTree({ FieldExplainField: 'SCENICAREA_TYPE' }).then((SCENICAREATYPE: any) => {
			if (SCENICAREATYPE && SCENICAREATYPE.length > 0) {
				const obj: any = {}
				const list: any = []
				SCENICAREATYPE.forEach((item: any) => {
					list.push({ label: item.label, value: item.value })
					obj[item.value] = item.label
				})
				session.set('SCENICAREATYPEList', list);
				session.set('SCENICAREATYPEObj', obj);
				session.set('SCENICAREATYPETree', SCENICAREATYPE);
			}
		})

		// 承载情况
		getFieldEnumTree({ FieldExplainField: 'LOAD_BEARING' }).then((LOADBEARING: any) => {
			if (LOADBEARING && LOADBEARING.length > 0) {
				const obj: any = {}
				const list: any = []
				LOADBEARING.forEach((item: any) => {
					list.push({ label: item.label, value: item.value })
					obj[item.value] = item.label
				})
				session.set('LOADBEARINGList', list);
				session.set('LOADBEARINGObj', obj);
				session.set('LOADBEARINGTree', LOADBEARING);
			}
		})

		// 成长值规则类型
		getFieldEnumTree({ FieldExplainField: 'GROWTH_TYPE' }).then((GROWTHSETTINGTYPE: any) => {
			if (GROWTHSETTINGTYPE && GROWTHSETTINGTYPE.length > 0) {
				const obj: any = {}
				const list: any = []
				GROWTHSETTINGTYPE.forEach((item: any) => {
					list.push({ label: item.label, value: item.value })
					obj[item.value] = item.label
				})
				session.set('GROWTHSETTINGTYPEList', list);
				session.set('GROWTHSETTINGTYPEObj', obj);
				session.set('GROWTHSETTINGTYPETree', GROWTHSETTINGTYPE);
			}
		})


		// 品牌分类
		getFieldEnumTree({ FieldExplainField: 'BRAND_CATEGORY' }).then((BRANDCATEGORY: any) => {
			if (BRANDCATEGORY && BRANDCATEGORY.length > 0) {
				const obj: any = {}
				const list: any = []
				BRANDCATEGORY.forEach((item: any) => {
					list.push({ label: item.label, value: item.value })
					obj[item.value] = item.label
				})
				session.set('BRANDCATEGORYList', list);
				session.set('BRANDCATEGORYObj', obj);
				session.set('BRANDCATEGORYTree', BRANDCATEGORY);
			}
		})

		// 质量等级
		getFieldEnumTree({ FieldExplainField: 'COMMODITYGRADE' }).then((COMMODITYGRADE: any) => {
			if (COMMODITYGRADE && COMMODITYGRADE.length > 0) {
				const obj: any = {}
				const list: any = []
				COMMODITYGRADE.forEach((item: any) => {
					list.push({ label: item.label, value: item.value })
					obj[item.value] = item.label
				})
				session.set('COMMODITYGRADEList', list);
				session.set('COMMODITYGRADEObj', obj);
				session.set('COMMODITYGRADETree', COMMODITYGRADE);
			}
		})


		// 商品属性
		getFieldEnumTree({ FieldExplainField: 'COMMODITY_NATURE' }).then((COMMODITYNATURE: any) => {
			if (COMMODITYNATURE && COMMODITYNATURE.length > 0) {
				const obj: any = {}
				const list: any = []
				COMMODITYNATURE.forEach((item: any) => {
					list.push({ label: item.label, value: item.value })
					obj[item.value] = item.label
				})
				session.set('COMMODITYNATUREList', list);
				session.set('COMMODITYNATUREObj', obj);
				session.set('COMMODITYNATURETree', COMMODITYNATURE);
			}
		})

		// 消费模式
		getFieldEnumTree({ FieldExplainField: 'PAY_METHOD' }).then((PAYMETHOD: any) => {
			if (PAYMETHOD && PAYMETHOD.length > 0) {
				const obj: any = {}
				const list: any = []
				PAYMETHOD.forEach((item: any) => {
					list.push({ label: item.label, value: item.value })
					obj[item.value] = item.label
				})
				session.set('PAYMETHODList', list);
				session.set('PAYMETHODObj', obj);
				session.set('PAYMETHODTree', PAYMETHOD);
			}
		})


		// 消费类型
		getFieldEnumTree({ FieldExplainField: 'CONSUMPTIONRECORD_TYPE' }).then((CONSUMPTIONRECORDTYPE: any) => {
			if (CONSUMPTIONRECORDTYPE && CONSUMPTIONRECORDTYPE.length > 0) {
				const obj: any = {}
				const list: any = []
				CONSUMPTIONRECORDTYPE.forEach((item: any) => {
					list.push({ label: item.label, value: item.value })
					obj[item.value] = item.label
				})
				session.set('CONSUMPTIONRECORDTYPEList', list);
				session.set('CONSUMPTIONRECORDTYPEObj', obj);
				session.set('CONSUMPTIONRECORDTYPETree', CONSUMPTIONRECORDTYPE);
			}
		})


		// 商品税率
		getFieldEnumTree({ FieldExplainField: 'DUTY_PARAGRAPH' }).then((DUTYPARAGRAPH: any) => {
			if (DUTYPARAGRAPH && DUTYPARAGRAPH.length > 0) {
				const obj: any = {}
				const list: any = []
				DUTYPARAGRAPH.forEach((item: any) => {
					list.push({ label: item.label, value: item.value })
					obj[item.value] = item.label
				})
				session.set('DUTYPARAGRAPHList', list);
				session.set('DUTYPARAGRAPHObj', obj);
				session.set('DUTYPARAGRAPHTree', DUTYPARAGRAPH);
			}
		})



		// 会员类型的枚举
		// const MEMBERSHIPTYPE = 
		getFieldEnumTree({ FieldExplainField: 'MEMBERSHIP_TYPE' }).then((MEMBERSHIPTYPE: any) => {
			if (MEMBERSHIPTYPE && MEMBERSHIPTYPE.length > 0) {
				const obj: any = {}
				const list: any = []
				MEMBERSHIPTYPE.forEach((item: any) => {
					list.push({ label: item.label, value: item.value })
					obj[item.value] = item.label
				})
				session.set('MEMBERSHIP_TYPEList', list);
				session.set('MEMBERSHIP_TYPEObj', obj);
				session.set('MEMBERSHIP_TYPETree', MEMBERSHIPTYPE);
			}
		})



		// 会员等级的枚举
		// const MEMBERSHIPLEVEL = 
		getFieldEnumTree({ FieldExplainField: 'MEMBERSHIP_LEVEL' }).then((MEMBERSHIPLEVEL: any) => {
			if (MEMBERSHIPLEVEL && MEMBERSHIPLEVEL.length > 0) {
				const obj: any = {}
				const list: any = []
				MEMBERSHIPLEVEL.forEach((item: any) => {
					list.push({ label: item.label, value: item.value })
					obj[item.value] = item.label
				})
				session.set('MEMBERSHIP_LEVELList', list);
				session.set('MEMBERSHIP_LEVELObj', obj);
				session.set('MEMBERSHIP_LEVELTree', MEMBERSHIPLEVEL);
			}
		})



		// 会员状态的枚举
		// const COMPANYSTATE = 
		getFieldEnumTree({ FieldExplainField: 'COMPANY_STATE' }).then((COMPANYSTATE: any) => {
			if (COMPANYSTATE && COMPANYSTATE.length > 0) {
				const obj: any = {}
				const list: any = []
				COMPANYSTATE.forEach((item: any) => {
					list.push({ label: item.label, value: item.value })
					obj[item.value] = item.label
				})
				session.set('COMPANY_STATEList', list);
				session.set('COMPANY_STATEObj', obj);
				session.set('COMPANY_STATETree', COMPANYSTATE);
			}
		})



		// 结算模式数组
		// const SETTLEMENT_MODESList = await 
		getFieldEnum({ FieldExplainField: 'SETTLEMENT_MODES' }).then((SETTLEMENT_MODESList) => {
			session.set('SETTLEMENT_MODESList', SETTLEMENT_MODESList);
			// 结算模式对象
			if (SETTLEMENT_MODESList && SETTLEMENT_MODESList.length > 0) {
				const SETTLEMENT_MODESObj = handleGetLabel(SETTLEMENT_MODESList)
				session.set('SETTLEMENT_MODESObj', SETTLEMENT_MODESObj);
			}
		})

		// 卡券类型
		getFieldEnum({ FieldExplainField: 'COUPONTYPE' }).then((COUPONTYPEList) => {
			session.set('COUPONTYPEList', COUPONTYPEList);
			if (COUPONTYPEList && COUPONTYPEList.length > 0) {
				const COUPONTYPEObj = handleGetLabel(COUPONTYPEList)
				session.set('COUPONTYPEObj', COUPONTYPEObj);
			}
		})



		// 合同类型数组
		// const COMPACT_CHARACTERList = await  
		getFieldEnum({ FieldExplainField: 'COMPACT_CHARACTER' }).then((COMPACT_CHARACTERList) => {
			session.set('COMPACT_CHARACTERList', COMPACT_CHARACTERList);
			// 合同类型对象
			if (COMPACT_CHARACTERList && COMPACT_CHARACTERList.length > 0) {
				const COMPACT_CHARACTERObj = handleGetLabel(COMPACT_CHARACTERList)
				session.set('COMPACT_CHARACTERObj', COMPACT_CHARACTERObj);
			}
		})


		// 合同类型子项数组
		// const COMPACT_DETAILSList = await 
		getFieldEnum({ FieldExplainField: 'COMPACT_DETAILS' }).then(COMPACT_DETAILSList => {
			session.set('COMPACT_DETAILSList', COMPACT_DETAILSList);
			// 合同类型子项对象
			if (COMPACT_DETAILSList && COMPACT_DETAILSList.length > 0) {
				const COMPACT_DETAILSObj = handleGetLabel(COMPACT_DETAILSList)
				session.set('COMPACT_DETAILSObj', COMPACT_DETAILSObj);
			}
		})


		// 合同附属类型数组
		// const COMPACT_CHILDTYPEList = await 
		getFieldEnum({ FieldExplainField: "COMPACT_CHILDTYPE" }).then(COMPACT_CHILDTYPEList => {
			session.set('COMPACT_CHILDTYPEList', COMPACT_CHILDTYPEList);
			// 合同附属类型对象
			if (COMPACT_CHILDTYPEList && COMPACT_CHILDTYPEList.length > 0) {
				const COMPACT_CHILDTYPEObj = handleGetLabel(COMPACT_CHILDTYPEList)
				session.set('COMPACT_CHILDTYPEObj', COMPACT_CHILDTYPEObj);
			}
		})


		// 合同结算周期数组
		// const SETTLEMENT_CYCLEList = await 
		getFieldEnum({ FieldExplainField: 'SETTLEMENT_CYCLE' }).then(SETTLEMENT_CYCLEList => {
			session.set('SETTLEMENT_CYCLEList', SETTLEMENT_CYCLEList);
			// 合同结算周期对象
			if (SETTLEMENT_CYCLEList && SETTLEMENT_CYCLEList.length > 0) {
				const SETTLEMENT_CYCLEObj = handleGetLabel(SETTLEMENT_CYCLEList)
				session.set('SETTLEMENT_CYCLEObj', SETTLEMENT_CYCLEObj);
			}
		})


		// 合同类型数组
		// const COMPACT_TYPEList = await 
		getFieldEnum({ FieldExplainField: 'COMPACT_TYPE' }).then(COMPACT_TYPEList => {
			session.set('COMPACT_TYPEList', COMPACT_TYPEList);
			// 合同类型对象
			if (COMPACT_TYPEList && COMPACT_TYPEList.length > 0) {
				const COMPACT_TYPEObj = handleGetLabel(COMPACT_TYPEList)
				session.set('COMPACT_TYPEObj', COMPACT_TYPEObj);
			}
		})


		// 签订程序数组
		// const COMPACTREGPROINSTList = await
		getFieldEnum({ FieldExplainField: 'COMPACTREGPROINST' }).then(COMPACTREGPROINSTList => {
			session.set('COMPACTREGPROINSTList', COMPACTREGPROINSTList);
			// 合同类型对象
			if (COMPACTREGPROINSTList && COMPACTREGPROINSTList.length > 0) {
				const COMPACTREGPROINSTObj = handleGetLabel(COMPACTREGPROINSTList)
				session.set('COMPACTREGPROINSTObj', COMPACTREGPROINSTObj);
			}
		})


		// 所属区域数组
		// const shopregionList = await 
		getFieldEnum({ FieldExplainField: 'shopregion', notformate: true }).then(shopregionList => {
			session.set('shopregionList', shopregionList);
			// 合同类型对象
			if (shopregionList && shopregionList.length > 0) {
				const shopregionObj = handleGetLabel(shopregionList)
				session.set('shopregionObj', shopregionObj);
			}
		})


		// 经营模式
		// const BUSINESSTYPEList = await 
		getFieldEnum({ FieldExplainField: 'BUSINESS_TYPE' }).then(BUSINESSTYPEList => {
			session.set('BUSINESSTYPEList', BUSINESSTYPEList);
			// 合同类型对象
			if (BUSINESSTYPEList && BUSINESSTYPEList.length > 0) {
				const BUSINESSTYPEObj = handleGetLabel(BUSINESSTYPEList)
				session.set('BUSINESSTYPEObj', BUSINESSTYPEObj);
			}
		})



		// 商品业态
		// const SHOPTRADEList = await 
		getFieldEnum({ FieldExplainField: 'BUSINESSTYPE' }).then(SHOPTRADEList => {
			session.set('SHOPTRADEList', SHOPTRADEList);
			const SHOPTRADEObj: any = {}
			if (SHOPTRADEList && SHOPTRADEList.length > 0) {
				SHOPTRADEList.forEach((item: any) => {
					SHOPTRADEObj[item.value] = item.label
				})
			}
			session.set('SHOPTRADEObj', SHOPTRADEObj);
		})

		// 经营品牌
		// const BUSINESSBRANDList = await 

		getFieldEnumTree({ FieldExplainField: 'BusinessBrandIds', FieldEnumPID: null, noStorge: true }).then(BUSINESSBRANDList => {
			session.set('BUSINESSBRANDList', BUSINESSBRANDList);
			const BUSINESSBRANDObj: any = {}
			if (BUSINESSBRANDList && BUSINESSBRANDList.length > 0) {
				BUSINESSBRANDList.forEach((item: any) => {
					BUSINESSBRANDObj[item.value] = item.label
				})
			}
			session.set('BUSINESSBRANDObj', BUSINESSBRANDObj);
		})


		// 经营状态
		// const BUSINESSSTATEList = await 
		getFieldEnum({ FieldExplainField: 'BUSINESSSTATE' }).then(BUSINESSSTATEList => {
			session.set('businessStateList', BUSINESSSTATEList);
			const stateObj: any = {}
			if (BUSINESSSTATEList && BUSINESSSTATEList.length > 0) {
				BUSINESSSTATEList.forEach((item: any) => {
					stateObj[item.value] = item.label
				})
			}
			session.set('businessStateObj', stateObj);
		})



		// 品牌类型
		// const brandList = await 
		getFieldEnumTree({ FieldExplainField: 'BRAND_TYPE', sessionName: 'BRAND_TYPE' }).then(brandList => {
			const brandObj: any = {}
			if (brandList && brandList.length > 0) {
				brandList.forEach((item: any) => {
					brandObj[item.value] = item.label
				})
			}
			session.set('brandObj', brandObj);
			session.set('brandList', brandList);
		})


		// 服务区枚举
		// const ServerpartIdsList = await 
		getFieldEnumTree({ FieldExplainField: 'ServerpartIds' }).then(ServerpartIdsList => {
			const obj: any = {}
			if (ServerpartIdsList && ServerpartIdsList.length > 0) {
				ServerpartIdsList.forEach((item: any) => {
					obj[item.value] = item.label
				})
			}
			session.set('ServerpartIdsList', obj);
		})


		// 服务区类型
		// const serverpartTypeList = await 
		getFieldEnumTree({ FieldExplainField: 'SERVERPART_TYPE' }).then(serverpartTypeList => {
			const ServerpartTypeObj: any = {}
			if (serverpartTypeList && serverpartTypeList.length > 0) {
				serverpartTypeList.forEach((item: any) => {
					ServerpartTypeObj[item.value] = item.label
				})
			}
			session.set('serverpartTypeList', serverpartTypeList);
			session.set('ServerpartTypeObj', ServerpartTypeObj);
		})


		// 经营业态
		// const BusinessTradeIdsList = await 
		getFieldEnumTree({ FieldExplainField: 'BusinessTradeIds' }).then(BusinessTradeIdsList => {
			console.log('BusinessTradeIdsListBusinessTradeIdsListBusinessTradeIdsList', BusinessTradeIdsList);

			const BusinessTradeIdsObj: any = {}
			const BusinessTradeIdsBigObj: any = {}
			if (BusinessTradeIdsList && BusinessTradeIdsList.length > 0) {
				BusinessTradeIdsList.forEach((item: any) => {
					const childrenValue: any = []
					BusinessTradeIdsObj[item.value] = item.label
					BusinessTradeIdsBigObj[item.value] = item.label
					if (item.children && item.children.length > 0) {
						item.children.forEach((subItem: any) => {
							if (childrenValue.indexOf(subItem.value) === -1) {
								childrenValue.push(subItem.value)
							}
							BusinessTradeIdsObj[subItem.value] = subItem.label
						})
					}
					item.childrenValue = childrenValue
				})
			}
			session.set('BusinessTradeIdsObj', BusinessTradeIdsObj);
			session.set('BusinessTradeIdsChildrenList', BusinessTradeIdsList);
			session.set('BusinessTradeIdsBigObj', BusinessTradeIdsBigObj);
		})



		// 预警类型
		// const waringList = await 
		getFieldGetFieEnumList({ FieldexPlain_Field: 'WARNING_TYPE' }).then(waringList => {
			if (waringList && waringList.length > 0) {
				const list: any = []
				const obj: any = {}
				const descList: any = []
				const descObj: any = {}
				waringList.forEach((item: any) => {
					list.push({ label: item.FieldEnum_Name, value: item.FieldEnum_Value })
					obj[item.FieldEnum_Value] = item.FieldEnum_Name
					descList.push({ label: item.FieldEnum_Desc, value: item.FieldEnum_Value })
					descObj[item.FieldEnum_Value] = item.FieldEnum_Desc
				})
				session.set('waringList', list);
				session.set('waringObj', obj);
				session.set('waringDescList', descList);
				session.set('waringDescObj', descObj);
			}
		})

		// 业务类型
		// const PROCESS_TYPEList = await 
		getFieldEnumTree({ FieldExplainField: 'PROCESS_TYPE', sessionName: 'PROCESS_TYPE' }).then(PROCESS_TYPEList => {
			if (PROCESS_TYPEList && PROCESS_TYPEList.length > 0) {
				const obj: any = {}
				const list: any = []
				PROCESS_TYPEList.forEach((item: any) => {
					if (item.children && item.children.length > 0) {
						item.children.forEach((subItem: any) => {
							list.push({ label: subItem.label, value: subItem.value })
							obj[subItem.value] = subItem.label
						})
					}
				})
				session.set('PROCESS_TYPEList', list);
				session.set('PROCESS_TYPEObj', obj);
				session.set('PROCESS_TYPETree', PROCESS_TYPEList);
			}
		})

		// 服务区枚举
		// const serverpartList = await 
		handleGetServerpartTree({
			ProvinceCode: currentUser?.ProvinceCode,
			ServerpartType: 1000,
			StatisticsType: 1000,
			ShowWholePower: false,
			ShowSPRegion: false,
			ShowRoyalty: false,
			ShowCompactCount: false,
		}).then((serverpartList) => {
			if (serverpartList && serverpartList.length > 0) {
				session.set('serverpartList', serverpartList);
				const obj: any = {}
				serverpartList.forEach((item: any) => {
					obj[item.value] = item.label
				})
				session.set('serverpartObj', obj);
			}
		})
	}

	// 显示就调用
	useEffect(() => {
		handleGetAllFieldEnum()
		const timeInter = setInterval(() => {
			handleGetAllFieldEnum()
		}, 600000)
		return () => {
			clearInterval(timeInter)
		}
	}, [])

	return (
		<ProLayout
			logo={logo}
			// formatMessage={formatMessage}
			{...props}
			{...settings}
			onCollapse={handleMenuCollapse}
			// headerContentRender={() => <ProBreadcrumb />}
			onMenuHeaderClick={() => history.push('/')}
			menuDataRender={() =>
				menuData
			}

			subMenuItemRender={(menuItemProps) => {
				if (menuItemProps.icon && typeof menuItemProps.icon === 'string') {
					const ele = React.createElement(Icon[menuItemProps.icon])
					return <div className="ant-pro-menu-item">
						<span style={{ marginRight: 10 }} className="ant-pro-menu-item">{ele}</span>
						<span className='ant-pro-menu-item-title'>{menuItemProps.name}</span>
					</div>;
				}
				return <div>
					{menuItemProps.name}
				</div>;
			}}
			menuItemRender={(menuItemProps, defaultDom) => {
				if (
					menuItemProps.isUrl ||
					!menuItemProps.path ||
					location.pathname === menuItemProps.path
				) {
					return defaultDom;
				}
				return <Link to={menuItemProps.path || '/'} onClick={() => {
					setIsFromMenu(true) // 左侧菜单点击，启用动画
				}}>
					{defaultDom}
					{/* {menuItemProps.name} */}
				</Link>;
			}}
			breadcrumbRender={false}
			// breadcrumbRender={(routers = []) => {
			// 	return [
			// 		{
			// 			path: '/',
			// 			breadcrumbName: formatMessage({ id: 'menu.home' }),
			// 		},
			// 		...routers,
			// 	]
			// }}
			itemRender={(route, params, routes, paths) => {
				const first = routes.indexOf(route) === 0;
				return first ? (
					<Link to={paths.join('/')}>{route.breadcrumbName}</Link>
				) : (
					<span>{route.breadcrumbName}</span>
				);
			}}

			footerRender={() => {
				if (settings.footerRender || settings.footerRender === undefined) {
					return defaultFooterDom;
				}
				return null;
			}}

			rightContentRender={() => <RightContent />}
			onPageChange={(next) => {
				if (next?.pathname && next?.pathname !== '/') {
					let title = '驿商云平台'
					console.log('moduleMap', moduleMap);

					const nextModule = moduleMap.find(n => next?.pathname && n?.path && next?.pathname.match(n?.path))
					if (nextModule) {
						// `${formatMessage({ id: `menu${title.substring(0, title?.indexOf('.detail'))}` })}详情`
						title = next?.pathname.indexOf('.detail') > -1 ? `${nextModule.name}详情` : (nextModule?.name || '')
					} else if (next?.pathname.indexOf('/detail') > -1) {
						const path = next?.pathname.substring(0, next?.pathname?.indexOf('/detail'))

						const nextDetailModule = moduleMap.find(n => n.path === path)
						if (nextDetailModule) {
							title = `${nextDetailModule.name}详情`
						}
					}
					recordUserbeHavi({ pathname: next?.pathname, name: nextModule ? title : '' })
					session.set('currentMenu', { pathname: next?.pathname, name: nextModule ? title : '' })

					handleTabsPanes({ path: next?.pathname, key: next?.pathname, title, children })
					setActiveKey(next?.pathname || '')
				}
				else {
					recordUserbeHavi({ pathname: next?.pathname || '/', name: '空白页' })
					session.set('currentMenu', { pathname: next?.pathname || '/', name: '空白页' })
				}
			}}
		>
			<Tabs
				hideAdd
				type="editable-card"
				onChange={(value) => {
					setIsFromMenu(false) // tab切换，禁用动画
					history.push(value)
					setActiveKey(value)
				}}
				activeKey={activeKey}
				onEdit={handleEdit}
				size="small"
				className='main-tab'

				tabBarExtraContent={
					<Tooltip title="关闭选项卡" placement="topRight">
						<Dropdown overlay={
							<Menu onClick={(targetKey) => {
								let closeTabKeys: string[] = []
								switch (targetKey.key) {
									case 'other':
										closeTabKeys = [...tabsPanes.filter(n => n.path !== activeKey).map(n => n.path)];
										break;
									case 'now':
										handleEdit(activeKey, 'remove')
										return;
									default:
										closeTabKeys = [...tabsPanes.map(n => n.path)];
										history.push('/')
										break;
								}

								dispatch({
									type: 'global/changeTabsRoutes',
									payload: { data: closeTabKeys, action: 'remove' },
								})
							}}>
								<Menu.Item key="other">关闭其他标签</Menu.Item>
								<Menu.Item key="now">关闭当前标签</Menu.Item>
								<Menu.Item key="all">关闭全部标签</Menu.Item>
							</Menu>
						}
							trigger={['click']}
							placement="bottomRight"
							// visible={tabVisible}
							arrow>

							<div onClick={(e) => {
								e.preventDefault()

							}}>

								<img style={{ width: '20px', height: '20px', cursor: 'pointer' }} src={upMenu} />
								{/* <IconFont className="tab-extra" name="icon-basic-down" size="14" style={{ color: '#404040' }}></IconFont> */}
							</div>
							{/* <DownOutlined style={{color:"#7b828c"}} /> */}
						</Dropdown >
					</Tooltip>
				}
				moreIcon={<DoubleRightOutlined style={{ color: "#7b828c" }} />}
			>
				{tabsPanes && tabsPanes.map((item: tabsRoute) =>
					<TabPane
						tab={item.title} key={item?.path}
						style={{ padding: 24, paddingTop: 0 }}>
						<Suspense fallback={<PageLoading enableAnimation={isFromMenu} />}>
							<Authorized authority={authorized!.authority} noMatch={noMatch}>
								<SimplePageTransition enableAnimation={isFromMenu}>
									{item.children}
								</SimplePageTransition>
							</Authorized>
						</Suspense>
					</TabPane>)
				}
			</Tabs>
			{/* 不要标签栏，删除tabs的代码，使用下方的代码就可以 */}
			{/* <Authorized authority={authorized!.authority} noMatch={noMatch}>
				<div style={{ padding: 24 }}>
					{tabsPanes.length > 0 && tabsPanes[tabsPanes.length - 1].children}
				</div>
			</Authorized> */}
		</ProLayout >
	);
};

export default connect(({ global, settings, user }: ConnectState) => ({
	collapsed: global.collapsed,
	tabsPanes: global.tabsRoutes,
	menuData: global.menuData,
	moduleMap: global.moduleMap,
	currentUser: user.currentUser,
	settings,
}))(BasicLayout);
