import Vue from "vue";
import VueRouter from "vue-router";

if (process.env.NODE_ENV === "development") {
    Vue.use(VueRouter);
}

import {ROUTER_MODE} from "../config/app";
import Home from "../views/home/index.vue";
import Empty from "../views/home/Empty.vue";
import showText from "../views/utils/showText";

// 权限管理相关
import authAdmin from "../views/userManage/admin/authAdmin.vue";
import authRole from "../views/userManage/admin/authRole.vue";
import authPermissionRule from "../views/userManage/admin/authPermissionRule.vue";
import systemParamConfig from "../views/userManage/param/systemParamConfig.vue";
import registerManage from "../views/userManage/registerManage.vue";
import customerManage from "../views/userManage/customerManage.vue";
import systemPDFTemplate from "../views/userManage/param/systemPDFTemplate";
import systemPDFModule from "../views/userManage/param/systemPDFModule";
import platform from "../views/userManage/platform.vue";
import userAccountManage from "@/views/userManage/userAccountManage";

//单据
import stockOrderDelSearch from "../views/warehouse/stockOrderDelSearch";
import stockOrderSearch from "../views/warehouse/stockOrderSearch";
import stockOrderDelete from "../views/warehouse/stockOrderDelete";

//往来单位字典
import UnitManage from "@/views/product/UnitManage";

//关联自助平台
import bindPlatform from "@/views/sys/bindPlatform";

//菜单管理
import company from "../views/warehouse/company.vue";
import inout from "../views/warehouse/ioFinishOrder.vue";
import ioUdiTrace from "../views/warehouse/ioUdiTrace.vue";

import ioNew from "../views/warehouse/ioNewOrder.vue";
import errorOrder from "../views/warehouse/ioErrorOrder.vue";
import BussinessType from "../views/basic/BussinessType.vue";

//基础数据维护
import invWarehouse from "../views/basic/invWarehouse";
import UdiInfoManage from "../views/basic/UdiInfoManage.vue";

//库存
import invProducts from "../views/warehouse/InvProducts.vue";
import bussinessType from "@/views/basic/BussinessType";
import additionalOrder from "@/views/warehouse/AdditionalOrder";

//设备管理
import phoneRegisterManage from "@/views/userManage/phoneRegisterManage";


const err401 = r =>
    require.ensure([], () => r(require("../views/error/err401.vue")), "home");

const register = r =>
    require.ensure([], () => r(require("../views/userManage/register.vue")), "home");

const registerApp = r =>
    require.ensure([], () => r(require("../views/userManage/registerApp.vue")), "home");

const forgetPasswd = r =>
    require.ensure([], () => r(require("../views/userManage/forgetPasswd.vue")), "home");

const err404 = r =>
    require.ensure([], () => r(require("../views/error/err404.vue")), "home");
const login = r =>
    require.ensure([], () => r(require("../views/login/index.vue")), "home");
const main = r =>
    require.ensure([], () => r(require("../views/home/main.vue")), "home");

// 注意 权限字段 authRule （严格区分大小写）
export const constantRouterMap = [
    {
        path: "*",
        component: err404,
        hidden: true
    },
    {
        path: "/401",
        component: err401,
        name: "401",
        hidden: true
    },
    {
        path: "/404",
        component: err404,
        name: "404",
        hidden: true
    },
    {
        path: "/500",
        component: err404,
        name: "500",
        hidden: true
    },

    {
        path: "/login",
        component: login,
        name: "登录",
        hidden: true
    },
    {
        path: "/register",
        component: register,
        name: "注册",
        hidden: true
    },
    {
        path: "/registerApp",
        component: registerApp,
        name: "注册",
        hidden: true
    },

    {
        path: "/forgetPasswd",
        component: forgetPasswd,
        name: "忘记密码",
        hidden: true
    },


    {
        path: "/",
        icon: "shouye",
        component: Home,
        redirect: "main",
        name: "首页",
        hidden: true,
        noDropdown: true,
        children: [
            {
                path: "main",
                component: main,
                name: "首页"
            }
        ]
    },

    {
        path: "/",
        icon: "showText",
        component: showText,
        redirect: "showText",
        name: "文本",
        hidden: true,
        noDropdown: true,
        children: [
            {
                path: "showText",
                component: showText,
                name: "文本"
            }
        ]
    }


];

export default new VueRouter({
    // mode: 'history', //后端支持可开
    mode: ROUTER_MODE,
    routes: constantRouterMap,
    strict: process.env.NODE_ENV !== "production"
});

