<template>
  <div>
    <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 class="line"></div>
      </div>
      <div class="btn" :class="{active: market === 'US'}" @click="tabChange('US')">
        <!-- 美股 -->
        {{ $t('common.l41') }}
        <div class="line"></div>
      </div>
      <div class="btn" :class="{active: market === 'CN'}" @click="tabChange('CN')">
        <!-- A股 -->
        {{ $t('common.l61') }}
        <div class="line"></div>
      </div>
      <div class="btn" :class="{active: market === 'HK'}" @click="tabChange('HK')">
        <!-- 港股 -->
        {{ $t('common.l42') }}
        <div class="line"></div>
      </div>
    </div>
    <marketList :key="market":swipeList="swipeList" :market="market"/>
  </div>
</template>
<script>
import marketList from "./components/list.vue";
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 () {
    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 {
  position: sticky;
  top: 50px;
  z-index: 4;
  height: 52px;
  padding: 0 16px;
  align-items: flex-end;
  white-space: nowrap;
  flex-wrap: nowrap;
  overflow-x: auto;
  background-color: #fff;
  &::-webkit-scrollbar {
    display: none;
  }
  .btn {
    cursor: pointer;
    font-size: 14px;
    color: #888888;
    padding-bottom: 18px;
    position: relative;
    &+.btn {
      margin-left: 24px;
    }
    &.active {
      font-size: 16px;
      font-weight: 600;
      color: #000;
      .line {
        display: block;
      }
    }
  }
  .line {
    position: absolute;
    left: 50%;
    bottom: 10px;
    transform: translateX(-50%);
    width: 12px;
    height: 2px;
    border-radius: 1px;
    background-color: #000;
    display: none;
  }
}
</style>