import Vue from 'vue'
import VueRouter from 'vue-router'
import store from "@/store"

Vue.use(VueRouter)

const ViewsCom = {
  // TAB
  Home: () => import('@/views/tab-bar/home'),
  Classification: () => import('@/views/tab-bar/classification'),
  ShoppingCart: () => import('@//views/tab-bar/shopping-cart'),
  UserCenter: () => import('@/views/tab-bar/user-center'),

  // 登录
  Login: () => import("@/views/login"),
  Registration: () => import("@/views/agreement/registration"),
  Privacy: () => import("@/views/agreement/privacy"),

  // 搜索
  Search: () => import('@/views/search/search'),
  SearchResult: () => import('@/views/search/list'),

  // 商铺、商品、评论、下单
  Shop: () => import("@/views/shop/detail"),
  ShopInfo: () => import("@/views/shop/info"),
  ShopCouponCenter: () => import("@/views/shop/coupon-center"),
  Goods: () => import("@/views/goods"),
  CommentList: () => import("@/views/comment/list"),
  CommentDetail: () => import("@/views/comment/detail"),
  OrderConfirm: () => import("@/views/order/confirm"),
  Payment: () => import("@/views/order/payment"),
  PayResult: () => import("@/views/order/pay-result"),
  //盲盒
  BlindBox: () => import("@/views/blind-box"),

  // 转让市场
  TransferMarket: () => import("@/views/transfer/market"),
  TransferTopList: () => import("@/views/transfer/top-list"),
  TransferGoodList: () => import("@/views/transfer/good-list"),
  TransferClassificationList: () => import("@/views/transfer/classification-list"),

  // 个人中心
  //   地址相关
  AddressList: () => import("@/views/user-center/address/list"),
  AddExpressAddr: () => import("@/views/user-center/address/add-express-addr"),
  AddCoinAddr: () => import("@/views/user-center/address/add-coin-addr"),
  //   订单相关
  OrderList: () => import("@/views/user-center/order/list"),
  OrderSearch: () => import("@/views/user-center/order/search"),
  OrderDetail: () => import("@/views/user-center/order/detail/order"),
  DeliveryDetail: () => import("@/views/user-center/order/detail/delivery"),
  DeliveryExpressDetail: () => import("@/views/user-center/order/express-detail"),
  //   评论相关
  ReleaseComment: () => import("@/views/user-center/comment/release"),
  ReleaseCommentResult: () => import("@/views/user-center/comment/result"),
  UnCommentList: () => import("@/views/user-center/comment/un-comment-list"),
  //   售后相关
  ApplyRefund: () => import("@/views/user-center/after-sale/apply"),
  SubmitRefund: () => import("@/views/user-center/after-sale/submit"),
  ApplyRefundExpress: () => import("@/views/user-center/after-sale/refund-express"),
  RefundList: () => import("@/views/user-center/after-sale/list"),
  RefundMoneyDetail: () => import("@/views/user-center/after-sale/refund-detail/money"),
  RefundGoodsDetail: () => import("@/views/user-center/after-sale/refund-detail/goods"),
  RefundExpressDetail: () => import("@/views/user-center/after-sale/express-detail"),
  //   分享邀请
  ShareInvite: () => import("@/views/user-center/share-invite"),
  //   个人信息
  PersonalInfo: () => import("@/views/user-center/personal-info"),
  //   设置
  Settings: () => import("@/views/user-center/settings/settings"),
  UpdatePayPwd: () => import("@/views/user-center/settings/update-pay-pwd"),
  Authentication: () => import("@/views/user-center/settings/authentication"),
  AboutUs: () => import("@/views/user-center/settings/about-us"),
  //   投诉
  ApplyComplaint: () => import("@/views/user-center/complaint/apply"),
  ComplaintList: () => import("@/views/user-center/complaint/list"),
  ComplaintDetail: () => import("@/views/user-center/complaint/detail"),
  //   收藏
  GoodsCollection: () => import("@/views/user-center/goods-collection"),
  //   关注
  ShopFollow: () => import("@/views/user-center/shop-follow"),
  //   足迹
  BrowseHistory: () => import("@/views/user-center/history"),
  //   消息相关
  NewsList: () => import("@/views/user-center/news/list"),
  NewsDetailList: () => import("@/views/user-center/news/detail-list"),
  //   客服相关
  CustomerServiceList: () => import("@/views/user-center/customer-service/list"),
  CustomerServiceChat: () => import("@/views/user-center/customer-service/chat"),
  //   资产相关
  AssetsList: () => import("@/views/user-center/assets/assets/list"),
  AssetsDetail: () => import("@/views/user-center/assets/assets/detail"),
  AssetsTransferDetail: () => import("@/views/user-center/assets/assets/transfer-detail"),
  AssetsWithdraw: () => import("@/views/user-center/assets/assets/withdraw"),
  AssetsTransferGift: () => import("@/views/user-center/assets/assets/transfer-gift"),
  AssetsTransfer: () => import("@/views/user-center/assets/assets/transfer"),
  IntegralDetail: () => import("@/views/user-center/assets/integral/detail"),
  IntegralTransfer: () => import("@/views/user-center/assets/integral/transfer"),
  IntegralCollection: () => import("@/views/user-center/assets/integral/collection"),
  AssetsRecordDetail: () => import("@/views/user-center/assets/record-detail"),
  //   优惠券
  CouponList: () => import("@/views/user-center/coupon/index"),

  // 新人注册页
  Download: () => import("@/views/download/download")
}

