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 adminRouter from "../views/userManage/admin/router.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 registerManage from "../views/userManage/registerManage.vue";
import userAccountManage from "../views/userManage/userAccountManage.vue";
import customerManage from "../views/userManage/customerManage.vue";
import customerInfo from "../views/userManage/customerInfo.vue";

//菜单管理
import unit from "../views/warehouse/unit.vue";
import code from "../views/warehouse/code.vue";
import errorCode from "../views/warehouse/errorCode.vue";

import udid from "../views/udid/udid.vue";
import udidDetail from "../views/udid/udidDetail.vue";
import udidSearch from "../views/udid/udidSearch.vue";
import udiInfoSearch from "../views/publish/udiInfoSearch.vue";
import selectUdi from "../views/udid/selectUdid.vue";
import udidload from "../views/udid/udidload.vue";


//出入库单据相关
import ioNew from "../views/warehouse/ioNewOrder.vue";
import errorOrder from "../views/warehouse/ioErrorOrder.vue";
import inout from "../views/warehouse/ioFinishOrder.vue";
import udiTrace from "../views/warehouse/udiTrace.vue";
import ioUdiTrace from "../views/warehouse/ioUdiTrace.vue";
import codeNeedRl from "../views/warehouse/codeNeedRl.vue";
import invProducts from "../views/warehouse/InvProducts.vue";


import company from "../views/warehouse/company.vue";

//产品信息维护
import DrugInfoManage from "../views/product/DrugInfoManage.vue";
import UdiInfoManage from "../views/product/UdiInfoManage.vue";
import udiRelevance from "../views/product/udiRelevance.vue";
import drugRelevance from "../views/product/drugRelevance.vue";
import BussinessType from "../views/product/BussinessType.vue";
import UnitManage from "../views/product/UnitManage.vue";
import UnitRelevance from "../views/product/UnitRelevance.vue";
import customerCodeContrast from "../views/sale/customerCodeContrast.vue";
import codecontrast from "../views/sale/codeContrast.vue";



import mipsOrder from "../views/manuorder/manuOrder.vue"
import manuDetail from "../views/manuorder/manuOrderDetail.vue"


//发布管理
import udiProduct from "../views/publish/udiProduct.vue"
import udiSubProduct from "../views/publish/udiSubProduct.vue"
import udiProductID from "../views/publish/udiProductID.vue"
import udiPublish from "../views/publish/udiPublish.vue"


//基础数据
import registerCert from "../views/basic/registerCert.vue"
import facidentcode from "../views/basic/facidentcode.vue"


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 forgetPasswd = r =>
    require.ensure([], () => r(require("../views/userManage/forgetPasswd.vue")), "home");
