import { ViewTool } from '@/utils';

/**
 * PIM 部件模型
 *
 * @export
 * @class PIMModel
 */
export default class PIMModel {

    /**
     * 菜单项集合
     *
     * @private
     * @type {any[]}
     * @memberof PIMModel
     */
    private items: any[] = [
                {
        	id: '74769e4fae4abae779fa5e1d71bef05d',
        	name: 'user_menus',
        	text: '用户菜单',
        	type: 'MENUITEM',
        	counterid: '',
        	tooltip: '用户菜单',
        	expanded: false,
        	separator: false,
        	hidden: false,
        	hidesidebar: false,
        	opendefault: false,
        	iconcls: '',
        	icon: '',
        	textcls: '',
        	appfunctag: '',
        	resourcetag: '',
        	items: [
                		        {
                	id: '5b9d13aef24ebeec49af943db98b35cb',
                	name: 'menuitem3',
                	text: '设置',
                	type: 'MENUITEM',
                	counterid: '',
                	tooltip: '设置',
                	expanded: false,
                	separator: false,
                	hidden: false,
                	hidesidebar: false,
                	opendefault: false,
                	iconcls: 'fa fa-cog',
                	icon: '',
                	textcls: '',
                	appfunctag: '',
                	resourcetag: '',
                }
                ,
        	],
        }
        ,
                {
        	id: '3191ef144a2b66a82edce66de7461bd5',
        	name: 'top_menus',
        	text: '顶部菜单',
        	type: 'MENUITEM',
        	counterid: '',
        	tooltip: '顶部菜单',
        	expanded: false,
        	separator: false,
        	hidden: false,
        	hidesidebar: false,
        	opendefault: false,
        	iconcls: '',
        	icon: '',
        	textcls: '',
        	appfunctag: '',
        	resourcetag: '',
        	items: [
                		        {
                	id: 'A8D78DD5-209F-4ADF-8B05-72F646DFCECD',
                	name: 'menuitem1',
                	text: '-',
                	type: 'MENUITEM',
                	counterid: '',
                	tooltip: '-',
                	expanded: false,
                	separator: false,
                	hidden: false,
                	hidesidebar: false,
                	opendefault: false,
                	iconcls: '',
                	icon: '',
                	textcls: '',
                	appfunctag: '',
                	resourcetag: '',
                }
                ,
        	],
        }
        ,
                {
        	id: 'dfc129d27761fa5213b01cda5ee15778',
        	name: 'left_exp',
        	text: '左侧菜单',
        	type: 'MENUITEM',
        	counterid: '',
        	tooltip: '左侧菜单',
        	expanded: false,
        	separator: false,
        	hidden: false,
        	hidesidebar: false,
        	opendefault: false,
        	iconcls: '',
        	icon: '',
        	textcls: '',
        	appfunctag: '',
        	resourcetag: '',
        	items: [
                		        {
                	id: '1F73FB8E-0E2A-4B7A-B800-004B01AB2301',
                	name: 'menuitem5',
                	text: '人员',
                	type: 'MENUITEM',
                	counterid: '',
                	tooltip: '人员',
                	expanded: false,
                	separator: false,
                	hidden: false,
                	hidesidebar: false,
                	opendefault: false,
                	iconcls: 'fa fa-users',
                	icon: '',
                	textcls: '',
                	appfunctag: '',
                	resourcetag: '',
                	items: [
                        		        {
                        	id: '4b24bf3dc681c591cb1663ce8853cc32',
                        	name: 'menuitem15',
                        	text: '员工信息',
                        	type: 'MENUITEM',
                        	counterid: '',
                        	tooltip: '员工信息',
                        	expanded: false,
                        	separator: false,
                        	hidden: false,
                        	hidesidebar: false,
                        	opendefault: false,
                        	iconcls: 'fa fa-user',
                        	icon: '',
                        	textcls: '',
                        	appfunctag: '_4',
                        	appfuncyype: 'APPVIEW',
                        	viewname: 'hremployee-grid-view',
                        	resourcetag: '',
                        }
                        ,
                	],
                }
                ,
                		        {
                	id: 'B25E7335-DEBD-478A-81FD-1BB47B68DFA4',
                	name: 'menuitem2',
                	text: '组织',
                	type: 'MENUITEM',
                	counterid: '',
                	tooltip: '组织',
                	expanded: false,
                	separator: false,
                	hidden: false,
                	hidesidebar: false,
                	opendefault: false,
                	iconcls: 'fa fa-sitemap',
                	icon: '',
                	textcls: '',
                	appfunctag: '',
                	resourcetag: '',
                	items: [
                        		        {
                        	id: '98B816C8-2AA6-4BB4-9CC5-C2B72A61C24B',
                        	name: 'menuitem4',
                        	text: '法人',
                        	type: 'MENUITEM',
                        	counterid: '',
                        	tooltip: '法人',
                        	expanded: false,
                        	separator: false,
                        	hidden: false,
                        	hidesidebar: false,
                        	opendefault: false,
                        	iconcls: 'fa fa-shirtsinbulk',
                        	icon: '',
                        	textcls: '',
                        	appfunctag: '_2',
                        	appfuncyype: 'APPVIEW',
                        	viewname: 'hrlegal-grid-view',
                        	resourcetag: '',
                        }
                        ,
                        		        {
                        	id: '7950AF8B-457E-4B66-9E43-48FA95ED5A0C',
                        	name: 'menuitem6',
                        	text: '运营单位',
                        	type: 'MENUITEM',
                        	counterid: '',
                        	tooltip: '运营单位',
                        	expanded: false,
                        	separator: false,
                        	hidden: false,
                        	hidesidebar: false,
                        	opendefault: false,
                        	iconcls: 'fa fa-building-o',
                        	icon: '',
                        	textcls: '',
                        	appfunctag: '_3',
                        	appfuncyype: 'APPVIEW',
                        	viewname: 'hroperation-unit-grid-view',
                        	resourcetag: '',
                        }
                        ,
                        		        {
                        	id: '8BCD342D-9983-4932-85AF-C31662BCE75A',
                        	name: 'menuitem7',
                        	text: '组织层次结构',
                        	type: 'MENUITEM',
                        	counterid: '',
                        	tooltip: '组织层次结构',
                        	expanded: false,
                        	separator: false,
                        	hidden: false,
                        	hidesidebar: false,
                        	opendefault: false,
                        	iconcls: 'fa fa-signal',
                        	icon: '',
                        	textcls: '',
                        	appfunctag: '_9',
                        	appfuncyype: 'APPVIEW',
                        	viewname: 'hromhierarchy-cat-grid-view',
                        	resourcetag: '',
                        }
                        ,
                        		        {
                        	id: 'F4927234-CF7B-44BA-AECC-24318EF8B794',
                        	name: 'menuitem9',
                        	text: '所有组织',
                        	type: 'MENUITEM',
                        	counterid: '',
                        	tooltip: '所有组织',
                        	expanded: false,
                        	separator: false,
                        	hidden: false,
                        	hidesidebar: false,
                        	opendefault: false,
                        	iconcls: 'fa fa-sitemap',
                        	icon: '',
                        	textcls: '',
                        	appfunctag: '_8',
                        	appfuncyype: 'APPVIEW',
                        	viewname: 'hrorganization-grid-view',
                        	resourcetag: '',
                        }
                        ,
                	],
                }
                ,
                		        {
                	id: 'E065C1FE-A872-4209-A254-67DE568A5F43',
                	name: 'menuitem10',
                	text: '职位',
                	type: 'MENUITEM',
                	counterid: '',
                	tooltip: '职位',
                	expanded: false,
                	separator: false,
                	hidden: false,
                	hidesidebar: false,
                	opendefault: false,
                	iconcls: 'fa fa-server',
                	icon: '',
                	textcls: '',
                	appfunctag: '',
                	resourcetag: '',
                	items: [
                        		        {
                        	id: 'F40EFB9B-4A24-45F2-8CD1-BD9CFD890109',
                        	name: 'menuitem11',
                        	text: '职位',
                        	type: 'MENUITEM',
                        	counterid: '',
                        	tooltip: '职位',
                        	expanded: false,
                        	separator: false,
                        	hidden: false,
                        	hidesidebar: false,
                        	opendefault: false,
                        	iconcls: 'fa fa-delicious',
                        	icon: '',
                        	textcls: '',
                        	appfunctag: '_6',
                        	appfuncyype: 'APPVIEW',
                        	viewname: 'hrpost-tab-exp-view',
                        	resourcetag: '',
                        }
                        ,
                        		        {
                        	id: '5866C16B-4C55-4E2C-8229-15F7533B9E4F',
                        	name: 'menuitem12',
                        	text: '职务',
                        	type: 'MENUITEM',
                        	counterid: '',
                        	tooltip: '职务',
                        	expanded: false,
                        	separator: false,
                        	hidden: false,
                        	hidesidebar: false,
                        	opendefault: false,
                        	iconcls: 'fa fa-bars',
                        	icon: '',
                        	textcls: '',
                        	appfunctag: '_5',
                        	appfuncyype: 'APPVIEW',
                        	viewname: 'hrduty-grid-view',
                        	resourcetag: '',
                        }
                        ,
                        		        {
                        	id: 'ED02F38F-5988-4458-95BB-75F91E922110',
                        	name: 'menuitem8',
                        	text: '测试',
                        	type: 'MENUITEM',
                        	counterid: '',
                        	tooltip: '测试',
                        	expanded: false,
                        	separator: false,
                        	hidden: false,
                        	hidesidebar: false,
                        	opendefault: false,
                        	iconcls: '',
                        	icon: '',
                        	textcls: '',
                        	appfunctag: '_7',
                        	appfuncyype: 'APPVIEW',
                        	viewname: 'hromhierarchy-grid-view',
                        	resourcetag: '',
                        }
                        ,
                	],
                }
                ,
        	],
        }
        ,
                {
        	id: 'fec63a28f5d99fd4ac7e43004b6a16f8',
        	name: 'bottom_exp',
        	text: '底部内容',
        	type: 'MENUITEM',
        	counterid: '',
        	tooltip: '底部内容',
        	expanded: false,
        	separator: false,
        	hidden: false,
        	hidesidebar: false,
        	opendefault: false,
        	iconcls: '',
        	icon: '',
        	textcls: '',
        	appfunctag: '',
        	resourcetag: '',
        }
        ,
                {
        	id: '5055aa1daf0c26ad0615bf59b899dac6',
        	name: 'footer_left',
        	text: '底部左侧',
        	type: 'MENUITEM',
        	counterid: '',
        	tooltip: '底部左侧',
        	expanded: false,
        	separator: false,
        	hidden: false,
        	hidesidebar: false,
        	opendefault: false,
        	iconcls: '',
        	icon: '',
        	textcls: '',
        	appfunctag: '',
        	resourcetag: '',
        }
        ,
                {
        	id: '543d8997967e967da007eba50c2c8ba1',
        	name: 'footer_center',
        	text: '底部中间',
        	type: 'MENUITEM',
        	counterid: '',
        	tooltip: '底部中间',
        	expanded: false,
        	separator: false,
        	hidden: false,
        	hidesidebar: false,
        	opendefault: false,
        	iconcls: '',
        	icon: '',
        	textcls: '',
        	appfunctag: '',
        	resourcetag: '',
        }
        ,
                {
        	id: '6afec0593769e90bdf8be1d490367306',
        	name: 'footer_right',
        	text: '底部右侧',
        	type: 'MENUITEM',
        	counterid: '',
        	tooltip: '底部右侧',
        	expanded: false,
        	separator: false,
        	hidden: false,
        	hidesidebar: false,
        	opendefault: false,
        	iconcls: '',
        	icon: '',
        	textcls: '',
        	appfunctag: '',
        	resourcetag: '',
        }
        ,
    ];

