import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '@/views/login'
import Page404 from '@/views/404'
import Layout from '@/views/layout/index'

Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    component: Login,
    meta: {
      title: '登录',
      roles: ['admin', 'editor'],
      hidden: true
    }
  },
  {
    path: '/404',
    component: Page404,
    meta: {
      title: '404',
      roles: ['admin', 'editor'],
      hidden: true
    }
  },
  {
    path: '/',
    redirect: '/home/index',
    meta: {
      title: '主页',
      roles: ['admin', 'editor'],
      hidden: true
    }
  },
  {
    path: '/home',
    component: Layout,
    meta: {
      title: '概况',
      icon: 'iconfont icon-fuwudiqiu',
      roles: ['admin', 'editor'],
      tapName: 'plane'
    },
    redirect: '/home/index',
    children: [
      {
        path: '/home/index',
        component: () => import('@/views/layout/components/main/home/index'),
        meta: {
          title: '概况',
          icon: 'iconfont icon-fuwudiqiu',
          roles: ['admin', 'editor'],
          tapName: 'plane'
        }
      }
    ]
  },
  {
    path: '/register',
    component: Layout,
    redirect: '/register/index',
    meta: {
      title: '飞机管理',
      icon: 'el-icon-edit-outline',
      roles: ['admin', 'editor'],
      tapName: 'plane'
    },
    children: [
      {
        path: '/register/index',
        component: () => import('@/views/layout/components/main/register/index'),
        meta: {
          title: '飞机列表',
          icon: 'el-icon-tickets',
          roles: ['admin', 'editor'],
          tapName: 'plane'
        }
      },
      {
        path: '/register/add',
        component: () => import('@/views/layout/components/main/register/add'),
        meta: {
          title: '添加飞机',
          icon: 'el-icon-plus',
          roles: ['admin', 'editor'],
          tapName: 'plane'
        }
      },
      {
        path: '/register/edit/:id',
        component: () => import('@/views/layout/components/main/register/add'),
        meta: {
          title: '更新飞机',
          icon: 'el-icon-edit',
          roles: ['admin', 'editor'],
          tapName: 'plane',
          hidden: true
        }
      },
      {
        path: '/register/crosFrequency',
        component: () => import('@/views/layout/components/main/register/crosFrequency'),
        meta: {
          title: '飞机对频',
          icon: 'el-icon-link',
          roles: ['admin', 'editor'],
          tapName: 'plane'
        }
      }
    ]
  },
  {
    path: '/route',
    component: Layout,
    redirect: '/route/index',
    meta: {
      title: '航线管理',
      icon: 'iconfont icon-feihangluxian',
      roles: ['admin', 'editor'],
      tapName: 'plane'
    },
    children: [
      {
        path: '/route/index',
        component: () => import('@/views/layout/components/main/route/index'),
        meta: {
          title: '航线列表',
          icon: 'iconfont icon-a-05-1-1jihuazhihanggenzong',
          roles: ['admin', 'editor'],
          tapName: 'plane'
        }
      },
      {
        path: '/route/add',
        component: () => import('@/views/layout/components/main/route/add'),
        meta: {
          title: '设计航线',
          icon: 'iconfont icon-huizhi',
          roles: ['admin', 'editor'],
          tapName: 'plane'
        }
      },
      {
        path: '/route/edit/:id',
        component: () => import('@/views/layout/components/main/route/add'),
        meta: {
          title: '编辑航线',
          icon: 'iconfont icon-huizhi',
          roles: ['admin', 'editor'],
          tapName: 'plane',
          hidden: true
        }
      }
    ]
  },
  {
    path: '/site',
    component: Layout,
    redirect: '/site/index',
    meta: {
      title: '站点管理',
      icon: 'iconfont icon-zhandianguanli',
      roles: ['admin', 'editor'],
      tapName: 'plane'
    },
    children: [
      {
        path: '/site/index',
        component: () => import('@/views/layout/components/main/site/index'),
        meta: {
          title: '站点列表',
          icon: 'el-icon-tickets',
          roles: ['admin', 'editor'],
          tapName: 'plane'
        }
      },
      {
        path: '/site/add',
        component: () => import('@/views/layout/components/main/site/add'),
        meta: {
          title: '添加站点',
          icon: 'el-icon-plus',
          roles: ['admin', 'editor'],
          tapName: 'plane'
        }
      },
      {
        path: '/site/edit/:id',
        component: () => import('@/views/layout/components/main/site/add'),
        meta: {
          title: '更新站点',
          icon: 'el-icon-edit',
          roles: ['admin', 'editor'],
          tapName: 'plane',
          hidden: true
        }
      }
    ]
  },
  {
    path: '/planes',
    component: Layout,
    redirect: '/planes/index',
    meta: {
      title: '无人机',
      icon: 'iconfont icon-wurenji',
      roles: ['admin', 'editor'],
      tapName: 'plane'
    },
    children: [
      {
        path: '/planes/index/:id/:name', // 动态加载路由时加ID参数
        component: () => import('@/views/layout/components/main/planes/index'),
        meta: {
          title: '飞机加载中',
          icon: 'el-icon-loading',
          roles: ['admin', 'editor'],
          tapName: 'plane'
        }
      }
    ]
  },
  {
    path: '/shop',
    component: Layout,
    redirect: '/shop/edit',
    meta: {
      title: '商铺管理',
      icon: 'iconfont icon-a-shanghu_choose2x1',
      roles: ['admin', 'editor'],
      tapName: 'admin'
    },
    children: [
      {
        path: '/shop/edit',
        component: () => import('@/views/layout/components/main/shop/add'),
        meta: {
          title: '商铺设置',
          icon: 'iconfont icon-dianpuguanli',
          roles: ['admin', 'editor'],
          tapName: 'admin'
        }
      },
      {
        path: '/shop/add',
        component: () => import('@/views/layout/components/main/shop/add'),
        meta: {
          title: '添加商铺',
          icon: 'iconfont icon-check',
          roles: ['admin', 'editor'],
          tapName: 'admin'
        }
      }
    ]
  },
  {
    path: '/admin',
    component: Layout,
    redirect: '/admin/index',
    meta: {
      title: '管理员管理',
      icon: 'iconfont icon-guanliyuan',
      roles: ['admin', 'editor'],
      tapName: 'admin'
    },
    children: [
      {
        path: '/admin/index',
        component: () => import('@/views/layout/components/main/admin/index'),
        meta: {
          title: '账户列表',
          icon: 'iconfont icon-yonghuguanli',
          roles: ['admin', 'editor'],
          tapName: 'admin'
        }
      },
      {
        path: '/admin/add',
        component: () => import('@/views/layout/components/main/admin/add'),
        meta: {
          title: '添加账户',
          icon: 'iconfont icon-xinzengguanliyuan',
          roles: ['admin', 'editor'],
          tapName: 'admin'
        }
      },
      {
        path: '/admin/edit/:id',
        component: () => import('@/views/layout/components/main/admin/add'),
        meta: {
          title: '编辑账户',
          icon: 'iconfont icon-huizhi',
          roles: ['admin', 'editor'],
          tapName: 'admin',
          hidden: true
        }
      }
    ]
  },
  {
    path: '/category',
    component: Layout,
    redirect: '/category/index',
    meta: {
      title: '分类管理',
      icon: 'iconfont icon-a-ziliaocaozuoxianshifenleishu',
      roles: ['admin', 'editor'],
      tapName: 'admin'
    },
    children: [
      {
        path: '/category/index',
        component: () => import('@/views/layout/components/main/category/index'),
        meta: {
          title: '分类管理',
          icon: 'iconfont icon-a-ziliaocaozuoxianshifenleishu',
          roles: ['admin', 'editor'],
          tapName: 'admin'
        }
      }
    ]
  },
  {
    path: '/product',
    component: Layout,
    redirect: '/spu/index',
    meta: {
      title: '商品管理',
      icon: 'iconfont icon-chanpin',
      roles: ['admin', 'editor'],
      tapName: 'admin'
    },
    children: [
      {
        path: '/spu/index',
        component: () => import('@/views/layout/components/main/product/spu/index'),
        meta: {
          title: 'SPU列表',
          icon: 'iconfont icon-chanpinliebiao-02',
          roles: ['admin', 'editor'],
          tapName: 'admin'
        }
      },
      {
        path: '/spu/add',
        component: () => import('@/views/layout/components/main/product/spu/add'),
        meta: {
          title: '添加SPU',
          icon: 'iconfont icon-huoquchanpin',
          roles: ['admin', 'editor'],
          tapName: 'admin'
        }
      },
      {
        path: '/spu/edit/:id',
        component: () => import('@/views/layout/components/main/product/spu/add'),
        meta: {
          title: '编辑SPU',
          icon: 'iconfont icon-huoquchanpin',
          roles: ['admin', 'editor'],
          tapName: 'admin',
          hidden: true
        }
      },
      {
        path: '/sku/index',
        component: () => import('@/views/layout/components/main/product/sku/index'),
        meta: {
          title: 'SKU列表',
          icon: 'iconfont icon-sku',
          roles: ['admin', 'editor'],
          tapName: 'admin'
        }
      },
      {
        path: '/sku/add',
        component: () => import('@/views/layout/components/main/product/sku/add'),
        meta: {
          title: '添加SKU',
          icon: 'iconfont icon-sku1',
          roles: ['admin', 'editor'],
          tapName: 'admin'
        }
      },
      {
        path: '/sku/edit/:id',
        component: () => import('@/views/layout/components/main/product/sku/add'),
        meta: {
          title: '编辑SKU',
          icon: 'iconfont icon-sku1',
          roles: ['admin', 'editor'],
          tapName: 'admin',
          hidden: true
        }
      }
    ]
  },
  {
    path: '/order',
    component: Layout,
    redirect: '/order/index',
    meta: {
      title: '订单与统计',
      icon: 'iconfont icon-dingdantongji',
      roles: ['admin', 'editor'],
      tapName: 'admin'
    },
    children: [
      {
        path: '/order/index',
        component: () => import('@/views/layout/components/main/order/index'),
        meta: {
          title: '订单管理',
          icon: 'iconfont icon-a-SalesOrderManagement',
          roles: ['admin', 'editor'],
          tapName: 'admin'
        }
      },
      {
        path: '/order/show/:id',
        component: () => import('@/views/layout/components/main/order/show'),
        meta: {
          title: '订单详情',
          icon: 'iconfont icon-a-SalesOrderManagement',
          roles: ['admin', 'editor'],
          tapName: 'admin',
          hidden: true
        }
      },
      {
        path: '/order/stat',
        component: () => import('@/views/layout/components/main/order/stat'),
        meta: {
          title: '销售统计',
          icon: 'iconfont icon-data-view',
          roles: ['admin', 'editor'],
          tapName: 'admin'
        }
      }
    ]
  },
  {
    path: '*',
    redirect: '/404',
    meta: {
      title: '404',
      roles: ['admin', 'editor'],
      hidden: true
    }
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
