<template>
  <div class="components">
    <div class="section">
      <div class="name-box">
        <div class="price-box">
          <div class="price" :class="{'down': symbolInfo.spread < 0}">
            <div>{{ $handleDigits(symbolInfo.ask, symbolInfo.digits) }}</div>
            <img v-show="symbolInfo.spread >= 0" class="icon2" src="/img/product/up.png" alt="">
            <img v-show="symbolInfo.spread < 0" class="icon2" src="/img/product/down1.png" alt="">
          </div>
          <div class="des" v-if="language == 'zh-CN' ||  language == 'zh-TW'">{{ companyInfo.industry }}</div>
          <div class="des" v-else>{{ companyInfo.industry_en || companyInfo.industry }}</div>
        </div>
        <div class="state-box flex">
          <div class="flex">
            <div class="state" v-if="activeMarket && activeMarket.id">{{ $t('product.l93') }}</div>
            <div class="state" v-else-if="tradeState">{{ tradeStateText[tradeState] }}</div>
            <div class="differ" :class="{'down': symbolInfo.spread < 0}">{{ symbolInfo.spread > 0 ? '+' : ''  }}{{ $handleDigits(symbolInfo.spread, symbolInfo.digits) }}({{ symbolInfo.percentage > 0 ? '+' : ''  }}{{ symbolInfo.percentage }}%)</div>
          </div>
          <div class="img-box flex" @click="tagIconShow = true">
            <img class="icon1" :src="`/img/product/${symbolInfo.market}.png?1`" alt="">
            <img class="icon1" v-if="symbolInfo.market == 'CFD'" src="/img/product/tag4.png" alt="">
            <img class="icon1" src="/img/product/tag2.png" alt="">
            <img class="icon1" src="/img/product/tag3.png" alt="">
            <img class="icon1" src="/img/product/tag1.png" alt="">
          </div>
        </div>
      </div>
      <van-row gutter="8">
        <van-col span="8">
          <div class="col flex">
            <!-- 开盘 -->
            <div class="label" v-html="getLabelHtml($t('product.l60'))" :class="{'cn': language == 'zh-CN' ||  language == 'zh-TW'}">
            </div>
            <div>{{ $handleDigits(symbolInfo.open, symbolInfo.digits) }}</div>
          </div>
        </van-col>
        <van-col span="8">
          <div class="col flex">
            <!-- 昨收 -->
            <div class="label" v-html="getLabelHtml($t('product.l61'))" :class="{'cn': language == 'zh-CN' ||  language == 'zh-TW'}">
            </div>
            <div class="val">{{ $handleDigits(symbolInfo.close, symbolInfo.digits) }}</div>
          </div>
        </van-col>
        <van-col span="8">
          <div class="col flex">
            <!-- 最高 -->
            <div class="label" v-html="getLabelHtml($t('product.l62'))" :class="{'cn': language == 'zh-CN' ||  language == 'zh-TW'}">
            </div>
            <div class="val up">{{ $handleDigits(symbolInfo.high, symbolInfo.digits) }}</div>
          </div>
        </van-col>
      </van-row>
      <van-row gutter="8" :class="{'cn': language == 'zh-CN' ||  language == 'zh-TW'}">
        <van-col span="8">
          <div class="col flex">
            <!-- 最低 -->
            <div class="label" v-html="getLabelHtml($t('product.l63'))" :class="{'cn': language == 'zh-CN' ||  language == 'zh-TW'}">
            </div>
            <div class="val down">{{ $handleDigits(symbolInfo.low, symbolInfo.digits) }}</div>
          </div>
        </van-col>
        <van-col span="8">
          <div class="col flex" v-if="symbolInfo.type == 1">
            <!-- 总股本 -->
            <div class="label" v-html="getLabelHtml($t('product.l64'))" :class="{'cn': language == 'zh-CN' ||  language == 'zh-TW'}">
            </div>
            <div class="val">{{ marketFormat(companyInfo.totalShares) }}</div>
          </div>
        </van-col>
        <van-col span="8">
          <div class="col flex" v-if="symbolInfo.type == 1">
            <!-- 总市值 -->
            <div class="label" v-html="getLabelHtml($t('product.l66'))" :class="{'cn': language == 'zh-CN' ||  language == 'zh-TW'}">
            </div>
            <div class="val">{{ marketFormat(marketValue) }}</div>
          </div>
        </van-col>
      </van-row>
      <van-row gutter="8" :class="{'cn': language == 'zh-CN' ||  language == 'zh-TW'}" v-if="symbolInfo.type == 1">
        <van-col span="8">
          <div class="col flex">
            <div class="label" :class="{'cn': language == 'zh-CN' ||  language == 'zh-TW'}">
              <!-- 流通股本 -->
              {{ $t('product.l65') }}
            </div>
            <div class="val">{{ marketFormat(companyInfo.floatShares) }}</div>
          </div>
        </van-col>
        <van-col span="8">
          <div class="col flex">
            <div class="label" :class="{'cn': language == 'zh-CN' ||  language == 'zh-TW'}">
              <!-- 流通市值 -->
              {{ $t('product.l67') }}
            </div>
            <div class="val">{{ marketFormat(marketValue1) }}</div>
          </div>
        </van-col>
        <van-col span="8">
          <div class="col flex">
            <!-- 市盈率 -->
            <div class="label" v-html="getLabelHtml($t('product.l98'))" :class="{'cn': language == 'zh-CN' ||  language == 'zh-TW'}">
            </div>
            <div class="val">--</div>
          </div>
        </van-col>
      </van-row>
    </div>
    <!-- <div class="section1">
      <div class="title flex">
        <div class="flex">
          <div>盘后</div>
          <div class="differ">240.89 +3.99 +1.68%</div>
        </div>
        <i class="el-icon-arrow-down"></i>
      </div>
    </div> -->
    <div class="section2">
      <quotationk :symbol="symbol" :symbolInfo="symbolInfo" :timeDiff="timeDiff" height="350px"/>
    </div>
    <depth :symbol="symbol" :symbolInfo="symbolInfo" />
    <van-popup get-container="body" v-model="tagIconShow" round position="bottom">
      <tagBox :symbolInfo="symbolInfo" />
    </van-popup>
  </div>
