import Vue from "vue";
import VueRouter from "vue-router";

import { getCookie } from "@/utils/getToken.js";

Vue.use(VueRouter);

const routes = [
  {
    path: "/jdbycquerytm",
    name: "jdbycquerytm",
    component: () => import("@/views/pages/jdbycquerytm")
  },
  {
    path: "/home",
    name: "home",
    component: () => import("@/views/pages/home")
  },
  {
    path: "/companyinformation",
    name: "companyinformation",
    component: () => import("@/views/pages/companyinformation")
  },
  // {
  //     path: "/",
  //     redirect: "/home"
  // },
  {
    path: "/",
    redirect: "/user"
  },
  {
    path: "/user",
    name: "user",
    redirect: "/user/login",
    component: () => import("@/views/pages/user"),
    children: [
      {
        path: "login",
        name: "login",
        component: () => import("@/views/pages/user/login")
      },
      {
        path: "register",
        name: "register",
        component: () => import("@/views/pages/user/register")
      },
      {
        path: "forgetpassword",
        name: "forgetpassword",
        component: () => import("@/views/pages/user/forgetPassword")
      }
    ]
  },
  {
    path: "/cashier",
    name: "cashier",
    component: () => import("@/views/pages/cashier")
  },
  {
    path: "/productdetails",
    name: "productdetails",
    component: () => import("@/views/pages/productdetails")
  },
  {
    path: "/successfulpayment",
    name: "successfulpayment",
    component: () => import("@/views/pages/successfulpayment")
  },
  {
    path: "/placeorder",
    name: "placeorder",
    component: () => import("@/views/pages/placeorder")
  },
  {
    path: "/jdbycdetailtm",
    name: "jdbycdetailtm",
    component: () => import("@/views/pages/jdbycdetailtm")
  },
  {
    path: "/companydetail",
    name: "companydetail",
    component: () => import("@/views/pages/companydetail")
  },
  {
    path: "/jdindentlist",
    name: "jdindentlist",
    component: () => import("@/views/pages/jdindentlist")
  },
  {
    path: "/jdindentdetail",
    name: "jdindentdetail",
    component: () => import("@/views/pages/jdindentdetail")
  },
  /////////
  {
    path: "/jdtrademark",
    name: "jdtrademark",
    component: () => import("@/views/pages/jdtrademark/Jdtrademark")
  },
  {
    path: "/selftmreg",
    name: "selftmreg",
    component: () => import("@/views/pages/selftmreg/Selftmreg")
  },
  {
    path: "/guaranteereg",
    name: "guaranteereg",
    component: () => import("@/views/pages/guaranteereg/Guaranteereg")
  },
  // 公告查询 十二期公告 首页
  {
    path: "/bycnoticetm",
    name: "bycnoticetm",
    component: () => import("@/views/pages/bycnoticetm/Bycnoticetm")
  },
  // 公告查询 查询页面 查询页
  {
    path: "/bycnoticeindex",
    name: "bycnoticeindex",
    component: () => import("@/views/pages/bycnoticeindex/Bycnoticeindex")
  },
  // 公告查询 公告详情页
  {
    path: "/bycnoticedetail",
    name: "bycnoticedetail",
    component: () => import("@/views/pages/bycnoticedetail/Bycnoticedetail")
  },
  ///// 政策后台页面
  {
    path: "/policyadmin",
    name: "policyadmin",
    component: () => import("@/views/pages/policyadmin/policyadmin.vue")
  },
  ///// 公司列表页
  {
    path: "/comapnylist",
    name: "comapnylist",
    component: () => import("@/views/fqembed/comapnylist.vue")
  },
  ///// 中转页面
  {
    path: "/needProxy",
    name: "needProxy",
    component: () => import("@/views/fqembed/needProxy.vue")
  },

];
const router = new VueRouter({
  routes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return { x: 0, y: 0 };
    }
  }
});

// router.beforeEach((to, from, next) => {
//   let userpin = getCookie("userpin");
//   if (
//     to.path == "/user/login" ||
//     to.path == "/user/register" ||
//     to.path == "/user/forgetPassword" ||
//     to.path == "/jdtrademark"
//   ) {
//     next();
//   } else {
//     if (userpin == "" || userpin == null) {
//       next("/user/login");
//     } else {
//       next();
//     }
//   }
// });

export default router;
