import { createWebHistory, createRouter, RouteRecordRaw } from 'vue-router';
/* Layout */
import Layout from '@/layout/index.vue';

/**
 * Note: 路由配置项
 *
 * hidden: true                     // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true                 // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                  // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                  // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                  // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect             // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'               // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
 * roles: ['admin', 'common']       // 访问路由的角色权限
 * permissions: ['a:a:a', 'b:b:b']  // 访问路由的菜单权限
 * meta : {
    noCache: true                   // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'                  // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'                // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false               // 如果设置为false，则不会在breadcrumb面包屑中显示
    activeMenu: '/system/user'      // 当路由设置了该属性，则会高亮相对应的侧边栏。
  }
 */

// 公共路由
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index.vue')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login.vue'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/register.vue'),
    hidden: true
  },
  {
    path: '/:pathMatch(.*)*',
    component: () => import('@/views/error/404.vue'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error/401.vue'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: '/index',
    children: [
      {
        path: '/index',
        component: () => import('@/views/home/index.vue'),
        name: 'Index',
        meta: { title: '优易365', affix: true, nav: true }
      },
      {
        path: '/indexB',
        component: () => import('@/views/home/index-b.vue'),
        name: 'IndexB',
        meta: { title: '企业购商城', affix: true, nav: true }
      },
      {
        path: '/indexMro',
        component: () => import('@/views/home/index-mro.vue'),
        name: 'IndexMro',
        meta: { title: '工业品商城', affix: true, nav: true }
      },
      {
        path: '/indexFuli',
        component: () => import('@/views/home/index-fuli.vue'),
        name: 'IndexFuli',
        meta: { title: '福礼商城', icon: 'dashboard', affix: true, nav: true }
      },
      {
        path: '/diy',
        component: () => import('@/views/home/diy.vue'),
        name: 'IndexDiy',
        meta: { title: 'Diy商城', diy: true, search: 'hide' }
      },
      {
        path: '/theme',
        component: () => import('@/views/home/theme.vue'),
        name: 'IndexTheme',
        meta: { title: '详情', icon: 'dashboard', affix: true, nav: true }
      },
      {
        path: '/indexData',
        component: () => import('@/views/home/index-data.vue'),
        name: 'indexData',
        meta: { title: '大客户站点', icon: 'dashboard', affix: true, nav: true }
      },
      {
        path: '/reg',
        component: () => import('@/views/reg/index.vue'),
        name: 'Reg',
        meta: { title: '个人注册', icon: 'dashboard', affix: true, nav: true }
      },
      {
        path: '/breg',
        component: () => import('@/views/breg/index.vue'),
        name: 'Breg',
        meta: { title: '企业注册', header: 'hide', search: 'hide' }
      },
      {
        path: '/greg',
        component: () => import('@/views/greg/index.vue'),
        name: 'Greg',
        meta: { title: '供应商注册', header: 'hide', search: 'hide' }
      },
      {
        path: '/search',
        component: () => import('@/views/search/index.vue'),
        name: 'Search',
        meta: { title: '搜索', icon: 'dashboard', affix: true, nav: true }
      },
      {
        path: '/search/special',
        component: () => import('@/views/search/special.vue'),
        name: 'SearchSpecial',
        meta: { title: '特价专区', icon: 'dashboard', affix: true, nav: true }
      },
      {
        path: '/search/brand',
        component: () => import('@/views/search/brand.vue'),
        name: 'SearchBrand',
        meta: { title: '品牌闪购', icon: 'dashboard', affix: true, nav: true }
      },
      {
        path: '/item',
        component: () => import('@/views/item/index.vue'),
        name: 'Item',
        meta: { title: '商品详情', nav: true, breadcrumb: true, breadcrumbColor: '#F4F4F4' }
      },
      {
        path: '/cart',
        component: () => import('@/views/cart/index.vue'),
        name: 'Cart',
        meta: { title: '我的购物车', nav: true }
      },
      {
        path: '/trad',
        component: () => import('@/views/trad/index.vue'),
        name: 'Trad',
        meta: { title: '确认订单信息', nav: true }
      },
      {
        path: '/payc',
        component: () => import('@/views/payc/index.vue'),
        name: 'shopPay',
        meta: { title: '支付订单', nav: true }
      },
      {
        path: '/solve/real',
        component: () => import('@/views/solve/real.vue'),
        name: 'solveReal',
        meta: { title: '资讯详情', nav: true, breadcrumb: true, breadcrumbColor: '#F4F4F4' }
      },
      {
        path: '/order/orderManage',
        name: 'OrderManage',
        component: () => import('@/views/order/orderManage/index.vue'),
        meta: { title: '订单管理', workbench: true }
      },
      {
        path: '/order/orderManage/detail',
        name: 'OrderDetail',
        component: () => import('@/views/order/orderManage/detail.vue'),
        meta: { title: '订单详情', hidden: true, workbench: true }
      },
      {
        path: '/order/orderManage/applyAfter',
        component: () => import('@/views/order/orderManage/applyAfter.vue'),
        name: 'ApplyAfter',
        meta: { title: '申请售后', hidden: true, workbench: true }
      },
      {
        path: '/order/orderAudit',
        name: 'OrderAudit',
        component: () => import('@/views/order/orderAudit/index.vue'),
        meta: { title: '审核订单', workbench: true }
      },
      {
        path: '/order/afterSale',
        name: 'AfterSale',
        component: () => import('@/views/order/afterSale/index.vue'),
        meta: { title: '售后服务', workbench: true }
      },
      {
        path: '/order/batchOrder',
        name: 'BatchOrder',
        component: () => import('@/views/order/batchOrder/index.vue'),
        meta: { title: '批量下单', workbench: true }
      },
      {
        path: '/order/orderEvaluation',
        name: 'OrderEvaluation',
        component: () => import('@/views/order/orderEvaluation/index.vue'),
        meta: { title: '订单评价', workbench: true }
      },
      {
        path: '/order/orderEvaluation/evaluation',
        name: 'EvaluationAdd',
        component: () => import('@/views/order/orderEvaluation/evaluation.vue'),
        meta: { title: '新增评价', workbench: true }
      },
      {
        path: '/plan',
        component: () => import('@/views/plan/index.vue'),
        name: 'Plan',
        meta: { title: '解决方案', nav: true, breadcrumb: true }
      },
      {
        path: '/plan_info',
        component: () => import('@/views/plan_info/index.vue'),
        name: 'PlanInfo',
        meta: { title: '解决方案详情', nav: true, breadcrumb: true, navList: [{ title: '解决方案', url: '/plan' }] }
      },
      {
        path: '/plan/procure',
        component: () => import('@/views/plan/procure.vue'),
        name: 'PlanProcure',
        meta: { title: '场景采购', nav: true, breadcrumb: true }
      },
      {
        path: '/plan_info/procure',
        component: () => import('@/views/plan_info/procure.vue'),
        name: 'PlanInfoProcure',
        meta: { title: '场景采购详情', nav: true, breadcrumb: true, navList: [{ title: '场景采购', url: '/plan/procure' }] }
      },
      {
        path: '/plan/guide',
        component: () => import('@/views/plan/guide.vue'),
        name: 'PlanGuide',
        meta: { title: '采购指南', nav: true, breadcrumb: true }
      },
      {
        path: '/plan_info/guide',
        component: () => import('@/views/plan_info/guide.vue'),
        name: 'PlanInfoGuide',
        meta: { title: '采购指南详情', nav: true, breadcrumb: true, breadcrumbColor: '#F4F4F4', navList: [{ title: '采购指南', url: '/plan/guide' }] }
      },
      {
        path: '/plan/project',
        component: () => import('@/views/plan/project.vue'),
        name: 'PlanProject',
        meta: { title: '项目案例', nav: true, breadcrumb: true }
      },
      {
        path: '/plan_info/project',
        component: () => import('@/views/plan_info/project.vue'),
        name: 'PlanInfoProject',
        meta: {
          title: '项目案例详情',
          nav: true,
          breadcrumb: true,
          breadcrumbColor: '#F4F4F4',
          navList: [{ title: '采购指南', url: '/plan/project' }]
        }
      },
      {
        path: '/i',
        name: 'I',
        component: () => import('@/views/i/index.vue'),
        meta: { title: '个人信息', workbench: true }
      },
      {
        path: '/easybuv',
        name: 'Easybuv',
        component: () => import('@/views/easybuv/index.vue'),
        meta: { title: '地址管理', workbench: true }
      },
      {
        path: 'enterprise/companyInfo',
        name: 'CompanyInfo',
        component: () => import('@/views/enterprise/companyInfo/index.vue'),
        meta: { title: '企业信息', workbench: true }
      },
      {
        path: 'enterprise/companyInfo/edit',
        name: 'CompanyInfoEdit',
        component: () => import('@/views/enterprise/companyInfo/edit.vue'),
        meta: { title: '完善企业信息', hidden: true, workbench: true }
      },
      {
        path: 'enterprise/securitySetting',
        name: 'SecuritySetting',
        component: () => import('@/views/enterprise/securitySetting/index.vue'),
        meta: { title: '安全设置', hidden: true, workbench: true }
      },
      {
        path: 'enterprise/securitySetting/resetPassword',
        name: 'ResetPassword',
        component: () => import('@/views/enterprise/securitySetting/resetPassword.vue'),
        meta: { title: '重置密码', hidden: true, workbench: true }
      },
      {
        path: 'enterprise/securitySetting/changePhone',
        name: 'ChangePhone',
        component: () => import('@/views/enterprise/securitySetting/changePhone.vue'),
        meta: { title: '更换手机号码', hidden: true, workbench: true }
      },
      {
        path: 'enterprise/purchaseHabit',
        name: 'PurchaseHabit',
        component: () => import('@/views/enterprise/purchaseHabit/index.vue'),
        meta: { title: '采购习惯', hidden: true, workbench: true }
      },
      {
        path: 'enterprise/changePerson',
        name: 'PurchaseHabit',
        component: () => import('@/views/enterprise/changePerson/index.vue'),
        meta: { title: '更换负责人', hidden: true, workbench: true }
      },
      {
        path: 'enterprise/messageNotice',
        name: 'MessageNotice',
        component: () => import('@/views/enterprise/messageNotice/index.vue'),
        meta: { title: '消息通知', workbench: true }
      },

      {
        path: 'enterprise/invoiceManage',
        name: 'InvoiceManage',
        component: () => import('@/views/enterprise/invoiceManage/index.vue'),
        meta: { title: '发票抬头管理', workbench: true }
      },
      {
        path: 'enterprise/purchasePlan',
        name: 'PurchasePlan',
        component: () => import('@/views/enterprise/purchasePlan/index.vue'),
        meta: { title: '专属采购方案', workbench: true }
      },
      {
        path: 'enterprise/agreementSupply',
        name: 'AgreementSupply',
        component: () => import('@/views/enterprise/agreementSupply/index.vue'),
        meta: { title: '协议供货', workbench: true }
      },
      {
        path: 'enterprise/myCollection',
        name: 'MyCollection',
        component: () => import('@/views/enterprise/myCollection/index.vue'),
        meta: { title: '我的收藏', workbench: true }
      },
      {
        path: 'enterprise/purchaseHistory',
        name: 'PurchaseHistory',
        component: () => import('@/views/enterprise/purchaseHistory/index.vue'),
        meta: { title: '历史购买', workbench: true }
      },
      {
        path: 'enterprise/myFootprint',
        name: 'MyFootprint',
        component: () => import('@/views/enterprise/myFootprint/index.vue'),
        meta: { title: '我的足迹', workbench: true }
      },
      {
        path: 'organization/deptManage',
        name: 'DeptManage',
        component: () => import('@/views/organization/deptManage/index.vue'),
        meta: { title: '部门管理', workbench: true }
      },
      {
        path: 'organization/staffManage',
        name: 'StaffManage',
        component: () => import('@/views/organization/staffManage/index.vue'),
        meta: { title: '人员管理', workbench: true }
      },
      {
        path: 'organization/roleManage',
        name: 'RoleManage',
        component: () => import('@/views/organization/roleManage/index.vue'),
        meta: { title: '角色管理', workbench: true }
      },
      {
        path: 'organization/approvalFlow',
        name: 'ApprovalFlow',
        component: () => import('@/views/organization/approvalFlow/index.vue'),
        meta: { title: '审批流程', workbench: true }
      },
      {
        path: 'organization/approvalFlow/create',
        name: 'ApprovalFlowCreate',
        component: () => import('@/views/organization/approvalFlow/create.vue'),
        meta: { title: '新建审批', hidden: true, workbench: true }
      },
      {
        path: 'organization/groupEnterprise',
        name: 'GroupEnterprise',
        component: () => import('@/views/organization/groupEnterprise/index.vue'),
        meta: { title: '集团关联企业', workbench: true }
      },
      {
        path: 'cost/itemExpense',
        name: 'ItemExpense',
        component: () => import('@/views/cost/itemExpense/index.vue'),
        meta: { title: '分项费用', workbench: true }
      },
      {
        path: 'cost/quotaControl',
        name: 'QuotaControl',
        component: () => import('@/views/cost/quotaControl/index.vue'),
        meta: { title: '额度控制', workbench: true }
      },
      {
        path: 'cost/quotaControl/apply',
        name: 'QuotaApply',
        component: () => import('@/views/cost/quotaControl/apply.vue'),
        meta: { title: '额度申请', hidden: true, workbench: true }
      },
      {
        path: 'reconciliation/billManage',
        name: 'BillManage',
        component: () => import('@/views/reconciliation/billManage/index.vue'),
        meta: { title: '对账单管理', workbench: true }
      },
      {
        path: 'reconciliation/invoiceManage',
        name: 'ReconciliationInvoiceManage',
        component: () => import('@/views/reconciliation/invoiceManage/index.vue'),
        meta: { title: '开票管理', workbench: true }
      },
      {
        path: 'valueAdded/maintenance',
        name: 'Maintenance',
        component: () => import('@/views/valueAdded/maintenance/index.vue'),
        meta: { title: '维保服务', workbench: true }
      },
      {
        path: 'valueAdded/maintenanceApply',
        name: 'MaintenanceApply',
        component: () => import('@/views/valueAdded/maintenance/apply.vue'),
        meta: { title: '维保申请', workbench: true }
      },
      {
        path: 'valueAdded/complaint',
        name: 'Complaint',
        component: () => import('@/views/valueAdded/complaint/index.vue'),
        meta: { title: '投诉与建议', workbench: true }
      },
      {
        path: 'analysis/orderAnalysis',
        name: 'OrderAnalysis',
        component: () => import('@/views/analysis/orderAnalysis/index.vue'),
        meta: { title: '订单交易分析', workbench: true }
      },
      {
        path: 'analysis/purchaseDetail',
        name: 'PurchaseDetail',
        component: () => import('@/views/analysis/purchaseDetail/index.vue'),
        meta: { title: '商品采购明细', workbench: true }
      },
      {
        path: 'analysis/orderStatus',
        name: 'OrderStatus',
        component: () => import('@/views/analysis/orderStatus/index.vue'),
        meta: { title: '订单执行状态', workbench: true }
      },
      {
        path: 'analysis/settlementStatus',
        name: 'SettlementStatus',
        component: () => import('@/views/analysis/settlementStatus/index.vue'),
        meta: { title: '对账结算状况', workbench: true }
      },
      {
        path: 'analysis/deptPurchase',
        name: 'DeptPurchase',
        component: () => import('@/views/analysis/deptPurchase/index.vue'),
        meta: { title: '部门采购金额', workbench: true }
      }
    ]
  }
];

// 动态路由，基于用户权限动态去加载
export const dynamicRoutes: RouteRecordRaw[] = [];

/**
 * 创建路由
 */
const router = createRouter({
  history: createWebHistory(import.meta.env.VITE_APP_CONTEXT_PATH),
  routes: constantRoutes,
  // 刷新时，滚动条位置还原
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    }
    return { top: 0 };
  }
});

export default router;
