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 authAdmin from "../views/userManage/admin/authAdmin.vue";
import authRole from "../views/userManage/admin/authRole.vue";
import authPermissionRule from "../views/userManage/admin/authPermissionRule.vue";

//权限相关
import sysMenu from "../views/sys/sysMenu";
import sysRole from "../views/sys/sysRole";
import sysUser from "../views/sys/sysUser";

import nested from "../views/home/nested";

//数据同步相关
import jobLog from "../views/UDIDownload/jobLog"
import fileInfo from "../views/UDIDownload/fielInfo"
import udiSingle from "../views/UDIDownload/udiSingle";
import udiDataDownload from '../views/UDIDownload/udiDataDownload';

import udplatDistributor from '../views/udplat/udplatDistributor';
import udplatHospital from '../views/udplat/udplatHospital';
import udplatManufacture from '../views/udplat/udplatManufacture';
import udplatGoods from '../views/udplat/udplatGoods';
import udplatLog from '../views/udplat/udplatLog';
import udplatGoodsMatch from '../views/udplat/udplatGoodsMatch';
import udiDataUpdate from "@/views/UDIDownload/udiDataUpdate";


// import UdiInfoSearch from '../views/external/UdiInfoSearch';


const err401 = r =>
    require.ensure([], () => r(require("../views/error/err401.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 UdiInfoSearch = r =>
    require.ensure([], () => r(require("../views/external/UdiInfoSearch.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: "/UdiInfoSearch",
        component: UdiInfoSearch,
        name: "UDI校验",
        hidden: true
    },

    {
        path: "/",
        icon: "shouye",
        component: Home,
        redirect: "main",
        name: "首页",
        hidden: true,
        noDropdown: true,
        children: [
            {
                path: "main",
                component: main,
                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/authAdmin",
        component: Home,
        icon: "guanliyuan1",
        name: "系统管理",
        hidden: false,
        meta: {
            authRule: ["user_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: "/sys",
        redirect: "/sys/sysMenu",
        component: Home,
        icon: "cloud-permissions",
        name: "权限管理",
        hidden: false,
        meta: {
            authRule: ["sys"]
        },
        children: [
            {
                name: "接口菜单",
                path: "sysMenu",
                component: sysMenu,
                meta: {
                    authRule: ["sys/sysMenu"]
                }
            },
            {
                name: "角色管理",
                path: "sysRole",
                component: sysRole,
                meta: {
                    authRule: ["sys/sysRole"]
                }
            },
            {
                name: "用户管理",
                path: "sysUser",
                component: sysUser,
                meta: {
                    authRule: ["sys/sysUser"]
                }
            }
        ]
    },
    {
        path: "/DownloadInfo",
        component: Home,
        redirect: "/UDIDownload",
        icon: "tongyong",
        name: "数据同步信息",
        noDropdown: false,
        hidden: false,
        meta: {
            authRule: ["UDIDownload"]
        },
        children: [
            {
                path: "/UDIDownload",
                component: nested,
                name: "国家同步库",
                noDropdown: false,
                hidden: false,
                meta: {
                    authRule: ["UDIDownload"]
                },
                children: [
                    {
                        name: "数据下载",
                        path: "udiDataDownload",
                        component: udiDataDownload,
                        meta: {
                            authRule: ["UDIDownload/udiDataDownload"]
                        },
                    },
                    // {
                    //     name: "数据更新",
                    //     path: "udiDataUpdate",
                    //     component: udiDataUpdate,
                    //     meta: {
                    //         authRule: ["UDIDownload/udiDataUpdate"]
                    //     },
                    // },
                    {
                        name: "UDI日志",
                        path: "jobLog",
                        component: jobLog,

                        meta: {
                            authRule: ["UDIDownload/jobLog"]
                        },
                    },
                    {
                        name: "同步文件",
                        path: "fileInfo",
                        component: fileInfo,

                        meta: {
                            authRule: ["UDIDownload/fileInfo"]
                        },
                    },
                    {
                        name: "DI查询",
                        path: "udiSingle",
                        component: udiSingle,
                        meta: {
                            authRule: ["UDIDownload/udiSingle"]
                        },
                    },
                ]

            },
            {
                path: "/UdplatDownload",
                component: nested,
                redirect: "/UDIDownload/udplatDistributor",
                name: "阳光平台",
                noDropdown: false,
                hidden: false,
                meta: {
                    authRule: ["UdplatDownload"]
                },
                children: [
                    {
                        name: "配送企业",
                        path: "udplatDistributor",
                        component: udplatDistributor,
                        meta: {
                            authRule: ["UDIDownload/udplatDistributor"]
                        }
                    },
                    {
                        name: "医疗机构",
                        path: "udplatHospital",
                        component: udplatHospital,
                        meta: {
                            authRule: ["UDIDownload/udplatHospital"]
                        }
                    },
                    {
                        name: "生产企业",
                        path: "udplatManufacture",
                        component: udplatManufacture,
                        meta: {
                            authRule: ["UDIDownload/udplatManufacture"]
                        }
                    },
                    {
                        name: "产品目录",
                        path: "udplatGoods",
                        component: udplatGoods,
                        meta: {
                            authRule: ["UDIDownload/udplatGoods"]
                        }
                    },
                    {
                        name: "阳光平台日志",
                        path: "udplatLog",
                        component: udplatLog,
                        meta: {
                            authRule: ["UDIDownload/udplatLog"]
                        }
                    },
                    {
                        name: "产品对照表",
                        path: "udplatGoodsMatch",
                        component: udplatGoodsMatch,
                        meta: {
                            authRule: ["UDIDownload/udplatGoodsMatch"]
                        }
                    }
                ]
            }
        ]
    }

];
