<template>
  <div class="box" v-if="list.length">
    <img class="hot" src="/img/home/hot.png" alt="极度证券">
    <div class="title flex">
      <div>
        <!-- 期权 -->
        {{ $t('home.l5') }}
      </div>
      <div class="right" @click="$router.replace('/market/option')">
        <!-- 更多 -->
        {{ $t('home.l6') }}
        <van-icon name="arrow" />
      </div>
    </div>
    <div class="table">
      <div class="thead flex">
        <div class="th1">
          <!-- 标的 -->
          {{ $t('home.l7') }}
        </div>
        <div class="th2">
          <!-- 费率(1M) -->
          {{ $t('home.l8') }}(1M)
        </div>
        <div class="th3">
          <!-- 名义本金 -->
          {{ $t('home.l9') }}
        </div>
        <div class="th2">
          <!-- 期权费 -->
          {{ $t('home.l10') }}
        </div>
      </div>
      <van-swipe :autoplay="3000" :show-indicators="false">
        <van-swipe-item v-for="(item) in 20" :key="item">
          <div class="tr flex" v-for="(item, index) in list.slice(((item - 1) * 5), item * 5)" :key="index" @click="$router.push('/product-detail/' + item.code + '/6')">
            <div class="th1">
              <div class="name" v-if="language == 'zh-CN'">{{item.title }}</div>
              <div class="name" v-else-if="language == 'zh-TW'">{{ item.name_cht || item.title }}</div>
              <div class="name" v-else>{{ item.title_en || item.title }}</div>
              <div class="label flex">
                <div class="tag-box">
                  <div class="tag" :class="getTagName(item.code)">{{ getTagName(item.code) }}</div>
                </div>
                <div>{{ item.code }}</div>
              </div>
            </div>
            <div class="th2 red">{{ item.price_1m }}%</div>
            <!-- 万 -->
            <div class="th3">100{{ $t('home.l11') }}</div>
            <div class="th2">{{ item.price_1m }}{{ $t('home.l11') }}</div>
          </div>
        </van-swipe-item>
      </van-swipe>
    </div>
    <div class="buy" @click="$router.replace('/market/option')">
      <!-- 更多报价 -->
      {{ $t('home.l12') }} <i class="el-icon-d-arrow-right"></i>
    </div>
  </div>
</template>
<script>
import { getOptionProductList } from "@/api/option";
export default {
  data () {
    return {
      list: [],
      pageNum: 1,
      pageSize: 100,
      show: true,
    }
  },
  inject: ['getproductDataObj'],
  computed: {
    productDataObj() {
      return this.getproductDataObj()
    },
  },
  deactivated() {
    this.show = false
  },
  activated() {
    this.show = true
  },
  created () {
    this.getOptionProductList()
  },
  methods: {
    getOptionProductList() {
      getOptionProductList({
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        market: 'CN',
        // recommend: 1,
        standard: 100
      }).then(res => {
        this.list = res.list || [];
      }).catch(() => {})
    },
    getTagName(code) {
      if (code) {
        var list = code.split('.')
        return list[1]
      }
    },
  }
}
</script>
<style lang="less" scoped>
.box {
  border-radius: 4px;
  border: 1px solid #F1F1F1;
  position: relative;
  padding: 16px 12px 13px;
  margin-bottom: 12px;
  .hot {
    position: absolute;
    right: -6px;
    top: -5px;
    width: 46px;
  }
}
.title {
  font-size: 18px;
  justify-content: space-between;
  font-weight: 600;
  color: var(--color-1-);
  margin-bottom: 9px;
  .right {
    font-size: 14px;
    color: #737474;
    font-weight: 400;
  }
}
.table {
  .thead {
    padding: 9px 0;
    font-size: 12px;
    color: #959697;
  }
  .th1 {
    flex: 1;
    min-width: 10%;
    max-width: 100%;
  }
  .th2 {
    width: 64px;
    text-align: right;
  }
  .th3 {
    width: 79px;
    text-align: right;
  }
  .tr {
    padding: 10px 0;
    border-top: 1px solid #F2F2F2;
    color: #4A4A4A;
  }
  .name {
    color: var(--color-1-);
    font-size: 15px;
    line-height: 21px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .label {
    color: #959697;
    font-size: 12px;
    margin-top: 2px;
  }
  .tag-box {
    margin-right: 6px;
    .tag {
      line-height: 16px;
      padding: 0 3px;
      border-radius: 2px;
    }
    .US {
      background-color: #FFF1F1;
      color: #EA4A45;
    }
    .HK {
      background-color: #EDF6FF;
      color: #1989FF;
    }
    .SZ,.SH {
      background-color: #FFEEE7;
      color: #FF6F30;
    }
  }
  .red {
    color: #EA4A45;
  }
}
.buy {
  margin-top: 10px;
  text-align: center;
  color: var(--color-);
}
</style>