const routes = [
  // TAB
  {
    path: '/',
    name: 'home',
    component: ViewsCom.Home,
    meta: {
      tabIndex: 0
    }
  },
  {
    path: '/classification',
    name: 'classification',
    component: ViewsCom.Classification,
    meta: {
      tabIndex: 1
    }
  },
  // {
  //   path: '/shopping-cart',
  //   name: 'shopping-cart',
  //   component: ViewsCom.ShoppingCart,
  //   meta: {
  //     tabIndex: 2
  //   }
  // },
  {
    path: '/user-center',
    name: 'user-center',
    component: ViewsCom.UserCenter,
    meta: {
      tabIndex: 2
    }
  },

  // 登录
  {
    path: '/login',
    name: 'login',
    component: ViewsCom.Login,
    // meta: {
    //   showNavBar: true,
    //   title: "登录"
    // }
  },
  //用户注册协议
  {
    path: '/agreement/registration',
    name: 'registration',
    component: ViewsCom.Registration,
    meta: {
      showNavBar: true,
      title: "用户注册协议"
    }
  },
  // 隐私协议
  {
    path: '/agreement/privacy',
    name: 'privacy',
    component: ViewsCom.Privacy,
    meta: {
      showNavBar: true,
      title: "用户隐私协议"
    }
  },


  // 搜索
  {
    path: '/search',
    name: 'search',
    component: ViewsCom.Search,
    meta: {
      showNavBar: true,
      title: "搜索"
    }
  },
  {
    path: '/search-result',
    name: 'search-result',
    component: ViewsCom.SearchResult,
    meta: {
      showNavBar: true,
      title: "搜索结果"
    }
  },


  // 商铺、商品、评论、下单
  {
    path: '/shop/:merchantId',
    name: 'shop',
    component: ViewsCom.Shop
  },
  {
    path: '/shop-info/:merchantId',
    name: 'shop-info',
    component: ViewsCom.ShopInfo,
    meta: {
      showNavBar: true,
      title: "主页详情"
    }
  },
  {
    path: '/shop-coupon-center/:merchantId',
    name: 'shop-coupon-center',
    component: ViewsCom.ShopCouponCenter,
    meta: {
      showNavBar: true,
      title: "领券中心"
    }
  },
  {
    path: '/goods/:goodsId',
    name: 'goods',
    component: ViewsCom.Goods
  },
  {
    path: '/comment-list',
    name: 'comment-list',
    component: ViewsCom.CommentList,
    meta: {
      showNavBar: true,
      title: "商品评论"
    }
  },
  {
    path: '/comment-detail',
    name: 'comment-detail',
    component: ViewsCom.CommentDetail,
    meta: {
      showNavBar: true,
      title: "评论详情"
    }
  },
  {
    path: '/order-confirm',
    name: 'order-confirm',
    component: ViewsCom.OrderConfirm,
    meta: {
      showNavBar: true,
      title: "确认订单"
    }
  },
  {
    path: '/payment',
    name: 'payment',
    component: ViewsCom.Payment,
    meta: {
      showNavBar: true,
      title: ""
    }
  },
  {
    path: '/pay-result/:pid',
    name: 'pay-result',
    component: ViewsCom.PayResult,
    meta: {
      showNavBar: true,
      title: ""
    }
  },
  //盲盒
  {
    path: '/blind-box/:goodsId',
    name: 'blind-box',
    component: ViewsCom.BlindBox,
  },

  // 转让市场
  {
    path: '/transfer/market',
    name: 'transfer-market',
    component: ViewsCom.TransferMarket,
    meta: {
      showNavBar: true,
      title: "转让交易市场"
    }
  },
  {
    path: '/transfer/top-list',
    name: 'transfer-top-list',
    component: ViewsCom.TransferTopList,
  },
  {
    path: '/transfer/good-list',
    name: 'transfer-good-list',
    component: ViewsCom.TransferGoodList
  },
  {
    path: '/transfer/classification-list',
    name: 'transfer-classification-list',
    component: ViewsCom.TransferClassificationList,
    meta: {
      showNavBar: true,
      title: ""
    }
  },


  // 个人中心
  //   地址相关
  {
    path: '/user-center/address/list',
    name: 'address-list',
    component: ViewsCom.AddressList,
    meta: {
      showNavBar: true,
      title: "地址管理"
    }
  },
  {
    path: '/user-center/address/add-express-addr',
    name: 'add-express-addr',
    component: ViewsCom.AddExpressAddr,
    meta: {
      showNavBar: true,
      title: "添加快递地址"
    }
  },
  {
    path: '/user-center/address/add-coin-addr',
    name: 'add-coin-addr',
    component: ViewsCom.AddCoinAddr,
    meta: {
      showNavBar: true,
      title: "添加提币地址"
    }
  },
  //   订单相关
  {
    path: '/user-center/order/order-list',
    name: 'order-list',
    component: ViewsCom.OrderList,
  },
  {
    path: '/user-center/order/order-search',
    name: 'order-search',
    component: ViewsCom.OrderSearch,
  },
  {
    path: '/user-center/order/order-detail/:oid',
    name: 'order-detail',
    component: ViewsCom.OrderDetail,
  },
  {
    path: '/user-center/order/delivery-detail/:deliveryId',
    name: 'delivery-detail',
    component: ViewsCom.DeliveryDetail,
  },
  {
    path: '/user-center/order/delivery-express-detail',
    name: 'delivery-express-detail',
    component: ViewsCom.DeliveryExpressDetail,
    meta: {
      showNavBar: true,
      title: "物流详情"
    }
  },
  //   评论相关
  {
    path: '/user-center/comment/release',
    name: 'release-comment',
    component: ViewsCom.ReleaseComment,
    meta: {
      showNavBar: true,
      title: "发表评论"
    }
  },
  {
    path: '/user-center/order/comment/result/:commentId',
    name: 'release-comment-result',
    component: ViewsCom.ReleaseCommentResult,
  },
  {
    path: '/user-center/order/comment/un-comment-list',
    name: 'un-comment-list',
    component: ViewsCom.UnCommentList,
    meta: {
      showNavBar: true,
      title: "发表评论"
    },
  },
  //   售后相关
  {
    path: '/user-center/after-sale/apply-refund',
    name: 'apply-refund',
    component: ViewsCom.ApplyRefund,
    meta: {
      showNavBar: true,
      title: "选择售后类型"
    },
  },
  {
    path: '/user-center/after-sale/submit-refund',
    name: 'submit-refund',
    component: ViewsCom.SubmitRefund,
    meta: {
      showNavBar: true,
      title: "申请退款"
    },
  },
  {
    path: '/user-center/after-sale/apply-refund-express',
    name: 'apply-refund-express',
    component: ViewsCom.ApplyRefundExpress,
    meta: {
      showNavBar: true,
      title: "填写物流"
    },
  },
  {
    path: '/user-center/after-sale/refund-list',
    name: 'refund-list',
    component: ViewsCom.RefundList,
    meta: {
      showNavBar: true,
      title: "售后"
    },
  },
  {
    path: '/user-center/after-sale/refund-money-detail',
    name: 'refund-money-detail',
    component: ViewsCom.RefundMoneyDetail,
    meta: {
      showNavBar: true,
      title: "退款详情"
    },
  },
  {
    path: '/user-center/after-sale/refund-goods-detail',
    name: 'refund-goods-detail',
    component: ViewsCom.RefundGoodsDetail,
    meta: {
      showNavBar: true,
      title: "退货详情"
    },
  },
  {
    path: '/user-center/after-sale/refund-express-detail',
    name: 'refund-express-detail',
    component: ViewsCom.RefundExpressDetail,
    meta: {
      showNavBar: true,
      title: "物流详情"
    },
  },
  //   分享邀请
  {
    path: '/user-center/share-invite',
    name: 'share-invite',
    component: ViewsCom.ShareInvite,
  },
  //   个人信息
  {
    path: '/user-center/personal-info',
    name: 'personal-info',
    component: ViewsCom.PersonalInfo,
    meta: {
      showNavBar: true,
      title: "个人中心"
    },
  },
  //   设置
  {
    path: '/user-center/settings',
    name: 'settings',
    component: ViewsCom.Settings,
    meta: {
      showNavBar: true,
      title: "设置"
    },
  },
  {
    path: '/user-center/update-pay-pwd',
    name: 'update-pay-pwd',
    component: ViewsCom.UpdatePayPwd,
    meta: {
      showNavBar: true,
      title: "修改支付密码"
    },
  },
  {
    path: '/user-center/authentication',
    name: 'authentication',
    component: ViewsCom.Authentication,
    meta: {
      showNavBar: true,
      title: "实名认证"
    },
  },
  {
    path: '/user-center/about-us',
    name: 'about-us',
    component: ViewsCom.AboutUs,
    meta: {
      showNavBar: true,
      title: "关于我们"
    },
  },
  //   设置
  {
    path: '/user-center/apply-complaint',
    name: 'apply-complaint',
    component: ViewsCom.ApplyComplaint,
    meta: {
      showNavBar: true,
      title: "发起投诉"
    },
  },
  {
    path: '/user-center/complaint-list',
    name: 'complaint-list',
    component: ViewsCom.ComplaintList,
    meta: {
      showNavBar: true,
      title: "我的投诉"
    },
  },
  {
    path: '/user-center/complaint-detail/:id',
    name: 'complaint-detail',
    component: ViewsCom.ComplaintDetail,
    meta: {
      showNavBar: true,
      title: "投诉详情"
    },
  },
  //   收藏
  {
    path: '/user-center/goods-collection',
    name: 'goods-collection',
    component: ViewsCom.GoodsCollection,
    meta: {
      showNavBar: true,
      title: "收藏版权"
    },
  },
  //   关注
  {
    path: '/user-center/shop-follow',
    name: 'shop-follow',
    component: ViewsCom.ShopFollow,
    meta: {
      showNavBar: true,
      title: "关注版权方"
    },
  },
  //   足迹
  {
    path: '/user-center/browse-history',
    name: 'browse-history',
    component: ViewsCom.BrowseHistory,
    meta: {
      showNavBar: true,
      title: "我的足迹"
    },
  },
  //   消息相关
  {
    path: '/user-center/news/list',
    name: 'news-list',
    component: ViewsCom.NewsList,
    meta: {
      showNavBar: true,
      title: "消息"
    },
  },
  {
    path: '/user-center/news/detail-list',
    name: 'news-detail-list',
    component: ViewsCom.NewsDetailList,
    meta: {
      showNavBar: true,
      title: "通知"
    },
  },
  //   客服相关
  {
    path: '/user-center/customer-service/list',
    name: 'customer-service-list',
    component: ViewsCom.CustomerServiceList,
    meta: {
      showNavBar: true,
      title: "客服中心"
    },
  },
  {
    path: '/user-center/customer-service/chat',
    name: 'customer-service-chat',
    component: ViewsCom.CustomerServiceChat,
    meta: {
      showNavBar: true,
      title: "聊天详情"
    },
  },
  //   资产相关
  {
    path: '/user-center/assets/assets-list',
    name: 'assets-list',
    component: ViewsCom.AssetsList,
  },
  {
    path: '/user-center/assets/assets-detail',
    name: 'assets-detail',
    component: ViewsCom.AssetsDetail,
  },
  {
    path: '/user-center/assets/assets-transfer-detail',
    name: 'assets-transfer-detail',
    component: ViewsCom.AssetsTransferDetail,
  },
  {
    path: '/user-center/assets/assets-withdraw',
    name: 'assets-withdraw',
    component: ViewsCom.AssetsWithdraw,
    meta: {
      showNavBar: true,
      title: "提货"
    },
  },
  {
    path: '/user-center/assets/assets-transfer-gift',
    name: 'assets-transfer-gift',
    component: ViewsCom.AssetsTransferGift,
    meta: {
      showNavBar: true,
      title: "转赠"
    },
  },
  {
    path: '/user-center/assets/assets-transfer',
    name: 'assets-transfer',
    component: ViewsCom.AssetsTransfer,
    meta: {
      showNavBar: true,
      title: "转让"
    },
  },
  {
    path: '/user-center/assets/integral-detail',
    name: 'integral-detail',
    component: ViewsCom.IntegralDetail,
  },
  {
    path: '/user-center/assets/integral-transfer',
    name: 'integral-transfer',
    component: ViewsCom.IntegralTransfer,
  },
  {
    path: '/user-center/assets/integral-collection',
    name: 'integral-collection',
    component: ViewsCom.IntegralCollection,
  },
  {
    path: '/user-center/assets/record-detail',
    name: 'assets-record-detail',
    component: ViewsCom.AssetsRecordDetail,
    meta: {
      showNavBar: true,
      title: "交易记录详情"
    },
  },
  //   优惠券
  {
    path: '/user-center/coupon/list',
    name: 'coupon-list',
    component: ViewsCom.CouponList,
    meta: {
      showNavBar: true,
      title: "我的优惠券"
    },
  },
  //   新人注册页
  {
    path: '/download',
    name: 'download',
    component: ViewsCom.Download,
    meta: {
      // showNavBar: true,
      title: "一幕商城-分享下载"
    },
  },

]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  // 设置searchFlag
  // if ((from.name == 'search' || from.name == "classification" || from.name == "home") && to.name == 'search-result') {
  //   store.commit("setSearchFlag", ++store.state.searchFlag)
  // }

  next()
})

router.afterEach((to, from) => {
  // 设置currentTab
  store.commit("setCurrentTab", to.meta.tabIndex || 0)

  // 设置标题
  store.commit("setTitle", to.meta.title || '')

  // 设置navbar展示
  store.commit("setShowNavBar", !!to.meta.showNavBar)

  // 设置tabbar展示
  store.commit("setShowTabBar", to.name == 'home' || to.name == 'classification' || to.name == 'user-center' || to.name == 'shopping-cart')
})

export default router