	/**
	 * 应用功能集合
	 *
	 * @private
	 * @type {any[]}
	 * @memberof PIMModel
	 */
	private funcs: any[] = [
        {
            appfunctag: '_8',
            appfuncyype: 'APPVIEW',
            openmode: '',
            codename: 'hrorganizationgridview',
            deResParameters: [],
            routepath: '/pim/:pim?/hrorganizations/:hrorganization?/gridview/:gridview?',
            parameters: [
                { pathName: 'hrorganizations', parameterName: 'hrorganization' },
                { pathName: 'gridview', parameterName: 'gridview' },
            ],
        },
        {
            appfunctag: '_3',
            appfuncyype: 'APPVIEW',
            openmode: '',
            codename: 'hroperationunitgridview',
            deResParameters: [],
            routepath: '/pim/:pim?/hroperationunits/:hroperationunit?/gridview/:gridview?',
            parameters: [
                { pathName: 'hroperationunits', parameterName: 'hroperationunit' },
                { pathName: 'gridview', parameterName: 'gridview' },
            ],
        },
        {
            appfunctag: '_2',
            appfuncyype: 'APPVIEW',
            openmode: '',
            codename: 'hrlegalgridview',
            deResParameters: [],
            routepath: '/pim/:pim?/hrlegals/:hrlegal?/gridview/:gridview?',
            parameters: [
                { pathName: 'hrlegals', parameterName: 'hrlegal' },
                { pathName: 'gridview', parameterName: 'gridview' },
            ],
        },
        {
            appfunctag: '_4',
            appfuncyype: 'APPVIEW',
            openmode: '',
            codename: 'hremployeegridview',
            deResParameters: [],
            routepath: '/pim/:pim?/hremployees/:hremployee?/gridview/:gridview?',
            parameters: [
                { pathName: 'hremployees', parameterName: 'hremployee' },
                { pathName: 'gridview', parameterName: 'gridview' },
            ],
        },
        {
            appfunctag: '_6',
            appfuncyype: 'APPVIEW',
            openmode: '',
            codename: 'hrposttabexpview',
            deResParameters: [],
            routepath: '/pim/:pim?/hrposts/:hrpost?/tabexpview/:tabexpview?',
            parameters: [
                { pathName: 'hrposts', parameterName: 'hrpost' },
                { pathName: 'tabexpview', parameterName: 'tabexpview' },
            ],
        },
        {
            appfunctag: '_9',
            appfuncyype: 'APPVIEW',
            openmode: '',
            codename: 'hromhierarchycatgridview',
            deResParameters: [],
            routepath: '/pim/:pim?/hromhierarchycats/:hromhierarchycat?/gridview/:gridview?',
            parameters: [
                { pathName: 'hromhierarchycats', parameterName: 'hromhierarchycat' },
                { pathName: 'gridview', parameterName: 'gridview' },
            ],
        },
        {
            appfunctag: '_5',
            appfuncyype: 'APPVIEW',
            openmode: '',
            codename: 'hrdutygridview',
            deResParameters: [],
            routepath: '/pim/:pim?/hrduties/:hrduty?/gridview/:gridview?',
            parameters: [
                { pathName: 'hrduties', parameterName: 'hrduty' },
                { pathName: 'gridview', parameterName: 'gridview' },
            ],
        },
        {
            appfunctag: '_7',
            appfuncyype: 'APPVIEW',
            openmode: '',
            codename: 'hromhierarchygridview',
            deResParameters: [],
            routepath: '/pim/:pim?/hromhierarchies/:hromhierarchy?/gridview/:gridview?',
            parameters: [
                { pathName: 'hromhierarchies', parameterName: 'hromhierarchy' },
                { pathName: 'gridview', parameterName: 'gridview' },
            ],
        },
	];

