<route lang="json5" type="page">
{
  layout: 'default',
  needLogin: true,
  style: {
    navigationBarTitleText: '%wallet.rechargeRecord.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 { rechargeRecordList, thirdPayAgree } from '@/api/wallet'
import { t } from '@/locale'
import { formatNumber } from '@/utils'
import { toPage } from '@/utils/page'

defineOptions({
  name: 'RechargeRecord', // 充值记录
})
// z-paging
const paging = ref(null)
// 类似mixins，如果是页面滚动务必要写这一行，并传入当前ref绑定的paging，注意此处是paging，而非paging.value
useZPaging(paging)
// 搜索结果
const statusEnum = ref<any[]>([])
const dataList = ref([])
async function getEnum() {
  const res = await _getEnum({ id: 2 })
  statusEnum.value = res.data
}
async function queryList(pageNo: number, pageSize: number) {
  try {
    const res = await rechargeRecordList({
      page: pageNo,
      size: pageSize,
      accountType: 1,
    })
    console.log(res)
    paging.value.complete(res.data.list)
  }
  catch {
    paging.value.complete(false)
  }
}
async function handleClick(data: any) {
  if (data.status === 1) {
    try {
      const res = await thirdPayAgree(data.id)
      console.log(res)
      if (res.code === '200') {
        toPage({ url: '/pages/webLink/webLink', params: { link: res.data, title: t('wallet.recharge.title') } })
      }
    }
    catch {}
  }
}
onLoad(() => {
  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="mb-16rpx flex items-center justify-between bg-white px-22rpx py-18rpx" @click="handleClick(item)">
        <view class="mr-16rpx flex-1">
          <view class="mb-8rpx flex items-center justify-between">
            <view>ID:{{ item.orderNo }}</view>
            <wd-text :type="item.status === 2 ? '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.walletBalanceText') }}：+{{ formatNumber(item.amount) }}</view>
            <view>{{ item.createTime }}</view>
          </view>
        </view>
        <wd-icon v-if="item.status === 1" custom-class="flex-shrink-0" name="chevron-right" size="48rpx" />
      </view>
    </view>
  </z-paging>
</template>

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