<template>
  <s-layout class="widthdraw-log-wrap" :title="$t('pay.withdrawlog.title')">
    <!-- 记录卡片 -->
    <view class="wallet-log-box ss-p-b-30">
      <view class="log-list" v-for="item in state.pagination.data" :key="item">
        <view class="head ss-flex ss-col-center ss-row-between">
          <view class="title">{{
            item.withdraw_type === 'bank'
              ? $t('pay.withdrawlog.tobank')
              : item.withdraw_type === 'alipay'
              ? $t('pay.withdrawlog.toalipay')
              : $t('pay.withdrawlog.toweixin')
          }}</view>
          <view
            class="num"
            :class="
              item.status === -1
                ? 'danger-color'
                : item.status === 2
                ? 'success-color'
                : 'warning-color'
            "
            >{{ item.amount }}元</view
          >
        </view>
        <view class="status-box item ss-flex ss-col-center ss-row-between">
          <view class="item-title">{{$t('pay.withdrawlog.applyStatus')}}</view>
          <view
            class="status-text"
            :class="
              item.status === -1
                ? 'danger-color'
                : item.status === 2
                ? 'success-color'
                : 'warning-color'
            "
            >{{ item.status_text }}</view
          >
        </view>
        <view class="time-box item ss-flex ss-col-center ss-row-between">
          <text class="item-title">{{$t('pay.withdrawlog.accountInfo')}}</text>
          <view class="time ss-ellipsis-1" v-if="item.withdraw_type === 'bank'"
            >{{ item.withdraw_info_hidden.开户行 }}[{{ item.withdraw_info_hidden.银行卡号 }}]</view
          >
          <view class="time ss-ellipsis-1" v-if="item.withdraw_type === 'alipay'">
            {{$t('pay.withdrawlog.alipay')}}[{{ item.withdraw_info_hidden.支付宝账户 }}]
          </view>
          <view class="time ss-ellipsis-1" v-if="item.withdraw_type === 'wechat'">{{$t('pay.withdrawlog.wxbalance')}}</view>
        </view>
        <view class="time-box item ss-flex ss-col-center ss-row-between">
          <text class="item-title">{{$t('pay.withdrawlog.orderNo')}}</text>
          <view class="time"> {{ item.withdraw_sn }} </view>
        </view>
        <view class="time-box item ss-flex ss-col-center ss-row-between">
          <text class="item-title">{{$t('pay.withdrawlog.fee')}}</text>
          <view class="time">{{ item.charge_fee }}元{{$t('pay.withdrawlog.cny')}}</view>
        </view>
        <view class="time-box item ss-flex ss-col-center ss-row-between">
          <text class="item-title">{{$t('pay.withdrawlog.applyTime')}}</text>
          <view class="time"> {{ item.createtime }}</view>
        </view>
      </view>
    </view>
    <s-empty
      v-if="state.pagination.total === 0"
      icon="/static/comment-empty.png"
      :text="$t('pay.withdrawlog.noData')"
    ></s-empty>
    <uni-load-more
      v-if="state.pagination.total > 0"
      :status="state.loadStatus"
      :content-text="{
        contentdown: '$t('activity.index.uploadMore'),
      }"
      @tap="loadmore"
    />
  </s-layout>
</template>

<script setup>
  import { reactive } from 'vue';
  import sheep from '@/sheep';
  import { onLoad, onReachBottom } from '@dcloudio/uni-app';
  import _ from 'lodash';
  const state = reactive({
    currentTab: 0,
    pagination: {
      data: [],
      current_page: 1,
      total: 1,
      last_page: 1,
    },
    loadStatus: '',
  });
  async function getList(page = 1, list_rows = 6) {
    const res = await sheep.$api.pay.withdraw.list({ list_rows, page });
    if (res.code === 1) {
      let logList = _.concat(state.pagination.data, res.data.data);
      state.pagination = {
        ...res.data,
        data: logList,
      };
      if (state.pagination.current_page < state.pagination.last_page) {
        state.loadStatus = 'more';
      } else {
        state.loadStatus = 'noMore';
      }
    }
  }
  // 加载更多
  function loadmore() {
    if (state.loadStatus !== 'noMore') {
      getList(state.pagination.current_page + 1);
    }
  }
  onLoad(() => {
    getList();
  });
  onReachBottom(() => {
    loadmore();
  });
</script>

<style lang="scss" scoped>
  // 记录卡片
  .log-list {
    min-height: 213rpx;
    background: $white;
    margin-bottom: 10rpx;
    padding-bottom: 10rpx;

    .head {
      padding: 0 35rpx;
      height: 80rpx;
      border-bottom: 1rpx solid $gray-e;
      margin-bottom: 20rpx;

      .title {
        font-size: 28rpx;
        font-weight: 500;
        color: $dark-3;
      }

      .num {
        font-size: 28rpx;
        font-weight: 500;
      }
    }

    .item {
      padding: 0 30rpx 10rpx;

      .item-icon {
        color: $gray-d;
        font-size: 36rpx;
        margin-right: 8rpx;
      }

      .item-title {
        width: 180rpx;
        font-size: 24rpx;
        font-weight: 400;
        color: #666666;
      }

      .status-text {
        font-size: 24rpx;
        font-weight: 500;
      }

      .time {
        font-size: 24rpx;
        font-weight: 400;
        color: #c0c0c0;
      }
    }
  }
  .warning-color {
    color: #faad14;
  }
  .danger-color {
    color: #ff4d4f;
  }
  .success-color {
    color: #67c23a;
  }
</style>
