<template>
	<view class="content">
		<view class="title-box">
			<view class="yue-box">
				<view class="yue-top">
					我的余额(元)
				</view>
				<view class="yue-bottom">
					{{money || 0}}
				</view>
			</view>
			<view class="box">
				<view class="cz" @click="navTo('/pages/money/recharge')">
					充值
				</view>
				<view class="cz" @click="navTo('/pages/money/withdrawal')">
					提现
				</view>
			</view>
		</view>
		<view class="center-box">
			<view class="centet-left">
				<view class="top">
					{{userInfo.recharge || 0}}
				</view>
				<view class="bottom">
					历史充值(元)
				</view>
			</view>
			<view class="" style="width: 2rpx;height: 54rpx;background: #EEEEEE;"></view>
			<view class="centet-left">
				<view class="top">
					{{userInfo.extraxt|| 0}}
				</view>
				<view class="bottom">
					历史提现(元)
				</view>
			</view>
		</view>
		<scroll-view class="good-content" scroll-y @scrolltolower="loadData" :style="{'height': height}">
			<!-- 空白页 -->
			<!-- <empty v-if="tabItem.loaded === true && tabItem.orderList.length === 0"></empty> -->
		
			<!-- 订单列表 -->
			<view class="detail" v-for="item in orderList">
				<view class="det-left">
					<view class="det-top">
						{{ item.title }}
					</view>
					<view class="det-bottom">
						{{ item.add_time }}
					</view>
				</view>
				<view class="det-right">
					{{ (item.pm == 0 ? '-' : '+') + item.number }}
				</view>
			</view>
			<uni-load-more :status="loadingType"></uni-load-more>
		</scroll-view>
	</view>
</template>

<script>
	import { mapState, mapMutations } from 'vuex';
	import {
		getUserInfo
	} from '@/api/user.js';
	import {
		spreadCommission,
		userBalance
	} from '@/api/wallet.js';
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import empty from '@/components/empty';
	export default {
		components: {
			empty,
			uniLoadMore
		},
		data() {
			return {
				tabCurrentIndex: 0,
				height: '',
				state: 0,
				loadingType: 'more',
				orderList: [],
				page: 1, //当前页数
				limit: 10 ,//每次信息条数
				money: '',
				cz: '',//历史充值
				tx: '',//历史提现
			};

		},
		onReady(res) {
			var obj = this;
			uni.getSystemInfo({
				success: resu => {
					const query = uni.createSelectorQuery();
					query.select('.good-content').boundingClientRect();
					query.exec(function(res) {
						obj.height = resu.windowHeight - res[0].top + 'px';
						console.log(obj.height)
					});
				},
				fail: res => {}
			});
		},
		onLoad() {
			this.loadData()
			this.getUserInfo()
		},
		methods: {
			...mapState('user', ['hasLogin', 'userInfo']),
			getUserInfo() {
				getUserInfo().then(res => {
					this.money = res.data.now_money*1
				})
			},
			navTo(url) {
				uni.navigateTo({
					url
				})
			},
			//获取收入支出信息
			async loadData(source) {
				let obj = this

				if (obj.loadingType === 'loading' || obj.loadingType === 'noMore') {
					//防止重复加载
					return;
				}
				// 修改当前对象状态为加载中
				obj.loadingType = 'loading';

				spreadCommission({
							page: obj.page,
							limit: obj.limit
						},
						obj.state
					)
					.then(({
						data
					}) => {
						if (data.length > 0) {
							obj.orderList = obj.orderList.concat(data[0].list);
							console.log(obj.orderList);
							obj.page++;
						}
						if (obj.limit == data.length) {
							//判断是否还有数据， 有改为 more， 没有改为noMore
							obj.loadingType = 'more';
							return;
						} else {
							//判断是否还有数据， 有改为 more， 没有改为noMore
							obj.loadingType = 'noMore';
						}
						uni.hideLoading();
						this.$set(obj, 'loaded', true);
					})
					.catch(e => {
						console.log(e);
					});
			},
			//swiper 切换
			changeTab(e) {
				this.tabCurrentIndex = e.target.current;
				this.loadData('tabChange');
			},
			//顶部tab点击
			tabClick(index) {
				this.tabCurrentIndex = index;
			}
		}
	}
</script>

<style lang="scss">
	page,
	.content {
		height: 100%;
		width: 750rpx;
		background: #111111;

		.title-box {
			padding-left: 30rpx;
			// margin-top: 100rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.yue-box {
				display: flex;
				flex-direction: column;

				.yue-top {
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #999999;
				}

				.yue-bottom {
					font-size: 60rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #A581FF;
				}
			}

			.box {

				.cz {
					margin: 20rpx 0;
					text-align: center;
					font-size: 30rpx;
					font-weight: bold;
					color: #FFFFFF;
					width: 140rpx;
					height: 64rpx;
					border: 2rpx solid #FFFFFF;
					border-radius: 32rpx 0px 0px 32rpx;
					line-height: 64rpx;
				}
			}
		}

		.center-box {
			display: flex;
			justify-content: space-around;
			align-items: center;
			margin: 30rpx 25rpx;
			height: 120rpx;
			background: #181818;
			border-radius: 10rpx;

			.centet-left {
				display: flex;
				flex-direction: column;
				align-items: center;
			}

			.top {
				font-size: 32rpx;
				font-weight: 400;
				color: #FFFFFF;
				line-height: 48rpx;
			}

			.bottom {
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #666666;
				line-height: 48rpx;
			}
		}
	}

	.detail {
		display: flex;
		height: 120rpx;
		justify-content: space-between;
		align-items: center;
		border-bottom: 1rpx solid #F0F0F0;
		margin: 0 25rpx;

		.det-left {
			display: flex;
			flex-direction: column;

			.det-top {
				line-height: 40rpx;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
			}

			.det-bottom {
				line-height: 40rpx;
				font-size: 22rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #999999;
			}
		}

		.det-right {
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #A581FF;
		}
	}

	.navbar {
		display: flex;
		height: 40px;
		padding: 0 5px;
		background: #fff;
		box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
		position: relative;
		z-index: 10;

		.nav-item {
			flex: 1;
			display: flex;
			justify-content: center;
			align-items: center;
			height: 100%;
			font-size: 15px;
			color: $font-color-dark;
			position: relative;

			&.current {
				color: $base-color;

				&:after {
					content: '';
					position: absolute;
					left: 50%;
					bottom: 0;
					transform: translateX(-50%);
					width: 44px;
					height: 0;
					border-bottom: 2px solid $base-color;
				}
			}
		}
	}
</style>
