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

// 视图组件
const PageView = () => import('@/layout/PageView')

Vue.use(Router)

/* Routes Config
* @meta
* icon: ''                      菜单图标（支持svg-icon、el-icon）
* title: ''                     菜单标题
* login: false                  是否需要登录
* ss: 'admin' || ['admin']    是否需要权限
* keep: false                   是否需要缓存（需要name才能生效）
* hidden: false                 是否显示在菜单
* open: false                   是否展开菜单（有子菜单前提下）
* redirectIndex: 0              重定向到第index位子菜单（有子菜单前提下）
* affix: false                  是否常驻在tagView组件上（外链无效）
*/

// 异步路由
export const asyncRoutes = [
    {
        name: 'dashboard',
        path: 'dashboard',
        component: () => import('@/pages/index/children/dashboard'),
        meta: {
            icon: 'dashboard',
            affix: true
        }
    },
    {
        name: 'operator_management',
        path: 'operator_management',
        component: () => import('@/pages/operator_management/operator_management'),
        meta: {
            icon: 'documentation',
            keep: true
        }
    },
    // {
    //     name: 'service_provider_management',
    //     path: 'service_provider_management',
    //     component: () => import('@/pages/service_provider_management/service_provider_management'),
    //     meta: {
    //         icon: 'documentation',
    //         keep: true
    //     }
    // },
    {
        name: 'EntInit',
        path: '/ent-init',
        component: PageView,
        meta: {
            icon: 'documentation'
        },
        children: [
            {
                name: 'EntInitManage',
                path: '/ent-init-manage',
                component: () => import('@/pages/ent-init/manage'),
                meta: {
                    icon: 'documentation',
                    keep: true
                }
            },
            {
                name: 'EntInitDevice',
                path: '/ent-init-device',
                component: () => import('@/pages/ent-init/device'),
                meta: {
                    icon: 'documentation',
                    // 页面缓存会导致其它页面无法传递值到该页面，
                    // 暂时不使用页面缓存。
                    // keep: true
                }
            },
            // {
            //     name: 'one_ent_init',
            //     path: '/one_ent_init',
            //     component: () => import('@/pages/ent_init/one_ent_init'),
            //     meta: {
            //         icon: 'documentation',
            //         keep: true
            //     }
            // },
            // {
            //     name: 'multiple_ent_init',
            //     path: '/multiple_ent_init',
            //     component: () => import('@/pages/ent_init/multiple_ent_init'),
            //     meta: {
            //         icon: 'documentation',
            //         keep: true
            //     }
            // },
            // {
            //     name: 'multiple_ent_init_file_details',
            //     path: '/multiple_ent_init_file_details',
            //     component: () => import('@/pages/ent_init/multiple_ent_init/file_details'),
            //     meta: {
            //         icon: 'documentation',
            //         hidden: true
            //     }
            // },
            {
                name: 'ScanDeviceServer',
                path: '/scan-device-server',
                component: () => import('@/pages/ent-init/scan-device-server'),
                meta: {
                    icon: 'documentation',
                    keep: true
                }
            },
            {
                name: 'binding_enterprises',
                path: '/scan-device-binding_enterprises',
                component: () => import('@/pages/binding_enterprises/binding_enterprises'),
                meta: {
                    icon: 'documentation',
                    keep: true
                }
            },
            {
                name: 'customer_batch_import',
                path: '/customer_batch_import',
                component: () => import('@/pages/ent_services/customer_batch_import'),
                meta: {
                    icon: 'documentation',
                    keep: true
                }
            },
            {
                name: 'customer_batch_file_details',
                path: '/customer_batch_file_details',
                component: () => import('@/pages/ent_services/customer_batch_file_details'),
                meta: {
                    icon: 'documentation',
                    hidden: true,
                    keep: true
                }
            },
            {
                name: 'product_batch_import',
                path: '/product_batch_import',
                component: () => import('@/pages/ent_services/product_batch_import'),
                meta: {
                    icon: 'documentation',
                    keep: true
                }
            },
            {
                name: 'product_batch_file_details',
                path: '/product_batch_file_details',
                component: () => import('@/pages/ent_services/product_batch_file_details'),
                meta: {
                    icon: 'documentation',
                    hidden: true,
                    keep: true
                }
            }
        ]
    },
    {
        name: 'enterprise_info',
        path: 'enterprise_info',
        component: PageView,
        meta: {
            icon: 'documentation'
        },
        children: [
            {
                name: 'ISPEntUser',
                path: '/ISPEntUser',
                component: () => import('@/pages/enterprise_info/isp-ent-user'),
                meta: {
                    icon: 'documentation',
                    keep: true
                }
            },
            // {
            //     name: 'enterprise_info',
            //     path: '/enterprise_info',
            //     component: () => import('@/pages/enterprise_info/enterprise_info'),
            //     meta: {
            //         icon: 'documentation',
            //         keep: true
            //     }
            // },
            {
                name: 'baiwang_account_query',
                path: '/baiwang_account_query',
                component: () => import('@/pages/enterprise_info/baiwang_account_query'),
                meta: {
                    icon: 'documentation',
                    keep: true
                }
            }
        ]
    },
    {
        name: 'mechanism_manage',
        path: 'mechanism_manage',
        component: PageView,
        meta: {
            icon: 'documentation'
        },
        children: [
            {

                name: 'agent_account_company',
                path: 'agent_account_company',
                component: () => import('@/pages/mechanism_manage/agent_account_company'),
                meta: {
                    icon: 'documentation',
                    keep: true
                }
            }
        ]
    },
    {
        name: 'invoice_management',
        path: 'invoice_management',
        component: PageView,
        meta: {
            icon: 'documentation'
        },
        children: [
            {
                name: 'invoice_query',
                path: '/invoice_query',
                component: () => import('@/pages/invoice_management/invoice_query'),
                meta: {
                    icon: 'documentation',
                    keep: true
                }
            },
            {
                name: 'invoice_exception',
                path: '/invoice_exception',
                component: () => import('@/pages/invoice_management/invoice_exception'),
                meta: {
                    icon: 'documentation',
                    keep: true
                }
            },
            {
                name: 'invoice_failed',
                path: '/invoice_failed',
                component: () => import('@/pages/invoice_management/invoice_failed'),
                meta: {
                    icon: 'documentation',
                    keep: true
                }
            },
        ]
    },
    {
        name: 'MessagePush',
        path: '/message-push',
        component: PageView,
        meta: {
            icon: 'documentation',
        },
        children: [
            {
                name: 'MessageSend',
                path: '/message-send',
                component: () => import('@/pages/message-push/send'),
                meta: {
                    icon: 'documentation',
                    keep: true
                }
            },
            {
                name: 'MessageHistory',
                path: '/message-history',
                component: () => import('@/pages/message-push/history'),
                meta: {
                    icon: 'documentation',
                    keep: true
                }
            }
        ]
    },
    {
        name: 'Commodity',
        path: '/commodity',
        component: PageView,
        meta: {
            icon: 'documentation',
        },
        children: [
            {
                name: 'CommodityAll',
                path: '/commodity-all',
                component: () => import('@/pages/commodity/all'),
                meta: {
                    icon: 'documentation',
                    keep: true
                }
            },
            {
                name: 'CommodityAdd',
                path: '/commodity-add',
                component: () => import('@/pages/commodity/add'),
                meta: {
                    icon: 'documentation',
                    keep: true
                }
            }
        ]
    },
    {
        name: 'ISPInfo',
        path: '/isp-info',
        component: () => import('@/pages/isp/info'),
        meta: {
            icon: 'documentation',
        }
    },
    {
        name: 'transaction',
        path: '/transaction',
        component: PageView,
        meta: {
            icon: 'documentation'
        },
        children: [
            {
                name: 'transaction_info',
                path: '/transaction_info',
                component: () => import('@/pages/transaction/transaction_info'),
                meta: {
                    icon: 'documentation',
                    keep: true
                }
            }
        ]
    },
    {
        name: 'coupon',
        path: '/coupon',
        component: PageView,
        meta: {
            icon: 'documentation'
        },
        children: [
            {
                name: 'coupon_manage',
                path: '/coupon_manage',
                component: () => import('@/pages/coupon/coupon_manage'),
                meta: {
                    icon: 'documentation',
                    keep: true
                }
            }
        ]
    },
    {
        name: 'operation_log',
        path: 'operation_log',
        component: PageView,
        meta: {
            icon: 'documentation'
        },
        children: [
            {
                name: 'operation_log',
                path: 'operation_log',
                component: () => import('@/pages/operation_log/operation_log'),
                meta: {
                    icon: 'documentation',
                    keep: true
                }
            }
        ]
    }
]

// 本地路由
export const localRoutes = [
    {
        path: '',
        redirect: '/login'
    },
    {
        path: '/login',
        component: () => import('@/pages/login/login')
    },
    {
        path: '/page401',
        component: () => import('@/pages/other/page401')
    },
    {
        path: '/page404',
        component: () => import('@/pages/other/page404')
    }
]

const createRouter = () => new Router({
    // mode: 'history',
    routes: localRoutes,
    scrollBehavior: () => ({ y: 0 })
})

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
