<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('mine.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]">
					<view class="text-[#00D2E0]">
						{{t('mine.recordAmount')}}
					</view>
					<view class="">
						<view class="" v-if="item.rate != 1">
							<view class="mb-[10rpx]">
								{{item.amount_act}} {{item.symbol}}
							</view>
							<view class="text-[#00D2E0]">
								≈ {{item.amount}}
							</view>
						</view>
						<view class="" v-if="item.rate == 1">
							{{item.amount_act}} {{item.symbol}}
						</view>
					</view>
				</view>
				<view class="flex justify-between mb-[20rpx]">
					<view class="text-[#00D2E0]">
						{{t('mine.recordStartTime')}}
					</view>
					<view class="">
						{{item.start_time}}
					</view>
				</view>
				<view class="flex justify-between">
					<view class="text-[#00D2E0]">
						{{t('mine.recordGetTime')}}
					</view>
					<view class="">
						{{item.create_time}}
					</view>
				</view>
			</view>
		</view>
	</z-paging>
</template>

<script lang="ts" setup>
	import { ref, shallowRef } from 'vue'
	import { getMineLists } from '@/api/user'
	import { getCurrency, getCurrency2, formatMoney } from '@/utils/util'
	import { t } from '@/utils/util'

	uni.setNavigationBarTitle({ title: t('mine.titleRecord') })
	const paging = shallowRef()
	const dataList = ref<any[]>([])
	const queryList = async (pageNo : number, pageSize : number) => {
		try {
			const data = await getMineLists({
				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">
</style>