<template>
  <div class="components" v-loading.body.fullscreen="fullscreenLoading" element-loading-background="rgba(255, 255, 255, 0)">
    <div class="place" v-if="!symbol">
      <div class="search-box flex" @click="searchShow = true">
        <img class="img" src="/img/exchange/search.png" alt="极度证券">
        <div>
          <!-- 请输入代码 -->
          {{ $t('exchange.l40') }}
        </div>
      </div>
    </div>
    <div class="section" v-if="symbol">
      <div class="box flex">
        <div class="label">
          <!-- 代码 -->
          {{ $t('exchange.l39') }}
        </div>
        <div class="right flex" @click="searchShow = true">
          <div>{{ symbol }}</div>
          <i class="el-icon-arrow-right"></i>
        </div>
      </div>
      <div class="box flex" v-if="symbolInfo.symbol">
        <div class="label">
          {{ symbolInfo.title }}
        </div>
        <div class="flex right">
          <div class="flex" :class="{'down': productDataObj[symbol].spread < 0}">
            <div>{{ $handleDigits(productDataObj[symbol].ask, symbolInfo.digits) }}</div>
            <div>{{ productDataObj[symbol].spread > 0 ? '+' : ''  }}{{ $handleDigits(productDataObj[symbol].spread, symbolInfo.digits) }}</div>
            <div>{{ productDataObj[symbol].spread > 0 ? '+' : ''  }}{{ productDataObj[symbol].percentage }}%</div>
          </div>
          <i class="el-icon-arrow-down" :class="{'active': showChart == 2}" @click="toggleChart"></i>
        </div>
      </div>
    </div>
    <div class="chart-box" v-if="symbolInfo.symbol && showChart == 2">
      <quotationk :symbol="symbol" :symbolInfo="symbolInfo" height="350px" />
    </div>
    <div class="section" v-if="symbolInfo.symbol">
      <complexCfd v-if="symbolInfo.market == 'CFD'" :symbol="symbol" :accountInfo="accountInfo" :symbolCopy="symbolCopy" />
      <complexStock v-else :symbol="symbol" :accountInfo="accountInfo" :symbolCopy="symbolCopy" />
    </div>
    <van-popup v-model="searchShow" position="right" :style="{ width: '100%' }">
      <search :market="accountInfo.market || symbolInfo.market" v-if="searchShow" type="1" @success="searchBack" @cancel="searchShow = false"/>
    </van-popup>
  </div>
</template>
<script>
import quotationk from "./quotationk.vue";
import search from "./search.vue";
import complexCfd from "./open/complexCfd.vue";
import complexStock from "./open/complexStock.vue";
import { getStorage, setStorage } from '@/utils/localStorage'
export default {
  props: ['symbol', 'accountInfo', 'symbolCopy'],
  components: {
    search,
    quotationk,
    complexCfd,
    complexStock
  },
  data () {
    return {
      showChart: getStorage('showChart') || 2,
      searchShow: false,
      tooltipShow: false,
    }
  },
  inject: ['getproductDataObj'],
  computed: {
    productDataObj() {
      return this.getproductDataObj()
    },
    symbolInfo() {
      return this.productDataObj[this.symbol] || {}
    },
    // sumMoney() {
    //   if (this.type == 1 && !Number(this.price)) {
    //     return '--'
    //   }
    //   return Number(this.$bigDecimal.multiply(this.type == 1 ? this.price : this.productDataObj[this.symbol].ask, this.$bigDecimal.multiply(this.volume, this.symbolInfo.contract_size))).toFixed(2)
    // },
    // availableBuy() {
    //   if (!Number(this.price)) {
    //     return '0.00'
    //   }
    //   return this.$bigDecimal.multiply(this.accountInfo.margin_free, 50)
    // },
    // availableSell() {
    //   if (!Number(this.price)) {
    //     return '0.00'
    //   }
    //   return this.$bigDecimal.multiply(this.accountInfo.margin_free, 50)
    // },
    // buyDisable() {
    //   if (!this.isLogin || !Number(this.price) || !Number(this.volume)) {
    //     return false
    //   }
    //   return Number(this.sumMoney) > Number(this.availableBuy)
    // },
    // sellDisable() {
    //   if (!this.isLogin || !Number(this.price) || !Number(this.volume)) {
    //     return false
    //   }
    //   return Number(this.sumMoney) > Number(this.availableBuy)
    // }
  },
  methods: {
    searchBack(val) {
      this.$router.replace(`/exchange/${val}/buy`)
      this.searchShow = false
    },
    toggleChart() {
      this.showChart = this.showChart == 1 ? 2 : 1
      setStorage('showChart', this.showChart)
    }
  }
}
</script>
<style lang="less" scoped>
.place {
  padding: 15px 16px 0;
  background-color: var(--bg-);
  color: #C3C3C3;
  .search-box {
    cursor: pointer;
    border-radius: 4px;
    border: 1px solid #D9D9D9;
    height: 38px;
    padding: 0 13px;
  }
  .img {
    width: 20px;
  }
}
.section {
  margin-bottom: 6px;
  background-color: var(--bg-);
  padding: 0 16px;
}
.box {
  padding: 12px 0;
  column-gap: 7px;
  border-bottom: 1px solid #F6F6F6;
  .label {
    width: 127px;
    color: #888888;
  }
  .right {
    flex: 1;
    justify-content: space-between;
    min-width: 10%;
    max-width: 100%;
    color: #000000;
    cursor: pointer;
    .flex {
      color: var(--red-);
      column-gap: 10px;
      &.down {
        color: var(--green-);
      }
    }
  }
  .place {
    color: #9F9F9F;
  }
  .el-icon-arrow-down {
    cursor: pointer;
    transform: rotateZ(180deg);
    transition: transform 0.5s;
    &.active {
      transform: rotateZ(0);
    }
  }
  .el-icon-arrow-right, .el-icon-arrow-down {
    font-size: 20px;
    color: #B6B6B6;
    margin-right: -2px;
  }
}
.chart-box {
  padding-right: 14px;
  padding-bottom: 10px;
  background-color: var(--bg-);
  margin-bottom: 6px;
}
</style>