<template>
  <div v-loading.body.fullscreen="fullscreenLoading" element-loading-background="rgba(255, 255, 255, 0)">
    <div class="btns flex">
      <div class="btn" :class="{active: market === 'hot'}" @click="tabChange('hot')">
        <!-- 热门 -->
        {{ $t('market.l6') }}
      </div>
      <div class="btn" v-for="item in groupList" :key="item.id" :class="{active: market == item.id}" @click="tabChange(item.id)">
        {{ titleName[item.title] || item.title }}
      </div>
    </div>
    <marketList :swipeList="swipeList" :market="market"/>
  </div>
</template>
<script>
import { getProductGroupList } from "@/api/product";
import marketList from "./components/list.vue";
export default {
  components: {
    marketList,
  },
  data () {
    return {
      market: '',
      groupList: [],
      swipeList: ['000001.SH', '399001.SZ', '399006.SZ', 'XAUUSD', 'BTCUSD', 'XBRUSD', '.DJI.US', '.IXIC.US', 'SPY.US', 'HSI.HK', 'HSCEI.HK', 'HSTECH.HK']
    }
  },
  computed: {
    titleName() {
      return {
        "指数": this.$t('download.l27'),
        "能源": this.$t('market.l19'),
        "其他": this.$t('inform.l22'),
        "加密货币": this.$t('market.l24'),
        "外汇": this.$t('market.l21'),
        "贵金属": this.$t('market.l22')
      }
    }
  },
  activated() {
    if (this.$route.params.market) {
      this.market = this.$route.params.market
    }
    // bus.$emit("updateSubscribe", this.swipeList, false, true);
  },
  created () {
    if (this.$route.params.market) {
      this.market = this.$route.params.market
    }
    this.getProductGroupList()
  },
  methods: {
    close() {
      this['noticeShow' + this.market] = false
    },
    tabChange(val) {
      if (this.market == val) {
        return
      }
      this.market = val
      this.$router.replace('/market/cfd/' + val)
    },
    getProductGroupList() {
      getProductGroupList({
        visible: 1
      }).then(res => {
        this.groupList = res.list || []
      }).catch(()=> {})
    }
  }
}
</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>