import Vue from 'vue'
import Router from 'vue-router'
// import store from '../store'
import auth from '../service/auth'

Vue.use(Router)

const router = new Router({
    mode: 'history',
    // mode: 'hash',
    base: process.env.BASE_URL,
    routes: [
        {
            path: '/citySafeNoticBefore',
            name: 'citySafeNoticBefore',
            meta: {
                title: '城市安全通知公告'
            },
            component: () => import('@/pages/citySafeNotic/indexBefore.vue')
        },
        {
            path: '/cityDangerReportBefore',
            name: 'cityDangerReportBefore',
            meta: {
                title: '城市隐患上报前置'
            },
            component: () => import('@/pages/cityDangerReport/indexBefore.vue')
        },
        {
            path: '/login',
            name: 'login',
            meta: {
                title: '登录'
            },
            component: () => import('@/pages/login/login.vue')
        },
        {
            path: '/citySafeNoticDetail',
            name: 'citySafeNoticDetail',
            meta: {
                title: '城市安全通知公告'
            },
            component: () => import('@/pages/citySafeNotic/detail.vue')
        },
        {
            path: '/citySafeNotic',
            name: 'citySafeNotic',
            meta: {
                title: '城市安全通知公告'
            },
            component: () => import('@/pages/citySafeNotic/index.vue')
        },

        {
            path: '/cityDangerReport',
            name: 'cityDangerReport',
            meta: {
                title: '城市隐患上报'
            },
            component: () => import('@/pages/cityDangerReport/index.vue')
        },

        {
            path: '/addcityDangerReport',
            name: 'addcityDangerReport',
            meta: {
                title: '城市隐患上报'
            },
            component: () => import('@/pages/cityDangerReport/add.vue')
        },
        {
            path: '/home',
            name: 'home',
            meta: {
                title: '修改密码'
            },
            component: () => import('@/pages/homePage/homeTabBar.vue'),
            children: [
                {
                    path: '/home/home',
                    name: 'home',
                    meta: {
                        title: '首页'
                    },
                    component: () =>
                        import('@/pages/homePage/components/home.vue')
                },
                {
                    path: '/home/mine',
                    name: 'mine',
                    meta: {
                        title: '我的'
                    },
                    component: () =>
                        import('@/pages/homePage/components/mine.vue')
                }
            ]
        },
        {
            path: '/register',
            name: 'register',
            meta: {
                title: '修改密码'
            },
            component: () => import('@/pages/homePage/register.vue')
        },
        {
            path: '/todo',
            name: 'todo',
            meta: {
                title: '待办',
            },
            component: () =>
                import('@/pages/todo/index.vue')
        },
        {
            path: '/enterpriseInformation',
            name: 'enterpriseInformation',
            meta: {
                title: '企业信息',
            },
            component: () =>
                import('@/pages/homeItems/information-Index.vue')
        },
        {
            path: '/registerbycpyinfo',
            name: 'registerbycpyinfo',
            meta: {
                title: '注册',
            },
            component: () =>
                import('@/pages/homeItems/registerbycpyinfo.vue')
        },
        {
            path: '/personList',
            name: 'personList',
            meta: {
                title: '人员名单'
            },
            component: () => import('@/pages/homeItems/personList.vue')
        },
        {
            path: '/addStaff',
            name: 'addStaff',
            meta: {
                title: '员工信息'
            },
            component: () => import('@/pages/homeItems/Detail/addStaff.vue')
        },
        {
            path: '/suspected',
            name: 'suspected',
            meta: {
                title: '疑似离职确认'
            },
            component: () => import('@/pages/homeItems/suspected.vue')
        },
        {
            path: '/suspectedDetail',
            name: 'suspectedDetail',
            meta: {
                title: '疑似离职'
            },
            component: () =>
                import('@/pages/homeItems/Detail/suspectedDetail.vue')
        },
        {
            path: '/abnormal',
            name: 'abnormal',
            meta: {
                title: '扫码异常'
            },
            component: () => import('@/pages/homeItems/abnormal.vue')
        },

        {
            path: '/abnormalDetail',
            name: 'abnormalDetail',
            meta: {
                title: '人员详情'
            },
            component: () =>
                import('@/pages/homeItems/Detail/abnormalDetail.vue')
        },
        {
            path: '/vistiorRegistration',
            name: 'vistiorRegistration',
            meta: {
                title: '访客登记'
            },
            component: () =>
                import('@/pages/visitorSide/vistiorRegistration.vue')
        },
        {
            path: '/visitorExamine',
            name: 'visitorExamine',
            meta: {
                title: '访客审核'
            },
            component: () => import('@/pages/homeItems/visitorExamine.vue')
        },
        {
            path: '/vistorDetail',
            name: 'vistorDetail',
            meta: {
                title: '访客审核详情'
            },
            component: () => import('@/pages/homeItems/Detail/vistorDetail.vue')
        },
        {
            path: '/QRcode',
            name: 'QRcode',
            meta: {
                title: '二维码申请'
            },
            component: () => import('@/pages/QRcode/QRapplication.vue')
        },
        {

            path: '/enterpriseReporting',
            name: 'enterpriseReporting',
            meta: {
                title: '企业填报'
            },
            component: () => import('@/pages/homeItems/enterpriseReporting.vue')
        },
        {

            path: '/enterpriseReportingDetail',
            name: 'enterpriseReportingDetail',
            meta: {
                title: '企业填报详情'
            },
            component: () => import('@/pages/homeItems/enterpriseReportingDetail.vue')
        },
        {

            path: '/settle_in',
            name: 'settle_in',
            meta: {
                title: '我的入驻'
            },
            component: () => import('@/pages/homeItems/settle_in.vue')
        },
        {

            path: '/settle_out',
            name: 'settle_out',
            meta: {
                title: '退租申请'
            },
            component: () => import('@/pages/homeItems/settle_out.vue')
        },
        {

            path: '/rzsq',
            name: 'rzsq',
            meta: {
                title: '入驻单'
            },
            component: () => import('@/pages/homeItems/Detail/rzsq.vue')
        },
        {

            path: '/tzsq',
            name: 'tzsq',
            meta: {
                title: '退租申请'
            },
            component: () => import('@/pages/homeItems/Detail/tzsq.vue')
        },
        {

            path: '/related-qualifications',
            name: 'related-qualifications',
            meta: {
                title: '相关资质'
            },
            component: () => import('@/pages/homeItems/components/related-qualifications.vue')
        },
        {

            path: '/addTzsq',
            name: 'addTzsq',
            meta: {
                title: '新增退租申请'
            },
            component: () => import('@/pages/homeItems/Detail/addTzsq.vue')
        },
        {

            path: '/my-bill',
            name: 'my-bill',
            meta: {
                title: '我的账单'
            },
            component: () => import('@/pages/homeItems/my-bill.vue')
        },
        {

            path: '/billDetail',
            name: 'billDetail',
            meta: {
                title: '我的账单'
            },
            component: () => import('@/pages/homeItems/Detail/billDetail.vue')
        },
        {

            path: '/webView',
            name: 'webView',
            meta: {
                title: '1'
            },
            component: () => import('@/pages/login/webView.vue')
        },
        // {
        //     path: '/venueRoom',
        //     name: 'venueRoom',
        //     meta: {
        //         title: '场馆列表'
        //     },
        //     component: () => import('@/pages/venue/index.vue')
        // },
        {
            path: '/venue',
            name: 'venue',
            meta: {
                title: '场馆列表'
            },
            component: () => import('@/pages/venue/index.vue')
        },
        {
            path: '/modifyHandle',
            name: 'modifyHandle',
            meta: {
                title: '案卷处理'
            },
            component: () => import('@/pages/modifyHandle/index.vue')
        },
        {
            path: '/saveCallback',
            name: 'saveCallback',
            meta: {
                title: '安全反馈'
            },
            component: () => import('@/pages/saveCallback/index.vue')
        },
        {
            path: '/saveCallbackdetail',
            name: 'saveCallbackDetail',
            meta: {
                title: '安全反馈-详情'
            },
            component: () => import('@/pages/saveCallback/detail.vue')
        },
        {
            path: '/saveCallbackHandle',
            name: 'saveCallback',
            meta: {
                title: '安全反馈处理'
            },
            component: () => import('@/pages/saveCallback/handle.vue')
        },
        {
            path: '/modifyHandleDetail',
            name: 'modifyHandleDetail',
            meta: {
                title: '案卷处理'
            },
            component: () => import('@/pages/modifyHandle/handle.vue')
        },
        {
            path: '/venue/detail',
            name: 'venueRoom-detail',
            meta: {
                title: '场馆-详情'
            },
            component: () => import('@/pages/venue/detail.vue')
        },
        {
            path: '/venue/reserve',
            name: 'venue-reserve',
            meta: {
                title: '场馆预约'
            },
            component: () => import('@/pages/venue/reserve.vue')
        },
        {
            path: '/venue/paymentVoucher',
            name: 'venue-paymentVoucher',
            meta: {
                title: '上传支付凭证'
            },
            component: () => import('@/pages/venue/paymentVoucher.vue')
        },


        {
            path: '/meetingFerenceRoom',
            name: 'meetingRoom',
            meta: {
                title: '会议室列表'
            },
            component: () => import('@/pages/meetingRoom/index.vue')
        },
        {
            path: '/meetingRoom/detail',
            name: 'meetingRoom-detail',
            meta: {
                title: '会议室-详情'
            },
            component: () => import('@/pages/meetingRoom/detail.vue')
        },
        {
            path: '/meetingRoom/reserve',
            name: 'meetingRoom-reserve',
            meta: {
                title: '会议室预约'
            },
            component: () => import('@/pages/meetingRoom/reserve.vue')
        },
        {
            path: '/meetingRoom/paymentVoucher',
            name: 'meetingRoom-paymentVoucher',
            meta: {
                title: '上传支付凭证'
            },
            component: () => import('@/pages/meetingRoom/paymentVoucher.vue')
        },
        {
            path: '/saveInfoList',
            name: 'saveInfoList',
            meta: {
                title: '安全管理知识库'
            },
            component: () => import('@/pages/homeItems/saveInfoList.vue')
        },
        {
            path: '/saveInfo',
            name: 'saveInfo',
            meta: {
                title: '安全管理详情'
            },
            component: () => import('@/pages/homeItems/Detail/saveInfo.vue')
        },
        {
            path: '/reportRepair',
            name: 'reportRepair',
            meta: {
                title: '政企服务'
            },
            component: () => import('@/pages/reportRepair/index.vue')
        }, {
            path: '/repairRecord',
            name: 'repairRecord',
            meta: {
                title: '上报记录'
            },
            component: () => import('@/pages/reportRepair/repairRecord.vue')
        }, {
            path: '/repairDetail',
            name: 'repairDetail',
            meta: {
                title: '报事详情'
            },
            component: () => import('@/pages/reportRepair/repairDetail.vue')
        }, {
            path: '/parkActivities',
            name: 'parkActivities',
            meta: {
                title: '园区活动'
            },
            component: () => import('@/pages/parkActivities/index.vue')
        }, {
            path: '/parkActivities/style',
            name: 'parkActivities-style',
            meta: {
                title: '活动风采'
            },
            component: () => import('@/pages/parkActivities/style.vue')
        }, {
            path: '/parkActivities/detail',
            name: 'parkActivities-detail',
            meta: {
                title: '活动详情'
            },
            component: () => import('@/pages/parkActivities/detail.vue')
        },
        {
            path: '/announcement',
            name: 'announcement',
            meta: {
                title: '通知公告'
            },
            component: () => import('@/pages/announcement/index.vue')
        }, {
            path: '/announcement/detail',
            name: 'announcement-detail',
            meta: {
                title: '通知公告'
            },
            component: () => import('@/pages/announcement/detail.vue')
        }
    ]
})

