<template>
  <view class="tab-page">
    <SupplierMarketPanel v-if="isLoggedIn" ref="marketPanel" />
    <GuestView
      v-else-if="!isLoggedIn"
      hint="登录后查看牦牛市场行情"
      @login="goLogin"
    />
  </view>
</template>

<script>
import SupplierMarketPanel from '@/components/supplier/market-panel.vue'
import GuestView from '@/components/partner/guest-view.vue'
import { useUserStore } from '@/store/user'
import { refreshTabPanelOnShow } from '@/utils/tabPanel'

export default {
  components: {
    SupplierMarketPanel,
    GuestView
  },
  data() {
    return {
      isLoggedIn: false
    }
  },
  onShow() {
    refreshTabPanelOnShow(this, {
      refreshRole: this.refreshRole,
      refName: 'marketPanel',
      shouldReload: () => this.isLoggedIn
    })
  },
  methods: {
    refreshRole() {
      this.isLoggedIn = useUserStore().isLoggedIn()
    },
    goLogin() {
      uni.navigateTo({ url: '/pages/login/index' })
    }
  }
}
</script>

<style lang="scss" scoped>
@import '@/styles/tab-page.scss';
</style>
