<template>
  <view class="app-container">
    <uv-navbar
      title="提现明细"
      placeholder
      autoBack
      bgColor="#ffffff"
    ></uv-navbar>
    <view class="main-list">
      <view
        class="main-list-item"
        v-for="(item, index) in dataList"
        :key="index"
        @click.stop="handleWithdraw(item)"
      >
        <view class="item-view u-flex-center-sb">
          <text class="time">{{ item.createTime }}</text>
          <text v-if="item.status == 1">待审核</text>
          <text class="status" v-if="item.status == 3">已到账</text>
          <text v-if="item.status == 2">提现失败</text>
        </view>
        <view class="item-view u-flex-center-sb">
          <view class="lable">提现金额：</view>
          <view class="value u-flex-center">
            <text class="num">￥{{ item.amount }}</text>
            <uv-icon name="arrow-right" color="#1a1a1a" size="30rpx"></uv-icon>
          </view>
        </view>
      </view>
    </view>

    <noData v-if="dataList == 0" :config="{ top: 10, content: '暂无数据~' }" />
    <loadMore v-if="dataList.length > 0" :status="status" />
  </view>
</template>

<script setup>
import { ref } from "vue";
import { onLoad, onReachBottom, onPullDownRefresh } from "@dcloudio/uni-app";
import { withdrawalPage_Api } from "@/api/userInfo.js";
import { agentWithdrawalPage_Api } from "@/api/agencyCenter.js";

const pageType = ref("1"); // 1:用户 2:代理商
const params = ref({ pageNum: 1, pageSize: 10 });
const dataList = ref([]);
const status = ref("loading");

const handleWithdraw = (item) => {
  uni.navigateTo({
    url: `/pages/user/wallet/reflectDetails?pageType=${pageType.value}&id=${item.id}`,
  });
};

// 查询提现明细
const getList = () => {
  status.value = "loading";
  uni.showLoading({
    title: "加载中...",
    mask: true,
  });
  let url =
    pageType.value == "1" ? withdrawalPage_Api : agentWithdrawalPage_Api;
  url(params.value)
    .then((res) => {
      uni.hideLoading();
      if (res && res.code == 200) {
        uni.stopPullDownRefresh();
        dataList.value = dataList.value.concat(res.rows);
        if (res.total <= dataList.value.length) {
          status.value = "noMore";
        } else {
          status.value = "more";
        }
      }
    })
    .catch((err) => {
      uni.hideLoading();
    });
};

onLoad((options) => {
  if (options.pageType) {
    pageType.value = options.pageType;
  }
  getList();
});

onReachBottom(() => {
  if (status.value !== "loading" && status.value !== "noMore") {
    params.value.pageNum++;
    getList();
  }
});
onPullDownRefresh(() => {
  params.value.pageNum = 1;
  dataList.value = [];
  getList();
});
</script>

<style lang="scss" scoped>
.app-container {
  padding: 54rpx;
  box-sizing: border-box;
  .main-list {
    .main-list-item {
      padding: 30rpx 0;
      border-bottom: 1rpx solid #f0f0f0;
      .item-view {
        font-size: 26rpx;
        margin-bottom: 10rpx;
        &:last-child {
          margin-bottom: 0;
        }
        .time {
          color: #999999;
        }
        .status {
          color: #00c220;
        }
        .lable {
          font-size: 28rpx;
          font-weight: 700;
          color: #1a1a1a;
        }
        .value {
          .num {
            font-size: 28rpx;
            font-weight: 400;
            color: #da4f4f;
          }
        }
      }
    }
  }
}
</style>
