<template>
  <div>
    <div class="filter-box flex">
      <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>
      <div class="mounth-box">
        <van-popover
          v-model="showPopover"
          placement="bottom-end"
          trigger="click"
        >
          <div class="popover-body">
            <div class="m-li" :class="{'active': mounth == '1m'}" @click="changeMounth('1m')">1M</div>
            <div class="m-li" :class="{'active': mounth == '2m'}" @click="changeMounth('2m')">2M</div>
            <div class="m-li" :class="{'active': mounth == '3m'}" @click="changeMounth('3m')">3M</div>
            <div class="m-li" :class="{'active': mounth == '6m'}" @click="changeMounth('6m')">6M</div>
          </div>
          <template #reference>
            <div class="filter flex">
              <img class="img" src="/img/icon/date.png" alt="">
              <div>
                <!-- 期限 -->
                {{ $t('exchange.l47') }} {{ mounth.toLocaleUpperCase() }}
              </div>
              <img class="arrow-down" :class="{'active': showPopover}" src="/img/market/down.png" alt="">
            </div>
          </template>
        </van-popover>
      </div>
    </div>
    <hotList v-if="market == '1'" :market="market" :mounth="mounth" />
    <list v-else :market="market" :mounth="mounth" />
  </div>
</template>
<script>
import list from "./components/list.vue";
import hotList from "./components/hotList.vue";
export default {
  components: {
    list,
    hotList
  },
  data() {
    return {
      market: '1',
      mounth: '1m',
      showPopover: false
    };
  },
  created () {
    if (this.$route.params.market) {
      this.market = this.$route.params.market
    }
  },
  methods: {
    tabChange(val) {
      if (this.market == val) {
        return
      }
      this.market = val
      this.$router.replace('/market/options/' + val)
    },
    changeMounth(m) {
      this.showPopover = false
      if (this.mounth == m) {
        return
      }
      this.mounth = m
    },
  },
};
</script>
<style lang="less" scoped>
.filter-box {
  position: relative;
  .filter {
    background-color: #fff;
    cursor: pointer;
    font-size: 12px;
    color: #6F6F6F;
    border-radius: 4px;
    border: 1px solid #EBEBEB;
    height: 32px;
    padding: 0 6px;
  }
  .img {
    width: 11px;
    margin-right: 4px;
  }
}
.mounth-box {
  padding-right: 16px;
  padding-top: 13px;
  .arrow-down {
    width: 10px;
    margin-left: 8px;
    transition: transform 0.4s;
    &.active {
      transform: rotate(-180deg);
    }
  }
}
.btns {
  padding: 13px 18px 0;
  flex: 1;
  min-width: 20%;
  white-space: nowrap;
  flex-wrap: nowrap;
  overflow-x: auto;
  position: relative;
  &::-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;
    }
  }
}
.popover-body {
  .m-li {
    cursor: pointer;
    color: #717171;
    width: 90px;
    text-align: center;
    line-height: 42px;
    &+.m-li {
      border-top: 1px solid #E9E9E9;
    }
    &.active {
      color: #000000;
    }
  }
}
</style>
