<template>
  <div class="list">
    <van-list
      v-model="loading"
      :finished="finished"
      :finished-text="list.length ? $t('common.l5') : ''"
      @load="onLoad"
    >
      <div class="li" v-for="item in list" :key="item.id">
        <van-image
          width="36"
          height="36"
          round
          fit="cover"
          :src="(item.path == 2 ? expertInfo.header : item.user_header) || '/img/follow/follow.png'"
        />
        <div class="body" v-if="item.path == 2">
          <div class="name-box">
            <div class="name">
              <!-- 申请结算 -->
              {{ $t('follow.l117') }}
            </div>
            <div class="time flex">
              <div class="lab">
                <!-- 申请时间  -->
                {{ $t('follow.l131') }}
              </div>
              <div>
                {{ item.insert_datetime.replace(/-/g, '/') }}
              </div>
            </div>
          </div>
          <div class="cell flex">
            <div class="lab">
              <!-- 结算金额 -->
              {{ $t('option.l34') }}
            </div>
            <div class="right">
              {{ $numToThousand(item.amount) }} USD
            </div>
          </div>
          <div class="cell flex">
            <div class="lab">
              <!-- 当前状态 -->
              {{ $t('follow.l135') }}
            </div>
            <div class="right">
              {{ statusText[item.status] }}
            </div>
          </div>
        </div>
        <div class="body" v-else>
          <div class="name-box">
            <div class="name">
              {{ item.user_title }}
            </div>
            <div class="time flex">
              <div class="lab">
                <!--  交易时间 -->
                {{ $t('product.l82') }}
              </div>
              <div>
                {{ item.insert_datetime.replace(/-/g, '/') }}
              </div>
            </div>
          </div>
          <div class="cell flex">
            <div class="lab">
              <!-- 跟单标的 -->
              {{ $t('follow.l132') }}
            </div>
            <div class="right">
              {{ productDataObj[item.from.symbol] ? productDataObj[item.from.symbol].title : '' }} {{ item.from.symbol }}
            </div>
          </div>
          <div class="cell flex">
            <div class="lab">
              <!-- 跟单数量 -->
              {{ $t('follow.l133') }}
            </div>
            <div class="right" v-if="productDataObj[item.from.symbol]">
              {{ $handleDigits($bigDecimal.multiply(item.from.volume, productDataObj[item.from.symbol].contract_size)) }}
            </div>
          </div>
          <div class="cell flex">
            <div class="lab">
              <!-- 跟单收益 -->
              {{ $t('follow.l134') }}
            </div>
            <div class="right up">
              {{item.from.profit > 0 ? '+' : '' }} {{ $numToThousand(item.from.profit) }} USD
            </div>
          </div>
          <div class="cell flex">
            <div class="lab">
              <!-- 分润金额 -->
              {{ $t('follow.l28') }}
            </div>
            <div class="right up">
              + {{ $numToThousand(item.amount) }} USD
            </div>
          </div>
        </div>
      </div>
     <NoData v-if="!loading && list.length == 0" />
    </van-list>
  </div>
</template>
<script>
import { getFollowBonusList } from "@/api/copy";
import bus from '@/utils/bus'
import { mapGetters } from "vuex";
export default {
  inject: ['getproductDataObj'],
  data () {
    return {
      pageNum: 0,
      pageSize: 20,
      list: [],
      finished: false,
      loading: false,
      symbolList: [],
      statusText: {
        // '1': '未支付',
        // '2': '待审核',
        // '3': '已驳回',
        // '4': '处理中',
        // '5': '已撤销',
        // '100': '已完成',
        '1': this.$t('ajax.201'),
        '2': this.$t('ajax.350'),
        '3': this.$t('ajax.408'),
        '4': this.$t('ajax.401'),
        '5': this.$t('ajax.404'),
        '100': this.$t('ajax.403'),
      },
    }
  },
  computed: {
    ...mapGetters(['expertInfo']),
    productDataObj() {
      return this.getproductDataObj()
    },
  },
  methods: {
    reset() {
      this.pageNum = 0
      this.onLoad()
    },
    onLoad() {
      this.pageNum += 1;
      if (this.pageNum == 1) {
        this.list = [];
      }
      this.getFollowBonusList()
    },
    getFollowBonusList() {
      getFollowBonusList({
        pageNum: this.pageNum,
        pageSize: this.pageSize,
      }).then(res => {
        var list = res.list || [];
        var symbolList = []
        list.forEach(item => {
          item.from = item.from ? JSON.parse(item.from) : {}
          if (this.symbolList.indexOf(item.from.symbol) === -1 && !this.productDataObj[item.from.symbol]) {
            symbolList.push(item.from.symbol)
            this.symbolList.push(item.from.symbol)
          }
        })
        bus.$emit("alterProductData", {
          getData: symbolList
        });
        if (this.pageNum == 1) {
          this.list = list;
        } else {
          this.list = this.list.concat(list);
        }
        this.loading = false;
        if (res.endRow == res.total) {
          this.finished = true;
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
.list {
  padding: 20px 16px 10px;
}
.li {
  border-radius: 8px;
  border: 1px solid #F6F6F6;
  padding: 9px 9px 13px;
  margin-bottom: 10px;
  display: flex;
  align-items: flex-start;
}
.body {
  flex: 1;
  min-width: 0px;
  padding-top: 4px;
  padding-left: 10px;
  .cell {
    column-gap: 6px;
    align-items: flex-start;
    justify-content: space-between;
    font-size: 12px;
    color: #B6B6B6;
    &+.cell {
      margin-top: 10px;
    }
  }
  .right {
    flex: 1;
    text-align: right;
    min-width: 0px;
  }
}
.name-box {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  column-gap: 12px;
  margin-bottom: 10px;
  .name {
    font-size: 15px;
    font-weight: 500;
  }
  .time {
    font-size: 10px;
    color: #B6B6B6;
    column-gap: 4px;
  }
}
.up {
  color: var(--red-);
}
.down {
  color: var(--green-);
}
</style>