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 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 BussinessType from "../views/basic/BussinessType.vue";
import basicUnitMaintain from "../views/basic/basicUnitMaintain.vue";
import UdiInfoManage from "../views/basic/UdiInfoManage.vue";
import company from "../views/userManage/param/company.vue";

//出入库管理
import inout from "../views/inout/IOFinishOrder.vue";
import udiTrace from "../views/inout/UdiCodeTrace.vue";
import code from "../views/inout/IOFinishCode.vue";
import errorCode from "../views/inout/IONewCode.vue";
import errorOrder from "../views/inout/IONewOrder.vue";
import ioErrorOrder from "../views/inout/IOErrorOrder.vue";
import waitOrder from "../views/inout/IOWaitOrder.vue";
import repeatOrder from "../views/inout/IORepeatOrder.vue";
import erpOrder from "../views/inout/IOErpOrder.vue";


//库存管理
import stockCheck from "../views/inventory/stockCheck.vue";
import onHand from "../views/inventory/OnHand.vue";
import stockPrint from "../views/inventory/stockPrint.vue";
import stockCode from "../views/inventory/stockCode.vue";


// Vue.use(VueRouter);

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 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: "/",
        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/adminManage/index",
        component: Home,
        icon: "guanliyuan1",
        name: "系统设置",
        hidden: false,
        meta: {
            authRule: ["user_manage"]
        },

        // noDropdown: true,
        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: "systemParamConfig",
                component: systemParamConfig,
                name: "参数设置",
                icon: "",
                meta: {
                    authRule: ["admin/systemParamConfig"]
                }
            }
        ]
    },
    {
        path: "/inout",
        component: Home,
        redirect: "/inout/main",
        icon: "tongyong",
        name: "出入库管理",
        noDropdown: false,
        meta: {
            authRule: ["inout"]
        },
        children: [

            {
                path: "ioErrorOrder",
                component: ioErrorOrder,
                name: "异常单据管理",
                meta: {
                    authRule: ["inout/ioErrorOrder"]
                }
            },
            {
                path: "errorOrder",
                component: errorOrder,
                name: "新增单据管理",
                meta: {
                    authRule: ["inout/errorOrder"]
                }
            },
            {
                path: "waitOrder",
                name: "等待校验单据",
                component: waitOrder,
                meta: {
                    authRule: ["inout/waitOrder"]
                }
            },
            {
                path: "main",
                name: "已完成单据",
                component: inout,
                meta: {
                    authRule: ["inout/main"]
                }
            },

            {
                path: "erpOrder",
                name: "ERP单据管理",
                component: erpOrder,
                meta: {
                    authRule: ["inout/erpOrder"]
                }
            },
            {
                path: "detail",
                name: "单号详情",
                component: code,
                hidden: true
            },
            {
                path: "errorDetail",
                name: "错误单号详情",
                component: errorCode,
                hidden: true
            },

            {
                path: "repeatOrder",
                component: repeatOrder,
                name: "扫码订单号重复",
                hidden: true,
                meta: {
                    authRule: ["inout/repeatOrder"]
                }
            },
            {
                path: "udiTrace",
                name: "UDI码追溯查询",
                component: udiTrace,
                meta: {
                    authRule: ["inout/udiTrace"]
                }
            },

        ]
    },


    {
        path: "/warehouse",
        redirect: "/warehouse/product",
        component: Home,
        icon: "tongyong",
        name: "库存管理",
        hidden: false,
        noDropdown: false,
        meta: {
            authRule: ["warehouse"]
        },
        children: [
            {
                path: "onHand",
                name: "现存量查询",
                component: onHand,

                meta: {
                    authRule: ["warehouse/onHand"]
                }
            },
            {
                path: "stockPrint",
                name: "货位卡管理",
                component: stockPrint,

                meta: {
                    authRule: ["warehouse/stockPrint"]
                }
            },

            {
                path: "stockCheck",
                name: "盘点单据",
                component: stockCheck,
                meta: {
                    authRule: ["warehouse/stockCheck"]
                }
            },
            {
                path: "stockCode",
                name: "库存明细",
                component: stockCode,
                hidden: true,
                meta: {
                    authRule: ["warehouse/stockCode"]
                }
            },
        ]
    },

    {
        path: "/product",
        redirect: "/product/productinfo",
        component: Home,
        icon: "tongyong",
        name: "基础数据",
        hidden: false,
        noDropdown: false,
        meta: {
            authRule: ["product"]
        },
        children: [


            {
                path: "productinfo",
                name: "医疗器械信息维护",
                component: UdiInfoManage,

                meta: {
                    authRule: ["product/productinfo"]
                }
            },
            {
                path: "unitMaintain",
                name: "往来单位信息维护",
                component: basicUnitMaintain,
                meta: {
                    authRule: ["basic/basicUnitMaintain"]
                }
            },
            {
                path: "bussinessType",
                name: "单据类型维护",
                component: BussinessType,
                meta: {
                    authRule: ["product/bussinessType"]
                }
            },
            {
                path: "company",
                name: "本企业信息",
                component: company,
                meta: {
                    authRule: ["product/company"]
                }
            }
        ]
    },

];
