<route lang="json5" type="page">
{
  layout: 'default',
  needLogin: true,
  style: {
    navigationBarTitleText: '%wallet.withdrawRecord.title%',
    navigationBarBackgroundColor: '#fff',
  },
}
</route>

<script lang="ts" setup>
// 必须导入需要用到的页面生命周期（即使在当前页面上没有直接使用到）
// eslint-disable-next-line unused-imports/no-unused-imports
import { onPageScroll, onReachBottom } from '@dcloudio/uni-app'
import useZPaging from 'z-paging/components/z-paging/js/hooks/useZPaging.js'
import { getEnum as _getEnum } from '@/api/common'
import { withdrawRecordList } from '@/api/wallet'
import { formatNumber } from '@/utils'

defineOptions({
  name: 'WithdrawRecord', // 充值记录
})
// z-paging
const paging = ref(null)
// 类似mixins，如果是页面滚动务必要写这一行，并传入当前ref绑定的paging，注意此处是paging，而非paging.value
useZPaging(paging)
const queryParams = ref<any>({})
const statusEnum = ref<any[]>([])
// 搜索结果
const dataList = ref([])
async function getEnum() {
  const res = await _getEnum({ id: 3 })
  statusEnum.value = res.data
}
async function queryList(pageNo: number, pageSize: number) {
  try {
    const res = await withdrawRecordList({
      page: pageNo,
      size: pageSize,
      accountType: queryParams.value.type,
    })
    console.log(res)
    paging.value.complete(res.data.list)
  }
  catch {
    paging.value.complete(false)
  }
}
onLoad((options) => {
  queryParams.value = options
  getEnum()
})
</script>

<template>
  <z-paging ref="paging" v-model="dataList" use-page-scroll @query="queryList">
    <view class="py-20rpx">
      <view v-for="item in dataList" :key="item.id" class="bg-white px-22rpx py-18rpx">
        <view class="mb-8rpx flex items-center justify-between">
          <view>ID:{{ item.orderNo }}</view>
          <wd-text :type="item.status === 4 ? 'success' : 'primary'" bold :text="statusEnum.find(i => i.code === item.status)?.name" />
        </view>
        <view class="flex items-center justify-between text-22rpx text-#3A444C">
          <view>{{ $t('orderDetail.walletAmountText') }}：-{{ formatNumber(item.amount) }}</view>
        </view>
        <view class="flex items-center justify-between text-22rpx text-#3A444C">
          <view>{{ $t('orderDetail.walletFeeText') }}：-{{ formatNumber(item.fee) }}</view>
          <view>{{ item.createTime }}</view>
        </view>
      </view>
    </view>
  </z-paging>
</template>

<style lang="scss" scoped>
//
</style>
