import Vue from 'vue';
import Router from 'vue-router';
import store from "@/store"

/* Layout */
import Layout from '../layout';

Vue.use(Router);

/**
 * constantRoutes
 * 没有权限要求的基本页
 * 所有角色都可以访问
 * */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('../views/login/index'),
    name: 'login',
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: 'home',
    children: [{
      path: 'home',
      component: () => import('../views/home/home'),
      name: 'Home',
      meta: {
        title: 'home',
        icon: 'home',
        noCache: true,
        affix: true
      }
    },
    {
      path: 'messageList',
      component: () => import('../views/home/messageList'),
      name: 'messageList',
      meta: {
        title: 'messageList',
        icon: 'messageList',
        noCache: true,
        affix: true
      }
    },
    {
      path: 'messageDetail',
      component: () => import('../views/home/messageDetail'),
      name: 'messageDetail',
      meta: {
        title: 'messageDetail',
        icon: 'messageDetail',
        noCache: true,
        affix: true
      }
    },
    {
      path: 'organizationIndex',
      component: () => import('../views/organizationNew/organizationIndex'),
      name: 'organizationIndex',
      meta: {
        title: 'organization',
        icon: 'organization',
        noCache: true,
        affix: true
      }
    },
    {
      path: 'shoreMemberAdd',
      component: () => import('../views/organizationNew/shoreMemberAdd'),
      name: 'shoreMemberAdd',
      meta: {
        title: 'shoreMemberAdd',
      }
    },
    {
      path: 'shoreMemberDetail',
      component: () => import('../views/organizationNew/shoreMemberDetail'),
      name: 'shoreMemberDetail',
      meta: {
        title: 'shoreMemberDetail',
      }
    },
    {
      path: 'organization',
      component: () => import('../views/organization/organization'),
      name: 'organization',
      meta: {
        title: 'organization',
        icon: 'organization',
        noCache: true,
        affix: true
      },
      children: [{
        path: 'orgAddMan',
        component: () => import('../views/organization/orgAddMan'),
        name: 'orgAddMan',
        meta: {
          title: 'orgAddMan',
          icon: 'orgAddMan',
          noCache: true,
          affix: true
        }
      },
      {
        path: 'forbidden',
        component: () => import('../views/organization/forbidden'),
        name: 'forbidden',
        meta: {
          title: 'forbidden',
          icon: 'forbidden',
          noCache: true,
          affix: true
        }
      },
      {
        path: 'showMessage',
        component: () => import('../views/organization/showMessage'),
        name: 'showMessage',
        meta: {
          title: 'showMessage',
          icon: 'showMessage',
          noCache: true,
          affix: true
        }
      },
      {
        path: 'orgEdit',
        component: () => import('../views/organization/orgEdit'),
        name: 'orgEdit',
        meta: {
          title: 'orgEdit',
          icon: 'orgEdit',
          noCache: true,
          affix: true
        }
      }
      ]
    },
    {
      path: 'jobScope',
      component: () => import('../views/jobAuthority/jobScope'),
      name: 'jobScope',
      meta: {
        title: 'jobScope',
        icon: 'jobScope',
        noCache: true,
        affix: true
      }
    },
    {
      path: 'jobAuthority',
      component: () => import('../views/jobAuthority/jobAuthority'),
      name: 'jobAuthority',
      meta: {
        title: 'jobAuthority',
        icon: 'jobAuthority',
        noCache: true,
        affix: true
      }
    },
    // {
    //   path: 'businessSettings',
    //   component: () => import('../views/businessSettings/businessSettings'),
    //   name: 'businessSettings',
    //   meta: {
    //     title: 'businessSettings',
    //     icon: 'businessSettings',
    //     noCache: true,
    //     affix: true
    //   }
    // },
    {
      path: 'bayed',
      component: () => import('../views/bayed/bayed'),
      name: 'bayed',
      meta: {
        title: 'bayed',
        icon: 'bayed',
        noCache: true,
        affix: true
      }
    },
    {
      path: 'bayedaDetail',
      component: () => import('../views/bayed/bayedDetail'),
      name: 'bayedDetail',
      meta: {
        title: 'bayedDetail',
        icon: 'bayedDetail',
        noCache: true,
        affix: true
      }
    },
    {
      path: 'check-flow',
      component: () => import('../views/check-flow'),
      name: 'checkFlow',
      meta: {
        title: 'checkFlow',
        icon: 'checkFlow',
      },
    },
    {
      path: 'organizationShip',
      component: () => import('../views/organizationShip/organization'),
      name: 'organizationShip',
      meta: {
        title: 'organizationShip',
        icon: 'organizationShip',
        noCache: true,
        affix: true
      },
      children: [{
        path: 'orgAddMan',
        component: () => import('../views/organizationShip/orgAddMan'),
        name: 'orgAddManShip',
        meta: {
          title: 'orgAddMan',
          icon: 'orgAddMan',
          noCache: true,
          affix: true
        }
      },
      {
        path: 'forbidden_ship',
        component: () => import('../views/organizationShip/forbidden'),
        name: 'forbiddenShip',
        meta: {
          title: 'forbidden',
          icon: 'forbidden',
          noCache: true,
          affix: true
        }
      },
      {
        path: 'showMessage',
        component: () => import('../views/organizationShip/showMessage'),
        name: 'showMessageShip',
        meta: {
          title: 'showMessage',
          icon: 'showMessage',
          noCache: true,
          affix: true
        }
      },
      {
        path: 'orgEdit',
        component: () => import('../views/organizationShip/orgEdit'),
        name: 'orgEditShip',
        meta: {
          title: 'orgEdit',
          icon: 'orgEdit',
          noCache: true,
          affix: true
        }
      }]
    },
    {
      path: 'jobAuthorityShip',
      component: () => import('../views/jobAuthorityShip/jobAuthority'),
      name: 'jobAuthorityShip',
      meta: {
        title: 'jobAuthorityShip',
        icon: 'jobAuthorityShip',
        noCache: true,
        affix: true
      }
    },
    {
      path: 'jobScopeShip',
      component: () => import('../views/jobAuthorityShip/jobScope'),
      name: 'jobScopeShip',
      meta: {
        title: 'jobScopeShip',
        icon: 'jobScopeShip',
        noCache: true,
        affix: true
      }
    },
    {
      path: 'shipManagement',
      component: () => import('../views/businessSettings/shipManagement'),
      name: 'shipManagement',
      meta: {
        title: 'shipManagement',
        icon: 'shipManagement',
        noCache: true,
        affix: true
      }
    },
    {
      path: 'companyInfoIndex',
      component: () => import('../views/companyInfo/companyInfoIndex'),
      name: 'companyInfoIndex',
      meta: {
        title: 'companyInfoIndex',
        icon: 'companyInfoIndex',
        noCache: true,
        affix: true
      }
    },
    // {
    //   path: 'travelCompanyIndex',
    //   component: () => import('../views/travelCompany/travelCompanyIndex'),
    //   name: 'travelCompanyIndex',
    //   meta: {
    //     title: 'travelCompanyIndex',
    //     icon: 'travelCompanyIndex',
    //     noCache: true,
    //     affix: true
    //   }
    // }
    ]
  },
];

const createRouter = () => new Router({
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
});

const router = createRouter();

export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}
router.beforeEach((to, from, next) => {
  const {baseInfo} = store.getters
  if (Object.keys(baseInfo).length === 0) {
    store.dispatch('user/getBaseInfo')
  }
  next();
})
export default router;