export const asyncRouterMap = [

    {
        path: "/userManage",
        redirect: "/userManage/adminManage/index",
        component: Home,
        icon: "guanliyuan1",
        name: "后台管理",
        hidden: false,
        meta: {
            authRule: ["backstage_manage"]
        },

        // noDropdown: true,
        children: [
            {
                path: "/permissionManage",
                component: Empty,
                redirect: "/permissionManage/permissionConfig",
                name: "权限管理",
                icon: "",
                meta: {
                    authRule: ["permission_manage"]
                },
                children: [
                    {
                        path: "authAdmin",
                        component: authAdmin,
                        name: "用户管理",
                        icon: "",
                        meta: {
                            authRule: ["admin/auth_admin"]
                        }
                    },
                    {
                        path: "authRole",
                        component: authRole,
                        name: "角色权限",
                        icon: "",
                        meta: {
                            authRule: ["admin/auth_role"]
                        }
                    },
                    {
                        path: "authPermissionRule",
                        component: authPermissionRule,
                        name: "功能管理",
                        icon: "",
                        meta: {
                            authRule: ["admin/auth_permission_rule"]
                        }
                    },
                ]

            },
            {
                path: "phoneRegisterManage",
                component: phoneRegisterManage,
                name: "设备管理",
                meta: {
                    authRule: ["deviceManage/phoneRegisterManage"]
                }
            },
            {
                path: "systemPDFTemplate/template",
                component: systemPDFTemplate,
                name: "打印模板",
                icon: "",
                meta: {
                    authRule: ["systemParam/systemPDFTemplate"]
                },
            },
            {
                path: "/enterpriseManage",
                component: Empty,
                name: "企业管理",
                redirect: "/enterpriseManage/enterpriseManage/index",
                icon: "",
                meta: {
                    authRule: ["enterpriseManage/enterpriseManageConfig"]
                },
                children: [
                    {
                        path: "registerManage",
                        component: registerManage,
                        name: "企业注册审核",
                        icon: "",
                        meta: {
                            authRule: ["enterprise/registerManage"]
                        }
                    },
                    {
                        path: "customerManage",
                        component: customerManage,
                        name: "企业信息管理",
                        icon: "",
                        meta: {
                            authRule: ["enterprise/customerManage"]
                        }
                    }
                ]
            },
            {
                path: "platform",
                component: platform,
                name: "医院自助平台",
                icon: "",
                meta: {
                    authRule: ["admin/platform"]
                }
            }
        ]
    },

    {
        path: "/basicProduct",
        redirect: "/udiInfo/UdiInfoManage",
        component: Home,
        icon: "tongyong",
        name: "基础数据",
        hidden: false,
        noDropdown: false,
        meta: {
            authRule: ["basicProduct"]
        },
        children: [
            {
                path: "company",
                name: "本企业信息",
                component: company,
                meta: {
                    authRule: ["product/company"]
                }
            },
            {
                path: "/dictionary",
                redirect: "/dictionary/manage",
                name: "字典管理",
                component: Empty,
                meta: {
                    authRule: ["udiInfo/manage"]
                },
                children: [
                    {
                        path: "invWarehouse",
                        component: invWarehouse,
                        name: "仓库字典",
                        icon: "",
                        meta: {
                            authRule: ["basicProduct/invWarehouse"]
                        }
                    },
                    {
                        path: "udiInfo",
                        name: "耗材字典",
                        component: UdiInfoManage,
                        meta: {
                            authRule: ["inout/udiInfo"]
                        }
                    },
                    {
                        path: "unitMaintain",
                        name: "往来单位字典",
                        component: UnitManage,
                        meta: {
                            authRule: ["inout/unitMaintain"]
                        }
                    }
                ]
            }
        ]
    },

    {
        path: "/inout",
        component: Home,
        redirect: "/inout/scanOrder",
        icon: "tongyong",
        name: "单据管理",
        noDropdown: false,
        meta: {
            authRule: ["inout"]
        },
        children: [
            {
                path: "ioNew",
                component: ioNew,
                name: "待处理单据",
                meta: {
                    authRule: ["inout/ioNew"]
                }
            },
            {
                path: "errorOrder",
                component: errorOrder,
                name: "处理异常单据",
                meta: {
                    authRule: ["inout/errorOrder"]
                }
            },
            {
                path: "stockOrderSearch",
                component: stockOrderSearch,
                name: "未验收单据",
                meta: {
                    authRule: ["stock/stockOrderSearch"]
                }
            },
            {
                path: "stockOrderDelSearch",
                component: stockOrderDelSearch,
                name: "已完成单据",
                meta: {
                    authRule: ["stock/stockOrderDelSearch"]
                }
            },
            {
                path: "stockOrderEdit",
                component: stockOrderDelete,
                name: "单据编辑",
                meta: {
                    authRule: ["stock/stockOrderDelete"]
                }
            },
        ]
    },

    {
        path: "/inv",
        redirect: "/inv/invProducts",
        component: Home,
        icon: "tongyong",
        name: "库存管理",
        hidden: false,
        noDropdown: false,
        meta: {
            authRule: ["inv"]
        },
        children: [
            {
                path: "additionalOrder",
                component: additionalOrder,
                name: "补录单据管理",
                meta: {
                    authRule: ["stock/additionalOrder"]
                }
            },
            {
                path: "invProducts",
                component: invProducts,
                name: "库存查询",
                icon: "",
                meta: {
                    authRule: ["inv/invProducts"]
                }
            },
            {
                path: "udiTrace",
                component: ioUdiTrace,
                name: "UDI流向查询",
                icon: "",
                meta: {
                    authRule: ["inv/udiTrace"]
                }
            }
        ]
    },

    {
        path: "/sys",
        redirect: "/sys/sysConfig",
        component: Home,
        icon: "tongyong",
        name: "系统管理",
        hidden: false,
        noDropdown: false,
        meta: {
            authRule: ["sys"]
        },
        children: [
            {
                name: "用户管理",
                path: "sysUser",
                component: userAccountManage,
                meta: {
                    authRule: ["sys/sysUser"]
                }
            },
            {
                path: "systemParamConfig",
                component: systemParamConfig,
                name: "运行参数",
                meta: {
                    authRule: ["admin/systemParamConfig"]
                }
            },
            {
                path: "bussinessType",
                name: "单据类型",
                component: BussinessType,
                meta: {
                    authRule: ["product/bussinessType"]
                }
            },
            {
                path: "module",
                component: systemPDFModule,
                name: "打印设置",
                icon: "",
                meta: {
                    authRule: ["pdf/module"]
                }
            },
            {
                path: "bindPlatform",
                component: bindPlatform,
                name: "医院客户",
                icon: "",
                meta: {
                    authRule: ["sys/bindPlatform"]
                }
            }
        ]
    }

];
