<template>
  <div class="components">
    <div class="section">
      <div class="name-box">
        <div class="symbol flex">
          <div>{{ symbol }}</div>
          <div class="industry" v-if="language == 'zh-CN' ||  language == 'zh-TW'">{{ companyInfo.industry }}</div>
          <div class="industry" v-else>{{ companyInfo.industry_en || companyInfo.industry }}</div>
        </div>
        <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?2" alt="极度证券">
            <img v-show="symbolInfo.spread < 0" class="icon2" src="/img/product/down1.png?2" alt="极度证券">
          </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 class="state-box 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.spread > 0 ? '+' : ''  }}{{ symbolInfo.percentage }}%)</div>
        </div>
      </div>
      <van-row gutter="8">
        <van-col span="8">
          <div class="col flex">
            <!-- 开盘 -->
            <div class="label">
              {{ $t('product.l60') }}
            </div>
            <div v-if="symbolOpen.open">{{ $handleDigits(symbolOpen.open, symbolInfo.digits) }}</div>
            <div v-else>--</div>
          </div>
        </van-col>
        <van-col span="8">
          <div class="col flex">
            <!-- 昨收 -->
            <div class="label">
              {{$t('product.l61')}}
            </div>
            <div class="val">{{ $handleDigits(symbolInfo.close, symbolInfo.digits) }}</div>
          </div>
        </van-col>
        <van-col span="8">
          <div class="col flex">
            <!-- 最高 -->
            <div class="label">
              {{ $t('product.l62') }}
            </div>
            <div class="val up" v-if="symbolOpen.high">{{ $handleDigits(symbolOpen.high, symbolInfo.digits) }}</div>
            <div v-else>--</div>
          </div>
        </van-col>
      </van-row>
      <van-row gutter="8">
        <van-col span="8">
          <div class="col flex">
            <!-- 最低 -->
            <div class="label">
              {{ $t('product.l63') }}
            </div>
            <div class="val down" v-if="symbolOpen.low">{{ $handleDigits(symbolOpen.low, symbolInfo.digits) }}</div>
            <div v-else>--</div>
          </div>
        </van-col>
        <van-col span="8">
          <div class="col flex" v-if="symbolInfo.type == 1">
            <!-- 总股本 -->
            <div class="label">
              {{ $t('product.l64') }}
            </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">
              {{ $t('product.l66') }}
            </div>
            <div class="val">{{ marketFormat(marketValue) }}</div>
          </div>
        </van-col>
      </van-row>
      <van-row gutter="8" v-if="symbolInfo.type == 1">
        <van-col span="8">
          <div class="col flex">
            <div class="label">
              <!-- 流通股本 -->
              {{ $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">
              <!-- 流通市值 -->
              {{ $t('product.l67') }}
            </div>
            <div class="val">{{ marketFormat(marketValue1) }}</div>
          </div>
        </van-col>
        <van-col span="8">
          <div class="col flex">
            <!-- 市盈率 -->
            <div class="label">
              {{ $t('product.l98') }}
            </div>
            <div class="val">{{ epsjbFormat(companyInfo.epsjb) }}</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="379px"/>
    </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', 'symbolOpen'],
  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 '--'
    },
    epsjbFormat(epsjb) {
      if (!epsjb && epsjb !== 0) {
        return '--'
      }
      if (epsjb <= 0) {
        return this.$t('product.l109')
      }
      return (this.symbolInfo.ask / epsjb).toFixed(2)
    },
  }
}
</script>
<style lang="less" scoped>
.components {
  max-height: calc(100vh - 120px);
  background-color: #F6F6F6;
  overflow-y: auto;
}
.section {
  background-color: var(--bg-);
  padding: 6px 10px 20px;
  margin-bottom: 1px;
  .name-box {
    color: #000;
    margin-bottom: 20px;
    .symbol {
      font-weight: 600;
      margin-bottom: 12px;
      justify-content: space-between;
    }
    .industry {
      font-weight: 400;
    }
  }
  .price-box {
    display: flex;
    align-items: baseline;
    margin-bottom: 13px;
    justify-content: space-between;
  }
  .price {
    display: flex;
    align-items: baseline;
    color: var(--red-);
    font-weight: 600;
    font-size: 26px;
    &.down {
      color: var(--green-);
    }
    .icon2 {
      width: 8px;
      margin-left: 6px;
      transform: translateY(-1px);
    }
  }
  .img-box {
    column-gap: 2px;
    cursor: pointer;
    .icon1 {
      height: 16px;
    }
  }
  .state-box {
    column-gap: 4px;
    font-size: 12px;
    .state {
      color: #888888;
    }
    .differ {
      color: var(--red-);
      &.down {
        color: var(--green-);
      }
    }
  }
  .van-row {
    &+.van-row {
      margin-top: 10px;
    }
    .col {
      justify-content: space-between;
      font-size: 12px;
      align-items: flex-start;
    }
    .label {
      min-width: 50px;
      color: #888888;
      font-weight: 400;
    }
    .val {
      color: #000;
      white-space: nowrap;
    }
    .down {
      color: var(--green-);
    }
    .up {
      color: var(--red-);
    }
  }
}
.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: 1px;
  font-size: 14px;
  color: #888888;
  padding-right: 10px;
  padding-bottom: 10px;
}
</style>