<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('transfer.titleRecord')"></h-dark>
		<view class="mx-[30rpx] mt-[20rpx]">
			<view v-for="item in dataList" :key="item.id"
				class="bg-[#2C326B] mb-[20rpx] rounded-lg px-[40rpx] py-[35rpx]">
				<view class="flex justify-between mb-[20rpx] pb-[20rpx]">
					<view class="">{{item.create_time}}</view>
					<view v-if="item.type==1" class="text-success">
						{{tips.in}}
					</view>
					<view v-if="item.type==2" class="text-error">
						{{tips.out}}
					</view>
				</view>
				<view class="">
					<view class="flex justify-between mb-[20rpx]">
						<view class="text-[#00D2E0]">
							{{t('transfer.fromUser')}}
						</view>
						<view class="">
							{{item.users_info.user_from}}
						</view>
					</view>
				</view>
				<view class="">
					<view class="flex justify-between mb-[20rpx]">
						<view class="text-[#00D2E0]">
							{{t('transfer.toUser')}}
						</view>
						<view class="">
							{{item.users_info.user_to}}
						</view>
					</view>
				</view>
				<view class="">
					<view class="flex justify-between">
						<view class="text-[#00D2E0]">
							{{t('transfer.money')}}
						</view>
						<view class="font-bold">
							<view v-if="item.type==1" class="text-success">
								+{{item.amount}}
							</view>
							<view v-if="item.type==2" class="text-error">
								-{{item.amount}}
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</z-paging>
</template>

<script lang="ts" setup>
	import { ref, reactive, shallowRef } from 'vue'
	import { transferRecordLists } from '@/api/finance'
	import { getCurrency,getCurrency2, formatMoney } from '@/utils/util'
	import { t } from '@/utils/util'
	uni.setNavigationBarTitle({ title: t('transfer.titleRecord') })

	//为了提高渲染速度
	const tips = reactive({
		in: t('tabs.in'),
		out: t('tabs.out'),
	})
	const paging = shallowRef()
	const dataList = ref<any[]>([])

	const queryList = async (pageNo : number, pageSize : number) => {
		try {
			const data = await transferRecordLists({
				page_no: pageNo,
				page_size: pageSize,
			})
			Object.keys(data.lists).forEach(key => {
				data.lists[key]['amount'] = getCurrency() + formatMoney(data.lists[key]['amount']) + ' ' +  getCurrency2()
			})
			paging.value.complete(data.lists)
		} catch (error) {
			paging.value.complete(false)
		}
	}
</script>

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