<template>
	<view class="wallet p30">
		<z-paging ref="paging" v-model="dataList" use-page-scroll @query="queryList">
			<view class="wallet_pall">
				<view>
					<view class="wallet_pall_header">
						基础收益
						<!-- <view @click="navTo(`/pages/mine/transferBalance`, true)">收益转入</view> -->
					</view>
					<view class="wallet_pall_ye">
						<view>{{ user.money || '0.00' }}</view>
						<!-- <view style="margin-top: 10rpx" @click="navTo(`/pages/mine/topUp`, true)">充值</view> -->
					</view>
				</view>

				<view>
					<view class="wallet_pall_header">增值收益</view>
					<view class="wallet_pall_ye">
						<view>{{ user.money2 || '0.00' }}</view>
					</view>
				</view>
			</view>
			<view class="mt30" style="padding: 15rpx 30rpx; display: flex; align-items: center; background: #6fa256; border-radius: 0 0 16rpx 16rpx">
				<view @click="navTo(`/pageInvest/money/recharge`, true)" style="width: 330rpx; text-align: center; color: #fff">充值</view>
				<view @click="navTo(`/pageInvest/money/withdraw`, true)" style="width: 330rpx; text-align: center; color: #fff">提现</view>
			</view>
			<view class="mt30">
				<uni-section title="明细" type="line" titleFontSize="32rpx"></uni-section>
			</view>

			<view class="mt30 wallet_list" v-for="(item, index) in dataList" :key="index">
				<view class="wallet_list_left">
					<view>{{ moneyJson.find((val) => val.id == item.type).name }}</view>
					<view>{{ item.created_at }}</view>
				</view>
				<view class="wallet_list_right">{{ item.money }}元</view>
			</view>
		</z-paging>
	</view>
</template>

<script setup>
import { reactive, ref } from 'vue';
import { onPullDownRefresh, onPageScroll, onReachBottom, onLoad, onShow } from '@dcloudio/uni-app';
import { timeFormat } from '@/uni_modules/uview-plus';
import { extractRecordList } from '@/api/api.js';
import moneyJson from '@/common/money.json';

import { userHook } from '@/hooks/userInfo.js';
const { user } = userHook();

import { useNav } from '@/hooks/useNav.js';
const { nav, navTo } = useNav();
let getInfo = ref({});
const paging = ref(null);
let dataList = ref([]);
let num = ref(1);

let isPagingRefNotFound = () => {
	return !paging.value;
};

onShow(async () => {
	if (num.value != 1) {
		paging.value.reload();
	}
	num.value++;
});

onPullDownRefresh(() => {
	if (isPagingRefNotFound()) return;
	paging.value.reload().catch(() => {});
});

onPageScroll((e) => {
	if (isPagingRefNotFound()) return;
	paging.value.updatePageScrollTop(e.scrollTop);
	e.scrollTop < 10 && paging.value.doChatRecordLoadMore();
});

onReachBottom(() => {
	if (isPagingRefNotFound()) return;
	paging.value.pageReachBottom();
});

const queryList = (pageNo, pageSize) => {
	const params = {
		current: pageNo,
		pageSize: pageSize
	};

	extractRecordList(params)
		.then((res) => {
			paging.value.complete(res);
		})
		.catch((res) => {
			paging.value.complete(false);
		});
};
</script>

<style scoped lang="scss">
.wallet_pall {
	background: #6fa256;
	// border-radius: 16rpx 16rpx 16rpx 16rpx;

	height: 272rpx;
	// background: linear-gradient(179deg, #4874e5 0%, #3864d6 100%);
	border-radius: 16rpx 16rpx 0 0;
	padding: 40rpx;
	padding-bottom: 0;
	border-bottom: 1rpx solid rgba(153, 153, 153, 0.6);

	display: flex;
	align-items: center;
	justify-content: space-between;

	&_header {
		font-weight: bold;
		font-size: 26rpx;
		color: #ffffff;
		display: flex;
		align-items: center;
		justify-content: space-between;
		view {
			width: 128rpx;
			height: 58rpx;
			background: #ffffff;
			border-radius: 32rpx 32rpx 32rpx 32rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 26rpx;
			color: #6fa256;
		}
	}
	&_ye {
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 100%;
		view:nth-child(1) {
			font-weight: bold;
			font-size: 68rpx;
			color: #ffffff;
		}
		view:nth-child(2) {
			width: 128rpx;
			height: 58rpx;
			background: #ffffff;
			border-radius: 32rpx 32rpx 32rpx 32rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 26rpx;
			color: #6fa256;
		}
	}
}

.wallet_list {
	width: 690rpx;
	height: 120rpx;
	background: #ffffff;
	border-radius: 8rpx 8rpx 8rpx 8rpx;
	padding: 15rpx 30rpx;
	@include flex($space: space-between);
	&_left {
		view:nth-child(1) {
			font-weight: bold;
			font-size: 28rpx;
			color: #232323;
			margin-bottom: 10rpx;
		}
		view:nth-child(2) {
			font-size: 24rpx;
			color: #232323;
		}
	}
	&_right {
		font-weight: bold;
		font-size: 28rpx;
		color: #ff2727;
	}
}

.mt30 {
	margin-bottom: 30rpx;
}
</style>
