<template>
	<view class="content">
		<view class="content-money flex">
			<view class="money-box">
				<view class="margin-b-20">{{$t('money.a2')}}</view>
				<view class="money">{{userWallet}}</view>
			</view>
			<!-- 数据代办 -->
			<view class="box">
				<view class="moneybtn-box">
					<view class="money-btn"></view>
					<view class="money-btn" @click="navto('/pages/user/money/recharge')">{{$t('money.a3')}}</view>
				</view>
				<view class="moneybtn-box margin-t-10">
					<view class="money-btn"></view>
					<view class="money-btn" @click="navto('/pages/user/money/withdrawal')">{{$t('money.a4')}}</view>
				</view>
			</view>
		</view>

		<view class="info-box flex">
			<view class="info-item">
				<view class="info-font">{{$t('money.a7')}}</view>
				<view class="info-num">{{userInfo.brokerage || '0'}}</view>
			</view>
			<view class="shu"></view>
			<view class="info-item">
				<view class="info-font">{{$t('money.a8')}}</view>
				<view class="info-num">{{userInfo.extract || '0'}}</view>
			</view>
		</view>

		<scroll-view :style="{height:height}" scroll-y="true" class="padding-b-20 padding-c-30 list-scroll-content"
			@scrolltolower="loadData">
			<!-- 订单列表 -->
			<view class="list flex padding-v-30" v-for="(item, index) in list" :key="index">
				<view>
					<view class="tit padding-b-20">{{item.title}}</view>
					<view class="tim">{{item.add_time}}</view>
				</view>
				<view class="boxT">
					<text v-if="item.pm==1">+</text>
					<text v-if="item.pm==0">-</text>
					<text class="mon">{{item.number}}</text>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		getMoneyLog
	} from "@/api/wallet.js"
	import {
		gameWallet,
	} from "@/api/game.js";
	import {
		getUserInfo,
	} from '@/api/user.js';
	import {
		getMoneyStyle
	} from '@/utils/rocessor.js';
	import empty from '@/components/empty';
	export default {
		filters: {
			getMoneyStyle
		},
		components: {
			empty,
		},
		data() {
			return {
				userInfo: {},
				userWallet: '', //余额
				height: '',
				loaded: false,
				list: [],
				money: '',
				page: 1,
				limit: 10,
				loadingType: 'more',
			};
		},
		onLoad(options) {},
		onReady(res) {
			var _this = this;
			uni.getSystemInfo({
				success: resu => {
					const query = uni.createSelectorQuery();
					query.select('.list-scroll-content').boundingClientRect();
					query.exec(function(res) {
						console.log(res[0].top);
						console.log(resu.windowHeight);
						_this.height = resu.windowHeight - res[0].top + 'px';
					});
				},
				fail: res => {}
			});
		},
		onShow() {
			this.getUserInfo();
			this.loadData();
			this.getUserWallet();
		},
		methods: {
			// 获取用户余额信息
			getUserWallet() {
				gameWallet().then((res) => {
					this.userWallet = +res.data.back.USDT.money.money
				})
			},
			getUserInfo() {
				getUserInfo({}).then(({
					data
				}) => {
					this.userInfo = data
				});
			},
			toBack() {
				uni.switchTab({
					url: '/pages/index/user'
				});
			},
			// 页面跳转
			navto(e) {
				uni.navigateTo({
					url: e
				});
			},

			//获取收入支出信息
			async loadData(source) {
				let navItem = this;
				if (navItem.loaded === true || navItem.loadingType === 'loading') {
					//tab切换只有第一次需要加载数据
					return;
				}
				// 修改当前对象状态为加载中
				navItem.loadingType = 'loading';
				getMoneyLog({
						page: navItem.page,
						limit: navItem.limit
					})
					.then(({
						data
					}) => {

						navItem.list = navItem.list.concat(data.list);
						navItem.page++;
						//判断是否还有数据, 有改为more, 没有改为noMore
						if (navItem.limit == data.list.length) {
							navItem.loadingType = 'more';
							return;
						} else {
							navItem.loadingType = 'noMore';
						}
						uni.hideLoading();
						this.$set(navItem, 'loaded', true);
					})
					.catch(e => {
						console.log(e);
					});
			},
		}
	};
</script>

<style lang="scss">
	.content {
		line-height: 1;
	}

	.content-money {
		position: relative;
		padding: 60rpx 30rpx;
		height: 250rpx;
		.box {
			position: absolute;
			right: 0;
			top: 50rpx;
			font-size: 30rpx;
			font-weight: bold;
			color: #ffffff;

			.moneybtn-box {
				padding: 14rpx 40rpx;
				border: 2px solid #FFFFFF;
				border-bottom-left-radius: 100rpx;
				border-top-left-radius: 100rpx;
				border-right: none;
			}
		}

		.money-box {
			position: relative;
			z-index: 2;
			color: #ffffff;
			text-align: left;

			.money {
				font-weight: bold;
				font-size: 72rpx;
				color: #fdb242;
			}
		}
	}

	.info-box {
		background: #1d1d22;
		border-radius: 20rpx;
		margin: 0 30rpx;
		padding: 30rpx;

		.info-item {
			width: 50%;
			display: flex;
			flex-direction: column;
			align-items: center;
			line-height: 1;

			.info-font {
				font-size: 30rpx;
				font-family: PingFang SC;
				font-weight: bold;
				text-align: center;
				color: #e2e2e2;
			}

			.info-num {
				margin-top: 30rpx;
				font-size: 30rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #ffffff;
			}
		}

		.shu {
			width: 2rpx;
			height: 74rpx;
			background: #ffffff;
		}
	}





	.content {
		height: 100%;

		.empty-content {
			background-color: #ffffff;
		}

	}

	// border-bottom: 1px solid #ffffff;

	.list {
		border-bottom: 1px solid $font-color-light;
		.tit {
			font-size: $font-base;
			font-weight: 500;
			color: #FFFFFF;
		}

		.tim {
			font-size: 22rpx;
			font-weight: 400;
			color: #999999;
		}

		.boxT {
			font-weight: bold;
			font-size: 30rpx;
			color: #FDB242;
		}
	}
</style>