</template>
<script>
import quotationk from "./components/quotationk.vue";
import depth from "./components/depth.vue";
import tagBox from "./components/tagBox.vue";
export default {
  props: ['symbol', 'symbolInfo', 'tradeState', 'companyInfo', 'timeDiff', 'activeMarket'],
  components: {
    quotationk,
    depth,
    tagBox
  },
  data () {
    return {
      tagIconShow: false
    }
  },
  computed: {
    marketValue() {
      if (this.companyInfo.totalShares && this.symbolInfo.ask) {
        return this.$bigDecimal.multiply(this.symbolInfo.ask, this.companyInfo.totalShares)
      }
      return ''
    },
    marketValue1() {
      if (this.companyInfo.floatShares && this.symbolInfo.ask) {
        return this.$bigDecimal.multiply(this.symbolInfo.ask, this.companyInfo.floatShares)
      }
      return ''
    },
    tradeStateText() {
      return {
        '已休盘': this.$t('product.l93'),
        '盘中': this.$t('product.l94'),
      }
    },
  },
  methods: {
    marketFormat(value) {
      if (value) {
        if (value > 1000000000000) {
          return Number((value / 1000000000000).toFixed(2)) + 'T'
        }
        if (value > 1000000000) {
          return Number((value / 1000000000).toFixed(2)) + 'B'
        }
        if (value > 1000000) {
          return Number((value / 1000000).toFixed(2)) + 'M'
        }
        return Number((value).toFixed(2))
      }
      return '--'
    },
    getLabelHtml(val) {
      if (this.language == 'zh-CN' || this.language == 'zh-TW') {
        var list = val.split('')
        var str = ''
        list.forEach(item => {
          str+= `<div>${item}</div>`
        })
        return str
      }
      return val
    }
  }
}
</script>
<style lang="less" scoped>
.components {
  max-height: calc(100vh - 120px);
  background-color: #F6FAFE;
  overflow-y: auto;
  padding-top: 1px;
}
.section {
  background-color: var(--bg-);
  padding: 20px 18px 18px;
  margin-bottom: 6px;
  .price-box {
    display: flex;
    align-items: baseline;
    margin-bottom: 12px;
    justify-content: space-between;
  }
  .price {
    display: flex;
    align-items: baseline;
    color: #EA4A45;
    font-weight: 600;
    font-size: 28px;
    &.down {
      color: #29AE6D;
    }
    .icon2 {
      width: 10px;
    }
  }
  .des {
    color: #333333;
  }
  .name-box {
    color: var(--color-1-);
    font-size: 12px;
    margin-bottom: 15px;
    .name {
      font-weight: 500;
      justify-content: space-between;
      margin-bottom: 14px;
    }
    .state {
      color: #999BA1;
    }
    .differ {
      color: #EA4A45;
      margin-left: 4px;
      &.down {
        color: #29AE6D;
      }
    }
  }
  .state-box {
    justify-content: space-between;
  }
  .img-box {
    column-gap: 3px;
    cursor: pointer;
    .icon1 {
      height: 13px;
    }
  }
  .van-row {
    &+.van-row {
      margin-top: 8px;
    }
    .col {
      justify-content: space-between;
      font-size: 11px;
      align-items: flex-start;
    }
    .label {
      min-width: 44px;
      color: #A0A0A0;
      font-weight: 400;
      &.cn{
        display: flex;
        justify-content: space-between;
      }
    }
    .val {
      font-weight: 500;
      color: #090909;
      white-space: nowrap;
    }
    .down {
      color: #29AE6D;
    }
    .up {
      color: #EA4A45;
    }
  }
}
.section1 {
  background-color: var(--bg-);
  margin-bottom: 10px;
  padding: 0 18px;
  .title {
    justify-content: space-between;
    font-size: 12px;
    color: var(--color-1-);
    height: 44px;
    .differ {
      color: var(--red-);
      margin-left: 10px;
    }
    .el-icon-arrow-down {
      font-size: 16px;
      font-weight: 500;
    }
  }
}
.section2 {
  background-color: var(--bg-);
  margin-bottom: 2px;
  font-size: 14px;
  color: #A2A2A2;
}
</style>