<template>
  <div class="list">
    <div class="li" v-for="item in followList" :key="item.eid">
      <div class="box">
        <div class="left flex">
          <van-image
            width="42"
            height="42"
            round
            fit="cover"
            :src="item.header || '/img/home/user.png'"
          />
          <div class="right">
            <div class="flex name-box">
              <div class="name">
                {{ item.expert_title }}
              </div>
              <div class="level">
                {{ item.expert_level }}
              </div>
            </div>
            <div class="tip flex" v-if="item.expert_active_datetime">
              <div class="radius"></div>
              <div>
                {{ getDay(item.expert_active_datetime) }}
              </div>
            </div>
          </div>
        </div>
        <div class="detail flex" @click="$router.push('/copy/detail/' + item.eid)">
          <div>
            <!-- 详情 -->
            {{ $t('fund.l51') }}
          </div>
          <img class="icon" src="/img/copy/market/right.png" alt="">
        </div>
      </div>
      <van-row gutter="6" type="flex">
        <van-col span="8">
          <div class="lab">
            <!-- 收益 -->
            {{ $t('follow.l138') }}
          </div>
          <div class="amount" :class="{up: item.profit >= 0, down: item.profit < 0}">
            {{ item.profit > 0 ? '+' : '' }} {{ $numToThousand(item.profit) }} USD
          </div>
        </van-col>
        <van-col span="8">
          <div class="lab">
            <!-- 分润 -->
            {{ $t('follow.l139') }}
          </div>
          <div class="amount" :class="{up: item.expert_profit >= 0, down: item.expert_profit < 0}">
            {{ item.expert_profit > 0 ? '+' : '' }} {{ $numToThousand(item.expert_profit) }} USD
          </div>
        </van-col>
        <van-col span="8">
          <div class="btn-box flex">
            <div class="btn" @click="cancelPopShow(item)">
              <!-- 取消跟单 -->
              {{ $t('follow.l30') }}
            </div>
          </div>
        </van-col>
      </van-row>
    </div>
    <NoData v-if="followList.length == 0 && loaded" />
    <van-popup v-model="cancelPop" round position="bottom">
      <cancelCopy :info="expertInfo" @success="cancelBack"/>
    </van-popup>
  </div>
</template>
<script>
import cancelCopy from "@/view/copyTrade/copyDetail/components/cancelCopy.vue";
import { mapGetters } from "vuex";
export default {
  components: {
    cancelCopy
  },
  data () {
    return {
      loaded: false,
      cancelPop: false,
      expertInfo: {}
    }
  },
  computed: {
    ...mapGetters(['followList']),
  },
  created () {
    this.$store.dispatch('getFollowList').finally(() => {
      this.loaded = true
    })
  },
  methods: {
    cancelPopShow(item) {
      this.cancelPop = true
      this.expertInfo = item
    },
    cancelBack() {
      this.$store.dispatch('getFollowList')
      this.cancelPop = false
    },
    getDay(time) {
      var timeDifference = new Date() - new Date(time.replace(' ', 'T') + '+08:00')
      var day = Math.floor(timeDifference / (1000 * 60 * 60 * 24))
      return day < 3 ? this.$t('follow.l140').replace('{p}', day || 1) : this.$t('follow.l165')
    }
  }
}
</script>
<style lang="less" scoped>
.list {
  padding: 0 10px 6px;
}
.li {
  border-radius: 8px;
  border: 1px solid #F6F6F6;
  padding: 9px;
  position: relative;
  margin-bottom: 10px;
}
.box {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  column-gap: 6px;
  padding-bottom: 8px;
  .left,.right {
    flex: 1;
    min-width: 0;
  }
  .left {
    column-gap: 10px;
  }
  .name-box {
    column-gap: 4px;
    margin-bottom: 4px;
  }
  .name {
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .level {
    border-radius: 2px;
    border: 1px solid #F6F6F6;
    padding: 2px 3px;
    font-size: 10px;
  }
  .detail {
    column-gap: 4px;
    font-size: 12px;
    cursor: pointer;
    padding-top: 4px;
  }
  .icon {
    width: 6px;
  }
}
.tip {
  font-size: 12px;
  color: #B6B6B6;
  .radius {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #64C063;
    margin-right: 4px;
  }
}
.van-row {
  align-items: flex-end;
  font-size: 10px;
  .lab {
    color: #B6B6B6;
    margin-bottom: 4px;
  }
  .btn-box {
    justify-content: flex-end;
  }
  .btn {
    cursor: pointer;
    background-color: #000000;
    border-radius: 15px;
    padding: 7px 14px;
    font-size: 12px;
    color: #FFFFFF;
  }
}
.up {
  color: var(--red-);
}
.down {
  color: var(--green-);
}
</style>