import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * 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"}' // 访问路由的默认传递参数
 * 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 = [

  {
    path: '/login',
    component: (resolve) => require(['@/views/login'], resolve),
    hidden: true
  },

  {
    path: '/404',
    component: (resolve) => require(['@/views/error/404'], resolve),
    hidden: true
  },
  {
    path: '/401',
    component: (resolve) => require(['@/views/error/401'], resolve),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: 'index',
    children: [
      {
        path: 'index',
        component: (resolve) => require(['@/views/index'], resolve),
        name: 'Index',
        meta: { title: '首页', icon: 'dashboard', affix: false }
      }
    ]
  },
  {
    path: '/doctor',
    component: Layout,
    // hidden: true,
    meta: { title: '医生信息', icon: 'user', noCache: true, affix: false },
    redirect: 'noredirect',
    children: [
      {
        path: 'doctorInfo',
        component: (resolve) => require(['@/views/doctor/profile/index'], resolve),
        name: '医生信息',
        meta: { title: '医生信息', icon: 'user', noCache: true, affix: false  }
      },
      // {
      //   path: 'config',
      //   component: (resolve) => require(['@/views/doctor/doctor/config'], resolve),
      //   name: '服务设置',
      //   meta: { title: '服务设置', icon: 'server' ,noCache: true, affix: false}
      // },

    ]
  },

  {
    path: '/prescribeAudit',
    component: Layout,
    redirect: 'noredirect',
    children: [
      {
        path: 'Index',
        component: (resolve) => require(['@/views/doctor/prescribeAudit/index'], resolve),
        name: '处方审核',
        meta: { title: '处方审核', icon: 'form', noCache: true, affix: false }
      }
    ]
  },

  // {
  //   path: '/order',
  //   component: Layout,
  //   meta: { title: '订单管理', icon: 'list', noCache: true, affix: false },
  //   redirect: 'noredirect',
  //   children: [
  //     {
  //       path: 'storeOrder',
  //       component: (resolve) => require(['@/views/order/storeOrder/index'], resolve),
  //       name: '药品订单',
  //       meta: { title: '药品订单', icon: 'dashboard', noCache: true, affix: false }
  //     },
  //     {
  //       path: 'inquiryOrder',
  //       component: (resolve) => require(['@/views/order/inquiryOrder/index'], resolve),
  //       name: '问诊订单',
  //       meta: { title: '问诊订单', icon: 'dict', noCache: true, affix: false }
  //     },
  //     {
  //       path: 'orderPing',
  //       component: (resolve) => require(['@/views/order/inquiryOrder/orderPing'], resolve),
  //       name: '患者评价',
  //       meta: { title: '患者评价', icon: 'job', noCache: true, affix: false }
  //     },
  //     // {
  //     //   path: 'prescribe',
  //     //   component: (resolve) => require(['@/views/his/prescribe/index'], resolve),
  //     //   name: '用户处方',
  //     //   meta: { title: '用户处方', icon: 'job', noCache: true, affix: false }
  //     // },
  //   ]
  // },

  // {
  //   path: '/myDrugStore',
  //   component: Layout,
  //   meta: { title: '我的药房', icon: 'nested', noCache: true, affix: false },
  //   redirect: 'noredirect',
  //   children: [
  //     {
  //       path: 'common',
  //       component: (resolve) => require(['@/views/myDrugStore/common'], resolve),
  //       name: '常用处方',
  //       meta: { title: '常用处方', icon: 'link', affix: false }
  //     },
  //     {
  //       path: 'history',
  //       component: (resolve) => require(['@/views/myDrugStore/history'], resolve),
  //       name: '历史处方',
  //       meta: { title: '历史处方', icon: 'log', affix: false }
  //     }
  //   ]
  // },
  // {
  //   path: '/doctorArticle',
  //   component: Layout,
  //   redirect: 'noredirect',
  //   children: [
  //     {
  //       path: 'Index',
  //       component: (resolve) => require(['@/views/doctorArticle/doctorArticle/index'], resolve),
  //       name: '文章管理',
  //       meta: { title: '文章管理', icon: 'tab', affix: false }
  //     }
  //   ]
  // },
  // {
  //   path: '/patient',
  //   component: Layout,
  //   redirect: 'noredirect',
  //   children: [
  //     {
  //       path: 'Index',
  //       component: (resolve) => require(['@/views/patient/patient/index'], resolve),
  //       name: '患者管理',
  //       meta: { title: '患者管理', icon: 'form', affix: false }
  //     }
  //   ]
  // },
  // {
  //   path: '/follow',
  //   component: Layout,
  //   redirect: 'noredirect',
  //   children: [
  //     {
  //       path: 'Index',
  //       component: (resolve) => require(['@/views/follow/follow/index'], resolve),
  //       name: '随访管理',
  //       meta: { title: '随访管理', icon: 'form', affix: false }
  //     }
  //   ]
  // },
  // {
  //   path: '/drugReport',
  //   component: Layout,
  //   redirect: 'noredirect',
  //   children: [
  //     {
  //       path: 'Index',
  //       component: (resolve) => require(['@/views/drugReport/drugReport/index'], resolve),
  //       name: '用药报告',
  //       meta: { title: '用药报告', icon: 'form', affix: false }
  //     }
  //   ]
  // },
  // {
  //    path: '/moneys',
  //    component: Layout,
  //    meta: { title: '财务管理', icon: 'money', noCache: true, affix: false },
  //    redirect: 'noredirect',
  //    children: [
  //      {
  //        path: 'extract',
  //        component: (resolve) => require(['@/views/moneys/extract/index'], resolve),
  //        name: '提现管理',
  //        meta: { title: '提现管理', icon: 'log', noCache: true, affix: false }
  //      },
  //      {
  //        path: 'bill',
  //        component: (resolve) => require(['@/views/moneys/bill/index'], resolve),
  //        name: '收入管理',
  //        meta: { title: '收入管理', icon: 'guide', noCache: true, affix: false }
  //      }
  //    ]
  //  },
  //  {
  //   path: '/watch',
  //   component: Layout,
  //   // hidden: true,
  //   meta: { title: '腕表管理', icon: 'time-range', noCache: true, affix: false },
  //   redirect: 'noredirect',
  //   children: [
  //     {
  //       path: 'deviceInfo',
  //       component: (resolve) => require(['@/views/watch/deviceInfo/index'], resolve),
  //       name: '腕表管理',
  //       meta: { title: '腕表管理', icon: 'chart', noCache: true, affix: false  }
  //     },
  //     // {
  //     //   path: 'materials',
  //     //   component: (resolve) => require(['@/views/watch/materials/index'], resolve),
  //     //   name: '设备物料',
  //     //   meta: { title: '设备物料', icon: 'documentation' ,noCache: true, affix: false}
  //     // },
  //     // {
  //     //   path: 'materialsType',
  //     //   component: (resolve) => require(['@/views/watch/materialsType/index'], resolve),
  //     //   name: '设备物料种类',
  //     //   meta: { title: '设备物料种类', icon: 'guide' ,noCache: true, affix: false}
  //     // },
  //   ]
  // },
  {
    path: '/watch/deviceInfo/details',
    component: Layout,
    hidden: true,
    children: [
      {
        path: ':deviceId(\\d+)',
        component: (resolve) => require(['@/views/watch/deviceInfo/details'], resolve),
        name: 'details',
        meta: { title: '设备详情', activeMenu: '/watch/deviceInfo'}
      }
    ]
  }
]
const originalPush = Router.prototype.push
Router.prototype.push = function push (location, onResolve, onReject) {
  if (onResolve || onReject){
    return originalPush.call(this, location, onResolve, onReject)
  }
  return originalPush.call(this, location).catch(err => err)
}

export default new Router({
  mode: 'history', // 去掉url中的#
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
