<template>
  <div v-loading.body.fullscreen="fullscreenLoading" element-loading-background="rgba(255, 255, 255, 0)">
    <noticeView v-if="activeMarket && activeMarket.id && activeNoticeShow" :market="market" :activeMarket="activeMarket" @close="close" />
    <div class="btns flex">
      <div class="btn" :class="{active: market === '1'}" @click="tabChange('1')">
        <!-- 热门 -->
        {{ $t('market.l6') }}
      </div>
      <div class="btn" :class="{active: market === 'US'}" @click="tabChange('US')">
        <!-- 美股 -->
        {{ $t('common.l41') }}
      </div>
      <div class="btn" :class="{active: market === 'CN'}" @click="tabChange('CN')">
        <!-- 沪深 -->
        {{ $t('market.l9') }}
      </div>
      <div class="btn" :class="{active: market === 'HK'}" @click="tabChange('HK')">
        <!-- 港股 -->
        {{ $t('common.l42') }}
      </div>
    </div>
    <marketList :swipeList="swipeList" :market="market"/>
  </div>
</template>
<script>
import marketList from "./components/list.vue";
import bus from "@/utils/bus";
import noticeView from "@/components/closedMarket/notice.vue";
import { mapGetters } from "vuex";
export default {
  components: {
    marketList,
    noticeView
  },
  data () {
    return {
      market: '1',
      noticeShowCN: true,
      noticeShowUS: true,
      noticeShowHK: true,
      noticeShowCFD: true,
      swipeList: ['000001.SH', '399001.SZ', '399006.SZ', 'XAUUSD', 'BTCUSD', 'XBRUSD', '.DJI.US', '.IXIC.US', 'SPY.US', 'HSI.HK', 'HSCEI.HK', 'HSTECH.HK']
    }
  },
  computed: {
    ...mapGetters(['marketCN', 'marketHK', 'marketUS', 'marketCFD']),
    activeMarket() {
      return this['market' + this.market]
    },
    activeNoticeShow() {
      return this['noticeShow' + this.market]
    },
  },
  activated () {
    // bus.$emit("updateSubscribe", this.swipeList, false, true);
    if (this.$route.params.market) {
      this.market = this.$route.params.market
    }
  },
  created () {
    if (this.$route.params.market) {
      this.market = this.$route.params.market
    }
  },
  methods: {
    close() {
      this['noticeShow' + this.market] = false
    },
    tabChange(val) {
      if (this.market == val) {
        return
      }
      this.market = val
      this.$router.replace('/market/stock/' + val)
    },
  }
}
</script>
<style lang="less" scoped>
.btns {
  padding: 13px 18px 0;
  white-space: nowrap;
  flex-wrap: nowrap;
  overflow-x: auto;
  &::-webkit-scrollbar {
    display: none;
  }
  .btn {
    cursor: pointer;
    margin-right: 6px;
    border-radius: 4px;
    border: 1px solid #EBEBEB;
    font-size: 14px;
    color: #6F6F6F;
    padding: 8px 10px;
    &.active {
      border-color: #000;
      color: #000000;
    }
  }
}
</style>