const pcIntent = r =>
    require.ensure([], () => r(require("../views/sale/pcIntent.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: "/forgetPasswd",
        component: forgetPasswd,
        name: "忘记密码",
        hidden: true
    },

    {
        path: "/pcIntent",
        component: pcIntent,
        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: "registerManage",
                component: registerManage,
                name: "用户审核管理",
                icon: "",
                meta: {
                    authRule: ["admin/registerManage"]
                }
            },
            {
                path: "customerManage",
                component: customerManage,
                name: "客户信息管理",
                icon: "",
                meta: {
                    authRule: ["admin/customerManage"]
                }
            },

        ]
    },



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

            {
                path: "unitMaintain",
                name: "往来单位信息维护",
                component: UnitManage,

                meta: {
                    authRule: ["inout/unitMaintain"]
                },
            },
            {
                path: "udiInfo",
                name: "器械信息维护",
                component: UdiInfoManage,

                meta: {
                    authRule: ["inout/udiInfo"]
                },
            },

            {
                path: "productinfo",
                name: "医疗器械信息维护",
                component: UdiInfoManage,
                hidden: true,
                meta: {
                    authRule: ["product/productinfo"]
                },
            },

            {
                name: "器械信息详情",
                path: "udirevance",
                hidden: true,
                component: udiRelevance,

            },
            {
                path: "productinfoadd",
                name: "客户药品信息",
                component: DrugInfoManage,
                hidden: true,
                meta: {
                    authRule: ["product/productinfoadd"]
                },
            },
            {
                path: "customerCodeContrast",
                name: "客户码对照表",
                component: customerCodeContrast,
                hidden: true,
                meta: {
                    authRule: ["product/customerCodeContrast"]
                },
            },
            {
                name: "药品信息详情",
                path: "drugrevance",
                hidden: true,
                component: drugRelevance,
            },

            {
                path: "unitMaintain",
                name: "往来单位信息维护",
                component: UnitManage,
                hidden: true,
                meta: {
                    authRule: ["product/unitMaintain"]
                },
            },
            {
                name: "往来单位关联",
                path: "unitrevance",
                hidden: true,
                component: UnitRelevance,
            },

            {
                path: "bussinessType",
                name: "单据类型维护",
                component: BussinessType,
                hidden: true,
                meta: {
                    authRule: ["product/bussinessType"]
                },
            },



            {
                path: "company",
                name: "本企业信息",
                component: company,
                meta: {
                    authRule: ["product/company"]
                },
            },
            {
                path: "userAccountManage",
                component: userAccountManage,
                name: "企业用户",
                icon: "",
                meta: {
                    authRule: ["product/userAccountManage"]
                }
            },
            {
                path: "registerCert",
                name: "注册证维护",
                component: registerCert,
                meta: {
                    authRule: ["product/registerCert"]
                },
            },
            {
                path: "facidentcode",
                name: "厂商识别码维护",
                component: facidentcode,
                meta: {
                    authRule: ["product/facidentcode"]
                },
            },


            {
                path: "customerInfo",
                name: "用户信息管理",
                component: customerInfo,
                hidden: true,
                meta: {
                    authRule: ["product/customerInfo"]
                },
            },


        ]
    },

    {
        path: "/publish",
        redirect: "/publish/udiProduct",
        component: Home,
        icon: "tongyong",
        hidden: false,
        name: "发布管理",
        noDropdown: false,
        meta: {
            authRule: ["publish"]
        },
        children: [

            {
                name: "产品信息维护",
                path: "udiProduct",
                component: udiProduct,

                meta: {
                    authRule: ["publish/udiProduct"]
                },
            },
            {
                name: "子类信息",
                path: "udiSubProduct",
                component: udiSubProduct,
                hidden: true,

            },

            {
                name: "器械标识维护",
                path: "identifcationMaintain",
                component: udiProductID,
                meta: {
                    authRule: ["public/identifcationMaintain"]
                },
            },


            {
                name: "器械标识上传",
                path: "identifcationUpload",
                component: udiPublish,
                meta: {
                    authRule: ["public/identifcationUpload"]
                },

            },

            {
                name: "已发布器械",
                path: "devicelist",
                component: udid,
                meta: {
                    authRule: ["public/devicelist"]
                },
            },
            {
                name: "器械信息详情",
                path: "detail",
                hidden: true,
                component: udidDetail,

            },
            {
                name: "最小包装标识查询",
                path: "search",
                component: udidSearch,
                meta: {
                    authRule: ["public/search"]
                }
            },
            {
                name: "UDI产品信息查询",
                path: "udiInfoSearch",
                component: udiInfoSearch,
                meta: {
                    authRule: ["public/udiInfoSearch"]
                }
            }

        ]
    },
    {
        path: "/info",
        redirect: "/info/druginfo",
        component: Home,
        icon: "tongyong",
        hidden: true,
        name: "已发布器械",
        noDropdown: false,
        meta: {
            authRule: ["info"]
        },
        children: [

            {
                name: "器械信息",
                path: "devicelist",
                component: udid,
                hidden: false,
                meta: {
                    authRule: ["info/devicelist"]
                },
            },

            {
                name: "器械信息下载",
                path: "udidload",
                component: udidload,
                hidden: true,
                meta: {
                    authRule: ["info/udidload"]
                },
            },


            {
                name: "选择产品信息",
                path: "selectUdi",
                hidden: true,
                component: selectUdi
            },

            {
                path: "codecontrast",
                name: "码对照",
                component: codecontrast, hidden: true,
                meta: {
                    authRule: ["info/codecontrast"]
                },
            },

            {
                path: "unit",
                name: "往来单位",
                component: unit, hidden: true,
                meta: {
                    authRule: ["info/unit"]
                },
            },


        ]
    },

    {
        path: "/inout",
        component: Home,
        redirect: "/inout/main",
        icon: "tongyong",
        name: "出入库管理",
        noDropdown: false,
        hidden: false,
        meta: {
            authRule: ["inout"]
        },
        children: [

            {
                path: "ioNew",
                component: ioNew,
                name: "新增扫码单据",
                meta: {
                    authRule: ["inout/ioNew"]
                },

            },

            {
                path: "main",
                name: "已完成单据",
                component: inout,
                meta: {
                    authRule: ["inout/main"]
                },

            },
            {
                path: "detail",
                name: "单号详情",
                component: code,
                hidden: true,

            },
            {
                path: "errorDetail",
                name: "错误单号详情",
                component: errorCode,
                hidden: true
            },



            {
                path: "udiTrace",
                name: "UDI流向查询",
                component: ioUdiTrace,
                meta: {
                    authRule: ["inout/udiTrace"]
                }
            },

            {
                path: "invProducts",
                name: "库存查询",
                component: invProducts,
                meta: {
                    authRule: ["inout/invProducts"]
                }
            },

            {
                path: "codeNeedRl",
                name: "UDI码关联关系",
                component: codeNeedRl,
                meta: {
                    authRule: ["inout/codeNeedRl"]
                }
            },
            {
                path: "errorOrder",
                component: errorOrder,
                name: "异常扫码单据",
                meta: {
                    authRule: ["inout/errorOrder"]
                },

            },


        ]
    },


];
