<template>
	<z-paging :refresher-enabled="false" :show-loading-more-when-reload="true" loading-more-default-text=""
		loading-more-loading-text="" loading-more-fail-text="" :empty-view-text="t('common.noData')"
		:show-loading-more-no-more-view="false" ref="paging" v-model="dataList" @query="queryList"
		class="max-w-[750px]">
		<h-dark :title="t('user.usedNoMoney')"></h-dark>
		<view class="user-wallet">
			<view class="pt-2.5">
					<view v-for="item in dataList" :key="item.id" class="bg-white mb-[8px] px-[40rpx] py-[20rpx] border-solid border-b border-0 border-light ">
						<view class="flex justify-between items-center">
							<view class="">
								<view class="">
									<view class="">
										{{item.type}}
									</view>
									<view class="text-error mt-[12rpx]" v-if="item.remark">
										{{item.remark}}
									</view>
								</view>
								<view class="flex justify-between mt-[16rpx]">
									<view class=" text-muted mr-1">{{item.create_time}}</view>
								</view>
							</view>
							<view class="text-right">
								<text class="font-bold">
									{{item.amount}}
								</text>
							</view>

						</view>
					</view>
			</view>
		</view>
	</z-paging>
</template>

<script lang="ts" setup>
	import { ref, shallowRef } from 'vue'
	import { financeLists } from '@/api/finance'
	import { getCurrency, formatDate, formatMoney } from '@/utils/util'
	import { t } from '@/utils/util'
	uni.setNavigationBarTitle({ title: t('user.usedNoMoney') })
	const paging = shallowRef()
	const dataList = ref<any[]>([])

	const queryList = async (pageNo : number, pageSize : number) => {
		try {
			const data = await financeLists({
				action: '',
				frozen: 1,
				page_no: pageNo,
				page_size: pageSize,
				date: formatDate(Math.round(Date.now() / 1000))
			})
			Object.keys(data.lists).forEach(key => {
				data.lists[key]['amount'] = getCurrency() + formatMoney(data.lists[key]['amount'])
				data.lists[key]['type'] = t("finance.type" + data.lists[key]['type'])
			})
			paging.value.complete(data.lists)
		} catch (error) {
			paging.value.complete(false)
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #FFFFFF;
	}
</style>