<template>
  <div>
    <!-- 没有更多了 -->
    <van-list
      v-model="loading"
      :finished="finished"
      :finished-text="list.length == 0 ? '' : $t('common.l46')"
      @load="onLoad"
    >
      <div class="item" v-for="item in list" :key="item.id" @click="checkDetail(item)">
        <div class="top flex">
          <div class="left flex">
            <img v-if="item.status == 100" class="icon" src="/img/list/out1.svg" alt="极度证券">
            <img v-else class="icon" src="/img/list/out.svg" alt="极度证券">
            <div>
              <!-- 提取资金 -->
              {{ $t('account.l37') }}
            </div>
          </div>
          <div class="right">
            -{{ $handleDigits2(item.amount) }} USD
          </div>
        </div>
        <div class="bottom">
          <div class="time-box flex">
            <div>{{ item.insert_datetime }}</div>
            <div class="right flex" :class="{'green': item.status == 100}">
              <div>{{ statusText[item.status] }}</div>
              <div class="radius"></div>
            </div>
          </div>
          <div class="flex type">
            <div>{{ $t('account.l1') }}</div>
            <van-icon name="down" />
            <div v-if="item.pay_type == 3 || item.pay_type == 4">{{ item.arrive_currency }}</div>
            <div v-else>{{ payName[item.pay_type] }}</div>
          </div>
        </div>
      </div>
      <!-- 暂无记录 -->
      <NoData :title="$t('common.l45')" v-if="list.length == 0 && !loading"/>
    </van-list>
  </div>
</template>
<script>
import { getCashRecordList } from "@/api/list";
export default {
  props: ['status'],
  data () {
    return {
      list: [],
      loading: false,
      finished: false,
      pageNum: 0,
      pageSize: 10,
      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'),
        '6': this.$t('ajax.401'),
        '100': this.$t('ajax.403'),
      },
    }
  },
  computed: {
    payName() {
      return {
        // '1': '银行汇款',
        // '2': '国际电汇',
        // '3': '数字货币',
        '1': this.$t('account.l31'),
        '2': this.$t('account.l32'),
        '3': this.$t('account.l33'),
      }
    },
  },
  methods: {
    reset() {
      this.finished = false
      this.loading = true
      this.pageNum = 0
      this.onLoad()
    },
    onLoad() {
      this.pageNum += 1
      getCashRecordList({
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        type: JSON.stringify([100]),
        status: this.status,
        path: 2
      }).then(res => {
        var list = res.list || []
        list.forEach(item => {
          item.from = item.from ? JSON.parse(item.from) : {}
          item.to = item.to ? JSON.parse(item.to) : {}
        })
        if (this.pageNum == 1) {
          this.list = list
        } else {
          this.list = this.list.concat(list)
        }
        // 加载状态结束
        this.loading = false;
        // 数据全部加载完成
        if (this.list.length >= res.total) {
          this.finished = true;
        }
      }).catch(() => {
        this.loading = false;
        this.finished = true;
      })
    },
    checkDetail(item) {
      this.$router.push('/account-records/detail/2/' + item.ordernum)
    },
  },
}
</script>
<style lang="less" scoped>
.van-list {
  padding: 17px 17px 0;
  .item {
    border-radius: 6px;
    border: 1px solid #E3E3E3;
    padding: 15px 12px 18px;
    &+.item {
      margin-top: 10px;
    }
  }
  .top {
    justify-content: space-between;
    margin-bottom: 9px;
    .icon {
      width: 17px;
      margin-right: 3px;
    }
    .right {
      font-size: 16px;
      font-weight: 600;
    }
  }
  .bottom {
    padding-left: 20px;
    font-size: 12px;
    color: #979797;
  }
  .time-box {
    justify-content: space-between;
    margin-bottom: 13px;
    .radius {
      width: 4px;
      height: 4px;
      border-radius: 50%;
      background: #FB4136;
      margin-left: 3px;
    }
    .right {
      color: #FB4136;
      &.green {
        color: #00B960;
        .radius {
          background-color: #00B960;
        }
      }
    }
  }
  .type {
    column-gap: 4px;
    .van-icon {
      transform: rotate(-90deg);
    }
  }
}
</style>