import { Merchant, Investor, Agent } from './updateMenu'
export function setTabBar(res: { id?: number; name?: string; type?: string }) {
  const App: any = getApp()
  App.globalData.selectedOrg = res
  if (res?.type === 'boss') {
    //商户-首页
    uni.switchTab({ url: '/pages/MERCHANT/index/index' })
  }
  if (res?.type === 'investor') {
    //投资方-首页
    uni.switchTab({ url: '/pages/INVESTOR/index/index' })
  }
  if (res?.type === 'agent') {
    //代理商-首页
    uni.switchTab({ url: '/pages/AGENT/index/index' })
  }
  console.log('App.globalData.selectedOrg', App.globalData.selectedOrg)
}

export function setTabBarData(idx: number, type?: string) {
  const pages = getCurrentPages()
  const currentPage: any = pages[pages.length - 1]
  // 检查是否有TabBar并设置选中的菜单
  if (currentPage) {
    const tabBar = currentPage.getTabBar ? currentPage.getTabBar() : null
    if (tabBar) {
      if (idx === 3) {
        if (type === 'boss') {
          //商户菜单
          tabBar.setData({
            selected: 3,
            list: Merchant
          })
        }
        if (type === 'investor') {
          //投资方菜单
          tabBar.setData({
            selected: 3,
            list: Investor
          })
        }
        if (type === 'agent') {
          //代理商
          tabBar.setData({
            selected: 3,
            list: Agent
          })
        }
        return
      }
      tabBar.setData({
        selected: idx
      })
    } else {
      console.error('当前页面没有TabBar')
    }
  }
}