// 无路由守卫
// router.beforeEach((to, from, next) => {
//     if (to.path == "/") {
//         alert("点击确认浏览测试页面");
//         next("/login");
//     } else {
//         next();
//     } // 修改显示标题
//     document.title = to.matched[0].meta.title;

// });

// 路由守卫 拦截
const whiteList = ['citySafeNoticDetail','citySafeNoticBefore','cityDangerReportBefore','vistiorRegistration', 'login', 'register', 'QRcode', 'todo', 'webView', 'registerbycpyinfo', 'cityDangerReport', `addcityDangerReport`,'citySafeNotic'] // 路由守卫白名单

router.beforeEach((to, from, next) => {
    /* 路由发生变化修改页面title */
    if (to.meta.title) {
        document.title = to.meta.title
    }
    if (whiteList.includes(to.name)) {
        // 在免登录白名单，直接进入
        next()
    } else if (to.path == '/home/home') {
        const uid = auth.uid()
        if (uid) {
            next()
        } else {
            next({
                path: '/cityDangerReportBefore',
                query: to.query
            })
        }
    } else if (to.path !== '/login') {
        const uid = auth.uid()
        if (auth.getUserType() === auth.TYPE_FRAME) {
            if (uid) {
                if (to.path === '/') {
                    next({
                        path: '/home/home'
                    })
                }
                next()
            } else if (to.path === '/register') {
                next()
            } else {
                next({
                    path: '/login'
                })
            }
        } else {
            next({
                path: '/login'
            })
        }
    } else {
        next()
    }
})

export default router
