<template>
  <custom-base-table
    :data="data"
    :columns="columns"
    thead-classes="text-primary"
  >
    <!-- 卖卖类型 -->
    <template slot="OrderType">
      <p>买入</p>
      <p>卖出</p>
    </template>
    <!-- 买卖时间 -->
    <template slot="KLineId" slot-scope="item">
      <p>
        {{
          moment(item.row.item.PurchaseKLineId * 1000).format(
            "YYYY-MM-DD HH:mm:ss"
          )
        }}
      </p>
      <p>
        {{
          item.row.item.SaleKLineId
            ? moment(item.row.item.SaleKLineId * 1000).format(
                "YYYY-MM-DD HH:mm:ss"
              )
            : "-"
        }}
      </p>
    </template>
    <!-- 买卖价格 -->
    <template slot="Price" slot-scope="item">
      <p>{{ item.row.item.PurchasePrice || "-" }}</p>
      <p>{{ item.row.item.SalePrice || "-" }}</p>
    </template>
    <!-- 买卖数量 -->
    <template slot="Count" slot-scope="item">
      <p>{{ item.row.item.PurchaseCoinCount || "-" }}</p>
      <p>{{ item.row.item.SaleCoinCount || "-" }}</p>
    </template>
    <!-- 最大浮亏 -->
    <template slot="MaxLossRatio" slot-scope="item">
      <p>{{ item.row.item.MaxLossPrice || "-" }}</p>
      <p>{{ item.row.item.MaxLossRatio || "-" }}%</p>
    </template>
    <!-- 盈亏 -->
    <template slot="Profit" slot-scope="item">
      <p>{{ item.row.item.Profit }}</p>
      <p v-if="item.row.item.Profit">
        {{
          (
            (item.row.item.Profit / item.row.item.TotalPurchasePrice) *
            100
          ).toFixed(2)
        }}%
      </p>
      <p v-else>-</p>
    </template>
    <!-- 累计盈亏 -->
    <template slot="TotalProfit" slot-scope="item">
      <p>{{ item.row.item.TotalProfit }}</p>
      <p v-if="item.row.item.TotalProfit">
        {{
          (
            (item.row.item.TotalProfit / policyFormData.PositionFund) *
            100
          ).toFixed(2)
        }}%
      </p>
      <p v-else>-</p>
    </template>
  </custom-base-table>
</template>

<script>
import CustomBaseTable from "../../components/CustomBaseTable";
import { tradeColumns } from "../../pages/prePages/js/columns";
import moment from "moment";
export default {
  model: { prop: "data", event: "tableDataChange" },
  props: { data: { type: Array, default: () => [] } },
  components: { CustomBaseTable },
  data() {
    return { moment, columns: tradeColumns };
  }
};
</script>
