<template>
  <div class="list">
    <div class="li" v-for="item in list" :key="item.ticket">
      <div class="left">
        <div class="box flex">
          <div class="title" v-if="productDataObj[item.symbol]">
            {{ productDataObj[item.symbol].title }}
          </div>
          <div>({{ item.symbol }})</div>
          <div class="cmd" :class="'cmd' + item.cmd">
            <!-- 买 -->
            {{ item.cmd == 0 ? $t('follow.l32') : $t('follow.l33') }}
          </div>
        </div>
        <div class="price flex">
          <div>{{ $handleDigits(item.open_price, productDataObj[item.symbol] ? productDataObj[item.symbol].digits : 2) }}</div>
          &gt;
          <div v-if="productDataObj[item.symbol]" :class="{up: item.cmd == 0, down: item.cmd == 1}">{{ $handleDigits(item.cmd == 0 ? productDataObj[item.symbol].ask : productDataObj[item.symbol].bid, productDataObj[item.symbol].digits) }}</div>
        </div>
        <div class="time flex">
          <div>{{ item.open_time.replace(/-/g, '/') }}</div>
        </div>
      </div>
      <div class="right">
        <div class="flex box1">
          <div class="lab">
            <!-- 数量 -->
            {{ $t('common.l25') }}
          </div>
          <div v-if="productDataObj[item.symbol]">
            {{ $handleDigits($bigDecimal.multiply(item.volume, productDataObj[item.symbol].contract_size)) }}
          </div>
        </div>
        <div class="income-box">
          <div>
            <!-- 收益率 -->
            {{ $t('follow.l7') }}
          </div>
          <div class="val" v-if="productDataObj[item.symbol]" :class="getRateReturn(item) > 0 ? 'up' : 'down'">
            {{ getRateReturn(item) }}%
          </div>
        </div>
      </div>
    </div>
    <NoData v-if="!loading && list.length == 0" />
  </div>
</template>
<script>
import { getExpertTradeList } from "@/api/copy";
import bus from '@/utils/bus'
export default {
  inject: ['getproductDataObj'],
  data () {
    return {
      loading: false,
      list: [],
      symbolList: [],
      id: '',
    }
  },
  computed: {
    productDataObj() {
      return this.getproductDataObj()
    },
  },
  created () {
    this.id = this.$route.params.id
    this.getExpertTradeList()
  },
  methods: {
    getExpertTradeList() {
      this.loading = true;
      getExpertTradeList({
        eid: this.id,
        status: 1,
      }).then(res => {
        var list = res.list || [];
        var symbolList = []
        list.forEach((item) => {
          if (this.symbolList.indexOf(item.symbol) === -1) {
            this.symbolList.push(item.symbol)
            if (!this.productDataObj[item.symbol]) {
              symbolList.push(item.symbol)
            }
          }
        })
        bus.$emit("alterProductData", {
          getData: symbolList,
          subscribeList: [...this.symbolList]
        });
        this.list = list;
      }).catch(() => {}).finally(() => {
        this.loading = false;
      })
    },
    getRateReturn(item) {
      return ((((item.cmd == 0 ? this.productDataObj[item.symbol].ask : this.productDataObj[item.symbol].bid) - item.open_price) / item.open_price) * 100).toFixed(2)
    }
  }
}
</script>
<style lang="less" scoped>
.list {
  padding: 0 16px 10px;
}
.li {
  border-radius: 8px;
  border: 1px solid #F6F6F6;
  padding: 14px 9px;
  position: relative;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  column-gap: 12px;
}
.left {
  flex: 1;
  min-width: 0px;
}
.box {
  margin-bottom: 6px;
  .title {
    min-width: 0px;
    max-width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .cmd {
    margin-left: 6px;
    padding: 2px;
    border-radius: 2px;
    background-color: var(--red-);
    font-weight: 600;
    font-size: 10px;
    color: #FFFFFF;
  }
}
.price {
  font-size: 12px;
  color: #B6B6B6;
  column-gap: 4px;
}
.time {
  font-size: 10px;
  color: #B6B6B6;
  margin-top: 10px;
  column-gap: 4px;
  .icon {
    width: 10px;
  }
}
.right {
  .box1 {
    font-size: 10px;
    column-gap: 4px;
    margin-bottom: 10px;
    .lab {
      color: #B6B6B6;
    }
  }
}
.income-box {
  font-size: 12px;
  color: #888888;
  .val {
    font-weight: 600;
    font-size: 14px;
    margin-top: 6px;
  }
}
.up {
  color: var(--red-);
}
.down {
  color: var(--green-);
}
</style>