	/**
	 * 根据当前路由查找激活菜单
	 *
	 * @param {*} route
	 * @returns {*}
	 * @memberof PIMModel
	 */
	public findActiveMenuByRoute(route: any): any {
		if (route) {
			const func = this.funcs.find((item: any) => {
				if (item.openmode === '') {
					const url: string = ViewTool.buildUpRoutePath(route, route.params, [], item.parameters, [], {});
					return url === route.fullPath;
				}
			});
            if (func) {
			    return this.findMenuByFuncTag(func.appfunctag);
            }
		}
	}

	/**
	 * 根据应用功能id查找菜单项
	 *
	 * @param {string} tag
	 * @param {any[]} [menus=this.items]
	 * @returns {*}
	 * @memberof PIMModel
	 */
	public findMenuByFuncTag(tag: string, menus: any[] = this.items): any {
		let menu: any;
		menus.every((item: any) => {
			if (item.appfunctag === tag) {
				menu = item;
				return false;
			}
			if (item.items) {
				menu = this.findMenuByFuncTag(tag, item.items);
				if (menu) {
					return false;
				}
			}
			return true;
		});
		return menu;
	}

	/**
	 * 查找默认打开菜单
	 *
	 * @param {any[]} [menus=this.items]
	 * @returns {*}
	 * @memberof PIMModel
	 */
	public findDefaultOpenMenu(menus: any[] = this.items): any {
		let menu: any;
		menus.every((item: any) => {
			if (item.opendefault === true) {
				menu = item;
				return false;
			}
			if (item.items) {
				menu = this.findMenuByFuncTag(item.items);
				if (menu) {
					return false;
				}
			}
			return true;
		});
		return menu;
	}

    /**
     * 获取所有菜单项集合
     *
     * @returns {any[]}
     * @memberof PIMModel
     */
    public getAppMenuItems(): any[] {
        return this.items;
    }

	/**
	 * 根据名称获取菜单组
	 *
	 * @param {string} name
	 * @returns {*}
	 * @memberof PIMModel
	 */
	public getMenuGroup(name: string): any {
		return this.items.find((item: any) => Object.is(item.name, name));
	}

    /**
     * 获取所有应用功能集合
     *
     * @returns {any[]}
     * @memberof PIMModel
     */
    public getAppFuncs(): any[] {
        return this.funcs;
    }
}