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

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

// import dashRouter from "./modules/dash"; //首页
import purchasRouter from "./modules/purchas"; //采购管理
import applyRouter from "./modules/apply"; //申领管理
import storeroomRouter from "./modules/storeroom"; //库房管理
import approveRouter from "./modules/approve"; //审批中心
import supplierRouter from "./modules/supplier"; //供应商管理
import orderRouter from "./modules/order"; //订单管理
import returnRouter from "./modules/productreturn"; //订单管理
import consumRouter from "./modules/consumcata"; //目录管理
import settlementRouter from "./modules/settlement"; //采购结算---业务对账
import invoiceRouter from "./modules/invoiceManage"; //采购结算---采购发票管理
import paymentStatusRouter from "./modules/paymentStatus" //付款状态查询--消耗明细
import mainrTenanceRouter from "./modules/mainrTenance" //申领模板维护
import mautFillRouter from '././modules/quality-management-sup' //资质管理
// returnRouter

export const constantRoutes = [
  {
    path: "/redirect",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index")
      }
    ]
  },
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true
  },
  {
    path: "/firstLogin",
    component: () => import("@/views/firstLogin/index"),
    hidden: true
  },
  {
    path: "/404",
    component: () => import("@/views/error-page/404"),
    hidden: true
  },
  {
    path: "/401",
    component: () => import("@/views/error-page/401"),
    hidden: true
  },
  {
    path: "/",
    component: Layout,
    redirect: "/message-center/messagecenter-index",
    children: [
      {
        // 公告详情
        path: "/noticeDetail/:id",
        component: () => import("@/views/page/system/notice/noticeDetail"),
        name: "NoticeDetail",
        meta: { title: "公告详情", icon: "dashboard" },
        hidden: true
      },
      {
        // 个人中心
        path: "/personalCenter",
        component: () => import("@/views/page/personalCenter/index"),
        name: "PersonalCenter",
        meta: { title: "账户信息", icon: "dashboard" },
        hidden: true
      }
    ]
  },
];


export const asyncRoutes = [
  purchasRouter,
  applyRouter,
  storeroomRouter,
  approveRouter,
  supplierRouter,
  orderRouter,
  returnRouter,
  consumRouter,
  settlementRouter,
  invoiceRouter,
  paymentStatusRouter,
  mainrTenanceRouter,
  mautFillRouter,
  { path: "*", redirect: "/404", hidden: true }
];

const createRouter = () =>
  new Router({
    //mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
