import Vue from 'vue';
import Router from 'vue-router';
import store from '../store/index';
import { getRoutes } from "@/common/utils";
import Layout from '../index.vue';


Vue.use(Router);

const router = new Router({
  mode: 'hash',
  base: process.env.VUE_APP_MOBILE_BASE_URL,
  routes: [
    {
      path: '/',
      component: () => import('../index.vue'),
      children: [
        {
          path: '/home', // 首页
          component: () => import('../views/index/home.vue'),
          meta: {
            title: '主页',
            icon: 'el-icon-s-home',
            requiresAuth: true,
        },
        },
        {
          path: '/error/:code',
          component: () => import('../views/error/index.vue'),
          meta: {
            title: 'error',requiresAuth : true 
          },
        },
        {
          path: '/UserAccount',
          component: () => import('../views/office/UserAccount.vue'),
          meta: {
            title: '个人账户',requiresAuth : true 
          },
        },
        {
          path: '/project',
          component: () => import('@/apps/mobile/views/project/project.vue'),
          meta: {
            title: '项目管理',requiresAuth : true 
          },
        },
        {
          path: '/Emergency',
          component: () => import('../views/Emergency/Emergency.vue'),
          meta: {
            title: '急修派工',requiresAuth : true 
          },
        },
        {
          path: '/UrgentRepair',
          name:'UrgentRepair',
          component: () => import('../views/Emergency/UrgentRepair.vue'),
          meta: {
            title: '急修中',requiresAuth : true 
          },
        },
        {
          path: '/Repair',
          component: () => import('../views/Emergency/Repair.vue'),
          meta: {
            title: '急修记录',requiresAuth : true 
          },
        },
        {
          path: '/CapitalRepair',
          component: () => import('../views/CapitalRepair/CapitalRepair.vue'),
          meta: {
            title: '大修管理',requiresAuth : true 
          },
        },
        {
          path: '/Userapplication',
          component: () => import('../views/Enterprise/Userapplication.vue'),
          meta: {
            title: '申请消息',requiresAuth : true 
          },
        },
        {
          path: '/MTCompanyUserPower',
          component: () => import('../views/Enterprise/MTCompanyUserPower.vue'),
          meta: {
            title: '成员管理',requiresAuth : true 
          },
        },
        {
          path: '/Region',
          component: () => import('../views/Enterprise/Region.vue'),
          meta: {
            title: '区域设置',requiresAuth : true 
          },
        },
        {
          path: '/MTCompanyUser',
          component: () => import('../views/Enterprise/MTCompanyUser.vue'),
          meta: {
            title: '组织设置',requiresAuth : true 
          },
        },
        {
          path: '/Global',
          component: () => import('../views/Enterprise/Global.vue'),
          meta: {
            title: '全局设置',requiresAuth : true 
          },
        },
        {
          path: '/MOptionCustom',
          component: () => import('../views/Enterprise/MOptionCustom.vue'),
          meta: {
            title: '保养单增项',requiresAuth : true 
          },
        },
        {
          path: '/LiftMaintenancePlan',
          component: () => import('../views/MaintenanceManagement/LiftMaintenancePlan.vue'),
          meta: {
            title: '维保计划',requiresAuth : true 
          },
        },
        {
          path: '/Maintenance',
          component: () => import('../views/MaintenanceManagement/Maintenance.vue'),
          meta: {
            title: '日常保养',requiresAuth : true 
          },
        },
        {
          path: '/StopMaintenancePlan',
          component: () => import('../views/MaintenanceManagement/StopMaintenancePlan.vue'),
          meta: {
            title: '停保管理',requiresAuth : true 
          },
        },
        {
          path: '/Liftcertificate',
          component: () => import('../views/office/Liftcertificate.vue'),
          meta: {
            title: '操作证管理',requiresAuth : true 
          },
        },
        {
          path: '/Attendance',
          component: () => import('../views/office/Attendance.vue'),
          meta: {
            title: '签到管理',requiresAuth : true 
          },
        },
        {
          path: '/Announcement',
          component: () => import('../views/office/Announcement.vue'),
          meta: {
            title: '公司公告',requiresAuth : true 
          },
        },
        {
          path: '/Lift',
          component: () => import('../views/Lift/Lift.vue'),
          meta: {
            title: '电梯档案',requiresAuth : true 
          },
        },{
          path: '/Inspection',
          component: () => import('../views/Inspection/Inspection.vue'),
          meta: {
            title: '年检管理',requiresAuth : true 
          },
        },
        
        {
          path: '/property',
          component: () => import('../views/maintenance/property.vue'),
          meta: {
            title: '客户管理',requiresAuth:true
          },
        },{
          path: '/CommonProblem',
          component: () => import('../views/CommonProblem/CommonProblem.vue'),
          meta: {
            title: '常见问题',requiresAuth:true
          },
        },{
          path: '/NewList',
          component: () => import('../views/NewList/NewList.vue'),
          meta: {
            title: '新闻公告',requiresAuth:true
          },
        },
        {
          path: '/Members',
          component: () => import('../views/Enterprise/Members.vue'),
          meta: {
            title: '角色设置',requiresAuth:true
          },
        },
        {
          path: '/user',
          component: () => import('../views/user/user.vue'),
          meta: {
            title: '用户设置',requiresAuth:true
          },
        },
        {
          path: '/contractManagement',
          component: () => import('../views/Contract/contractManagement.vue'),
          meta: {
            title: '合同管理',requiresAuth:true
          },
        },{
          path: '/collect',
          component: () => import('../views/Contract/collect.vue'),
          meta: {
            title: '收款管理',requiresAuth:true
        },
        
      },

      {
        path: '/monitoring-center/index',
        component: () => import('@/apps/mobile/views/monitoring-center-bank/index.vue'),
        meta: {
          title: '监控中心', 
          icon: 'el-icon-user-solid', 
          requiresAuth: true
        },
      },

    //   {
    //     path: '/monitoring-center', // 监控中心
    //     component: Layout,
    //     meta: {
    //         requiresAuth: true,
    //     },
    //     redirect: '/monitoring-center/index',
    //     children: [
    //         {
    //             path: 'index',
    //             component: () => import('../views/monitoring-center-bank/index.vue'),
    //             meta: {
    //                 title: '监控中心',
    //                 icon: 'el-icon-user-solid',
    //                 requiresAuth: true,
    //             },
    //         },
    //     ],
    // },
    {
        path: '/chat-room',
        component: () => import('@/apps/mobile/views/monitoring-center-bank/chat-room/chat-room.vue'),
        hidden: true,
        meta: {
            title: '聊天室',
        },
    },
    {
        path: '/data-bank', // 资料库
        component: Layout,
        meta: {
            title: '资料库',
            icon: 'el-icon-s-tools',
            requiresAuth: true,
        }
    },
    {
      path: '/data-bank/index',
      component: () => import('@/apps/mobile/views/data-bank/official/index.vue'),
      meta: {
          title: '官方文件管理',
          requiresAuth: true,
      },
    },
    {
      path: '/brand',
      component: () => import('@/apps/mobile/views/data-bank/brands/index.vue'),
      meta: {
          title: '品牌管理',
          requiresAuth: true,
      },
      redirect: '/brand/index',
      children: [
          {
              path: 'index',
              component: () => import('@/apps/mobile/views/data-bank/brands/brand/brand.vue'),
              meta: {
                  title: '品牌管理',
                  requiresAuth: true,
              },
          },
          {
              path: 'brand-details',
              component: () => import('@/apps/mobile/views/data-bank/brands/details/details.vue'),
              hidden: true,
              meta: {
                  title: '品牌详情',
                  requiresAuth: true,
              },
          },
      ],
    },
    {
      path: '/data-bank/classify',
      component: () => import('@/apps/mobile/views/data-bank/classify/index.vue'),
      meta: {
          title: '资料分类拓展',
          requiresAuth: true,
      },
    },
    {
      path: '/data-bank/accessory',
      component: () => import('@/apps/mobile/views/data-bank/accessory/index.vue'),
      meta: {
          title: '资料附件管理',
          requiresAuth: true,
      },
    },
    {
      path: '/data-bank/code',
      component: () => import('@/apps/mobile/views/data-bank/code/index.vue'),
      meta: {
          title: '故障代码管理',
          requiresAuth: true,
      },
    },
    {
      path: '/data-bank/operation',
      component: () => import('@/apps/mobile/views/data-bank/operation/index.vue'),
      meta: {
          title: '操作系统管理',
          requiresAuth: true,
      },
    },
    {
      path: '/data-bank/operation-accessory',
      component: () => import('@/apps/mobile/views/data-bank/operation-accessory/index.vue'),
      meta: {
          title: '操作系统附件管理',
          requiresAuth: true,
      },
    },
    {
        path: '/school', // 学堂管理
        component: Layout,
        meta: {
            requiresAuth: true,
            icon: 'el-icon-question',
            title: '学堂管理',
        },
        redirect: '/school/index',
    },
    {
      path: '/school/index',
      component: () => import('@/apps/mobile/views/school/index.vue'),
      meta: {
          title: '视频管理',
          requiresAuth: true,
      },
    },
    {
      path: '/school/video-approve',
      component: () => import('@/apps/mobile/views/school/approve.vue'),
      meta: {
          title: '视频审批',
          requiresAuth: true,
      },
    },
    {
        path: '/recruitment', // 招聘管理
        component: Layout,
        meta: {
            title: '招聘管理',
            icon: 'el-icon-s-tools',
            requiresAuth: true,
        },
        redirect: '/recruitment/index',
    },
    {
      path: '/recruitment/index',
      component: () => import('@/apps/mobile/views/recruitment/index/index.vue'),
      meta: {
          title: '招聘管理',
          requiresAuth: true,
      },
    },
    {
      path: '/recruitment/recruitment-approval',
      component: () => import('@/apps/mobile/views/recruitment/index/approval.vue'),
      meta: {
          title: '招聘审核',
          requiresAuth: true,
      },
    },
    {
      path: '/recruitment/recruitment-application',
      component: () => import('@/apps/mobile/views/recruitment/recruitment-application/index.vue'),
      meta: {
          title: '求职信息管理',
          requiresAuth: true,
      },
    },
    {
        path: '/template-library',
        component: Layout,
        meta: {
            title: '模板库',
            icon: 'el-icon-s-tools',
            requiresAuth: true,
        },
    },
    {
      path: '/template-library/maintenance',
      component: () => import('@/apps/mobile/views/template-library/maintenance/index.vue'),
      meta: {
          title: '维保项管理',
          requiresAuth: true,
      },
    },
    {
      path: '/template-library/template',
      component: () => import('@/apps/mobile/views/template-library/template/index.vue'),
      meta: {
          title: '系统模板管理',
          requiresAuth: true,
      },
    },
    {
      path: '/template-library/enterprise',
      component: () => import('@/apps/mobile/views/template-library/template/enterprise-template.vue'),
      meta: {
          title: '企业模板管理',
          requiresAuth: true,
      },
    },
    {
        path: '/state-bank', // 申诉管理
        component: Layout,
        meta: {
            title: ' 申诉管理',
            requiresAuth: true,
        },
        redirect: '/state-bank/index',
    },
    {
      path: '/state-bank/index',
      component: () => import('@/apps/mobile/views/state-bank/index.vue'),
      meta: {
          title: '申诉管理',
          icon: 'el-icon-question',
          requiresAuth: true,
      },
    },
    {
        path: '/question-bank', // 题库管理
        component: Layout,
        meta: {
            title: '题库管理',
            icon: 'el-icon-s-tools',
            requiresAuth: true,
        },
        redirect: '/question-bank/index',
    },
    {
      path: '/question-bank/index',
      component: () => import('@/apps/mobile/views/question-bank/index.vue'),
      meta: {
          title: '题库管理',
          requiresAuth: true,
      },
    },
    {
      path: '/question-bank/approval',
      component: () => import('@/apps/mobile/views/question-bank/approval/index.vue'),
      meta: {
          title: '题库审批',
          requiresAuth: true,
      },
    },
    {
        path: '/comment', //评论管理
        component: Layout,
        meta: {
            title: '评论管理',
            requiresAuth: true,
        },
        redirect: '/comment/index',
    },
    {
      path: '/comment/index',
      component: () => import('@/apps/mobile/views/comment/index.vue'),
      meta: {
          title: '评论管理',
          icon: 'el-icon-question',
          requiresAuth: true,
      },
    },
    {
        path: '/dialogue-bank', // 会话管理
        component: Layout,
        meta: {
            title: '会话管理',
            requiresAuth: true,
        },
        redirect: '/dialogue-bank/index',
    },
    {
      path: '/dialogue-bank/index',
      component: () => import('@/apps/mobile/views/dialogue-bank/index.vue'),
      meta: {
          title: '会话管理',
          icon: 'el-icon-question',
          requiresAuth: true,
      },
    },
    {
        path: '/card-bank', // 卡券管理
        component: Layout,
        meta: {
            requiresAuth: true,
            title: '卡券管理',
            icon: 'el-icon-question',
        },
        redirect: '/card-bank/index',
    },
    {
      path: '/card-bank/index',
      component: () => import('@/apps/mobile/views/card-bank/index.vue'),
      meta: {
          title: '卡券管理',
          requiresAuth: true,
      },
    },
    {
      path: '/card-bank/card-approve',
      component: () => import('@/apps/mobile/views/card-bank/approve/index.vue'),
      meta: {
          title: '卡券审批',
          requiresAuth: true,
      },
    },
    {
        path: '/expert-database', // 专家库
        component: Layout,
        meta: {
            title: '专家库',
            icon: 'el-icon-s-tools',
            requiresAuth: true,
        },
        redirect: '/expert-database/index',
    },
    {
      path: '/expert-database/index',
      component: () => import('@/apps/mobile/views/expert-database-bank/expert/index.vue'),
      meta: {
          title: '专家管理',
          requiresAuth: true,
      },
    },
    {
      path: '/expert-database/approval',
      component: () => import('@/apps/mobile/views/expert-database-bank/approval/index.vue'),
      meta: {
          title: '专家审批',
          requiresAuth: true,
      },
    },
    {
      path: '/expert-database/agreement',
      component: () => import('@/apps/mobile/views/expert-database-bank/agreement/index.vue'),
      meta: {
          title: '协议管理',
          requiresAuth: true,
      },
    },
    {
      path: '/expert-database/punishment',
      component: () => import('@/apps/mobile/views/expert-database-bank/punishment/index.vue'),
      meta: {
          title: '处罚记录',
          requiresAuth: true,
      },
    },
    {
        path: '/operation', // 运营设置
        component: Layout,
        meta: {
            title: '运营设置',
            icon: 'el-icon-s-tools',
            requiresAuth: true,
        },
        redirect: '/operation/index',
    },
    {
      path: '/operation/index',
      component: () => import('@/apps/mobile/views/operation-bank/user/index.vue'),
      meta: {
          title: '用户管理',
          requiresAuth: true,
      },
    },
    // {
    //   path: '/operation/privilege',
    //   component: () => import('@/apps/mobile/views/operation-bank/user-privilege/index.vue'),
    //   meta: {
    //       title: '用户特权',
    //       requiresAuth: true,
    //   },
    // },
    // {
    //   path: '/operation/privilege-approval',
    //   component: () => import('@/apps/mobile/views/operation-bank/user-privilege/approval.vue'),
    //   meta: {
    //       title: '用户特权审批',
    //       requiresAuth: true,
    //   },
    // },
    {
      path: '/operation/rule',
      component: () => import('@/apps/mobile/views/operation-bank/user-rule/index.vue'),
      meta: {
          title: '用户规则设置',
          requiresAuth: true,
      },
    },
    // {
            //     path: 'rule-approval',
            //     component: () => import('@/apps/mobile/views/operation-bank/user-rule/approval.vue'),
            //     meta: {
            //         title: '用户规则审核',
            //         requiresAuth: true,
            //     },
            // },
    {
      path: '/operation/member-fee',
      component: () => import('@/apps/mobile/views/operation-bank/member-fee/index.vue'),
      meta: {
          title: '会费管理',
          requiresAuth: true,
      },
    },
    {
      path: '/operation/fee-approve',
      component: () => import('@/apps/mobile/views/operation-bank/member-fee/approve.vue'),
      meta: {
          title: '会费审核',
          requiresAuth: true,
      },
    },
    {
      path: '/operation/reward',
      component: () => import('@/apps/mobile/views/operation-bank/reward/index.vue'),
      meta: {
          title: '赏金管理',
          requiresAuth: true,
      },
    },
    {
      path: '/operation/rebate-rule',
      component: () => import('@/apps/mobile/views/operation-bank/rebate-rule/index.vue'),
      meta: {
          title: '返利规则管理',
          requiresAuth: true,
      },
    },
    {
      path: '/operation/rebate-rule-approve',
      component: () => import('@/apps/mobile/views/operation-bank/rebate-rule/approval.vue'),
      meta: {
          title: '返利规则审核',
          requiresAuth: true,
      },
    },
    {
      path: '/operation/commission',
      component: () => import('@/apps/mobile/views/operation-bank/commission/index.vue'),
      meta: {
          title: '抽成设置',
          requiresAuth: true,
      },
    },
    {
      path: '/operation/commission-approval',
      component: () => import('@/apps/mobile/views/operation-bank/commission/approval.vue'),
      meta: {
          title: '抽成审核',
          requiresAuth: true,
      },
    },
    {
      path: '/operation/expert-upgrade-rule',
      component: () => import('@/apps/mobile/views/operation-bank/expert-upgrade-rule/index.vue'),
      meta: {
          title: '专家升级规则',
          requiresAuth: true,
      },
    },
    {
      path: '/operation/expert-upgrade-rule-approval',
      component: () => import('@/apps/mobile/views/operation-bank/expert-upgrade-rule/approval.vue'),
      meta: {
          title: '专家升级规则审核',
          requiresAuth: true,
      },
    },
    {
      path: '/operation/tax-rate',
      component: () => import('@/apps/mobile/views/operation-bank/tax-rate/index.vue'),
      meta: {
          title: '税率设置',
          requiresAuth: true,
      },
    },
    {
      path: '/operation/tax-rate-approval',
      component: () => import('@/apps/mobile/views/operation-bank/tax-rate/approval.vue'),
      meta: {
          title: '税率审核',
          requiresAuth: true,
      },
    },
    {
      path: '/operation/other-settings',
      component: () => import('@/apps/mobile/views/operation-bank/other-settings/index'),
      meta: {
          title: '其他设置',
          requiresAuth: true,
      },
    },
    {
      path: '/operation/other-settings-approval',
      component: () => import('@/apps/mobile/views/operation-bank/other-settings/approval'),
      meta: {
          title: '其他设置审核',
          requiresAuth: true,
      },
    },
            // {
            //     path: 'bonus-level',
            //     component: () => import('@/apps/mobile/views/operation-bank/bonus-level'),
            //     meta: {
            //         title: '打赏分档配置',
            //         requiresAuth: true,
            //     },
            // },
            // {
            //     path: 'bonus-level-approval',
            //     component: () => import('@/apps/mobile/views/operation-bank/bonus-level/approval'),
            //     meta: {
            //         title: '打赏分档审批',
            //         requiresAuth: true,
            //     },
            // },
    {
        path: '/banner', // banner管理
        component: Layout,
        meta: {
            requiresAuth: true,
        },
    },
    {
      path: '/banner/index',
      component: () => import('@/apps/mobile/views/banner/index.vue'),
      meta: {
          title: 'banner管理',
          icon: 'el-icon-question',
          requiresAuth: true,
      },
    },
    {
        path: '/payment', // 支付体系
        component: Layout,
        meta: {
            title: '支付体系',
            icon: 'el-icon-s-tools',
            requiresAuth: true,
        },
        redirect: '/payment/index',
    },
    {
      path: '/payment/index',
      component: () => import('@/apps/mobile/views/payment-bank/user-account/index.vue'),
      meta: {
          title: '用户账户管理',
          requiresAuth: true,
      },
    },
    {
      path: '/payment/withdraw-approve',
      component: () => import('@/apps/mobile/views/payment-bank/withdraw-approve/index.vue'),
      meta: {
          title: '用户提现审批',
          requiresAuth: true,
      },
    },
    {
      path: '/payment/platform-account',
      component: () => import('@/apps/mobile/views/payment-bank/platform-account/index.vue'),
      meta: {
          title: '平台账户管理',
          requiresAuth: true,
      },
    },
    {
      path: '/payment/audit-invoice',
      component: () => import('@/apps/mobile/views/payment-bank/audit-invoice/index.vue'),
      meta: {
          title: '发票审核',
          requiresAuth: true,
      },
    },
    {
        path: '/Sensitive-word-library', // 敏感词汇管理
        component: Layout,
        meta: {
            title: '敏感词汇管理',
            requiresAuth: true,
        },
    },
    {
      path: '/Sensitive-word-library/index',
      component: () => import('@/apps/mobile/views/Sensitive-word-library/index.vue'),
      meta: {
          title: '敏感词汇管理',
          icon: 'el-icon-question',
          requiresAuth: true,
      },
    },
    {
        path: '/shop', // 商品管理
        component: Layout,
        meta: {
            title: '商品管理',
            requiresAuth: true,
        },
    },
    {
      path: '/shop/index',
      component: () => import('@/apps/mobile/views/shop/index.vue'),
      meta: {
          title: '商品管理',
          icon: 'el-icon-question',
          requiresAuth: true,
      },
    },
    {
        path: '/authority', // 权限管理
        component: Layout,
        meta: {
            title: ' 权限管理',
            icon: 'el-icon-s-check',
            requiresAuth: true,
        },
        redirect: '/authority/index',
    },
    {
      path: '/authority/app-menu',
      component: () => import('@/apps/mobile/views/authority/app-menu/index.vue'),
      meta: {
          title: 'app菜单管理',
          requiresAuth: true,
      },
    },
    {
      path: '/authority/web-menu',
      component: () => import('@/apps/mobile/views/authority/web-menu/index.vue'),
      meta: {
          title: 'web菜单管理',
          requiresAuth: true,
      },
    },
  // {
  //     path: '/authority/backstage-menu',
  //     component: () => import('@/apps/mobile/views/authority/backstage-menu/index.vue'),
  //     meta: {
  //         title: '后台菜单管理',
  //         requiresAuth: true,
  //     },
  // },
    {
        path: '/personnel', // 人员轨迹
        component: Layout,
        meta: {
            title: '人员轨迹',
            requiresAuth: true,
        },
    },
    {
      path: '/personnel/index',
      component: () => import('@/apps/mobile/views/personnel/index.vue'),
      meta: {
          title: '人员轨迹',
          icon: 'el-icon-question',
          requiresAuth: true,
      },
    },
    {
      path: '/personnel', // 团队最新定位
      component: Layout,
      meta: {
          title: '团队最新定位',
          requiresAuth: true,
      },
    },
    {
      path: '/personnel/team',
      component: () => import('@/apps/mobile/views/personnel/team.vue'),
      meta: {
          title: '团队最新定位',
          icon: 'el-icon-question',
          requiresAuth: true,
      },
    },
        ...getRoutes(require.context('@/apps/mobile/views', true, /\/router\.js$/))

      ]
    },
    {
      path: '/login',
      component: () => import('../views/login/login.vue'),
      meta: {
        title: '登录'
      },
    },
    {
      path: '/register',
      component: () => import('../views/login/register.vue'),
      meta: {
        title: '注册'
      },
    },
    {
      path: '/unregister',
      component: () => import('../views/login/unregister.vue'),
      meta: {
        title: '忘记密码'
      },
    },
    {
      path: '/error/:code',
      component: () => import('../views/error/index.vue'),
      hidden: true,
      meta: {
          title: 'error',
      },
    },
    ...getRoutes(require.context('@/apps/mobile/views', true, /\/router\.js$/))
  ]
})


router.beforeEach((to, from, next) => {
  if (to.meta.requiresAuth) {         //如果需要跳转 ，往下走（1）
    console.log(store.state.token)
    if (store.state.token) {            //判断是否登录过，如果有登陆过，说明有token,或者token未过期，可以跳过登录（2）
      next();
      if (to.path === '/login') {    //判断下一个路由是否为要验证的路由（3）
        next('/home');         // 如果是直接跳到首页，
      } else {             //如果该路由不需要验证，那么直接往后走
        next();
      }
    } else {
      console.log('没有');      //如果没有登陆过，或者token 过期， 那么跳转到登录页
      next({
        path : '/login', // 登录页
      })
      // next('/login'); 
    }
  } else {                           //不需要跳转，直接往下走
    next();
  }
});

export default router