<template>
	<view class="content">
		<!-- #ifndef MP -->
		<view class="revert flex-upDown-center">
			<view class="revert-1" @click="switchTab('/pages/user/user')">
				<image src="../../static/img/img03.png"></image>
			</view>
			<view class="revert-2">余额</view>
		</view>
		<!-- #endif -->
		
		<view class="content-money">
			<view class="money-box">
				<view class="money flex1" @click="navto('/pages/award/balancedetails')">
					<text>总金额(元)</text>
					<text >余额明细</text>
				</view>
				<view class="text" style="text-align: center;">￥{{money}}</view>
			</view>
		</view>
		<view class="buttom-box flex">
			<view class="buttom">
				<view class="money">￥{{brokerage_recharge}}</view>
				<text class="text">佣金转入（元）</text>
			</view>
			<view class="interval"></view>
			<!-- <view class="buttom">
				<view class="money">￥{{ recharge | getMoneyStyle }}</view>
				<text class="text">充值金额</text>
			</view> -->
		</view>
		<view class="button">
			<!-- <view class="button1" @click="navto('/pages/wallet/recharge')">充值</view> -->
		</view>
	</view>
</template>

<script>
	import {
		spreadCommission,
		userBalance
	} from '@/api/wallet.js';
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import {
		getMoneyStyle
	} from '@/utils/rocessor.js';
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import empty from '@/components/empty';
	export default {
		filters: {
			getMoneyStyle
		},
		components: {
			empty,
			uniLoadMore
		},
		onReady() {
			// 初始化获取页面宽度
			uni.createSelectorQuery()
				.select('.content')
				.fields({
						size: true
					},
					data => {
						// 保存头部高度
						this.maxheight = data.height - Math.floor((data.width / 750) * 570);
					}
				)
				.exec();
		},
		data() {
			return {
				// 头部图高度
				brokerage_recharge:0,
				maxheight: '',
				tabCurrentIndex: 0,
				navList: [{
						state: 1,
						text: '支出',
						loadingType: 'more',
						orderList: [],
						page: 1, //当前页数
						limit: 10 //每次信息条数
					},
					{
						state: 2,
						text: '收入',
						loadingType: 'more',
						orderList: [],
						page: 1, //当前页数
						limit: 10 //每次信息条数
					}
				],
				money: '', // 总余额
				recharge: '', // 充值金额
				orderStatusSum: '', // 累计消费
			};
		},
		onLoad(options) {},
		onShow() {
			this.loadData();
			// 获取用户余额
			userBalance({}).then(({
				data
			}) => {
				this.money = data.now_money;
				this.brokerage_recharge = data.brokerage_recharge;
				this.recharge = data.recharge;
				this.orderStatusSum = data.orderStatusSum;
			});
		},
		methods: {
			// 页面跳转
			switchTab(e) {
				uni.switchTab({
					url: e
				});
			},
			navto(e) {
				uni.navigateTo({
					url: e
				});
			},
			//获取收入支出信息
			async loadData(source) {
				//这里是将订单挂载到tab列表下
				let index = this.tabCurrentIndex;
				let navItem = this.navList[index];
				let state = navItem.state;
				if (source === 'tabChange' && navItem.loaded === true) {
					//tab切换只有第一次需要加载数据
					return;
				}
				if (navItem.loadingType === 'loading') {
					//防止重复加载
					return;
				}
				// 修改当前对象状态为加载中
				navItem.loadingType = 'loading';
				spreadCommission({
							page: navItem.page,
							limit: navItem.limit
						},
						state
					)
					.then(({
						data
					}) => {
						if (data.length > 0) {
							navItem.orderList = navItem.orderList.concat(data);
							console.log(navItem.orderList);
							navItem.page++;
						}
						if (navItem.limit == data.length) {
							//判断是否还有数据， 有改为 more， 没有改为noMore
							navItem.loadingType = 'more';
							return;
						} else {
							//判断是否还有数据， 有改为 more， 没有改为noMore
							navItem.loadingType = 'noMore';
						}
						uni.hideLoading();
						this.$set(navItem, '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 {
		background: #ffffff;
		height: 100%;
	}

	.revert {
		z-index: 10;
		width: 100%;
		position: absolute;
		top: 20rpx;
		padding: 0 30rpx;

		.revert-1 {
			width: 20rpx;
			height: 35rpx;

			image {
				width: 20rpx;
				height: 35rpx;
			}
		}

		.revert-2 {
			text-align: center;
			width: calc(100% - 20rpx);
			font-size: 32rpx;
			font-weight: 500;
			color: #ffffff;
		}
	}

	.content-money {
		background: $page-color-base;

		// border: 2px solid #ffffff;
		.moneyTx {
			position: absolute;
			top: 150rpx;
			right: 0rpx;
			width: 150rpx;
			padding: 10rpx 30rpx;
			border: 2px solid #ffffff;
			border-top-left-radius: 99rpx;
			border-bottom-left-radius: 99rpx;
			color: #ffffff;
			line-height: 1;
			font-size: $font-base;
		}

		.buttom-box {
			background-color: #ffffff;
			text-align: center;
			margin: 0 30rpx;
			padding: 20rpx 0;
			border-radius: $border-radius-sm;
			margin-top: -60rpx;

			.buttom {
				font-size: $font-lg;
				flex-grow: 1;
			}

			.interval {
				width: 2px;
				height: 60rpx;
				background-color: #eeeeee;
			}

			.icon {
				height: 50rpx;
				width: 48rpx;
				margin: 0 auto;

				.icon-img {
					width: 100%;
					height: 100%;
				}
			}
		}
	}

	.buttom-box {
		background-color: #ffffff;
		text-align: center;
		margin: 0 30rpx;
		padding: 30rpx 0;
		border-radius: $border-radius-sm;
		box-shadow: 0px 0px 20px 0px rgba(50, 50, 52, 0.06);
		margin-top: -60rpx;
		position: relative;

		.buttom {
			font-size: $font-lg;
			flex-grow: 1;

			.money {
				font-weight: bold;
				font-size: 32rpx;
				color: #DB1935;
			}
		}

		.text {
			color: #666666;
		}

		.interval {
			width: 2rpx;
			height: 60rpx;
			background-color: #eeeeee;
		}

		.icon {
			height: 50rpx;
			width: 48rpx;
			margin: 0 auto;

			.icon-img {
				width: 100%;
				height: 100%;
			}
		}
	}

	.button {
		.button1 {
			width: 480rpx;
			height: 80rpx;
			background: linear-gradient(90deg, rgba(254, 78, 70, 1) 0%, rgba(252, 65, 65, 1) 100%);
			border-radius: 10rpx;
			font-size: 30rpx;
			font-weight: 500;
			color: #ffffff;
			line-height: 80rpx;
			text-align: center;
			margin: 180rpx auto 0;
		}

		.button2 {
			width: 480rpx;
			height: 80rpx;
			background: #F2F2F2;
			border-radius: 10rpx;
			font-size: 30rpx;
			font-weight: 500;
			color: #FC4141;
			line-height: 80rpx;
			text-align: center;
			margin: 30rpx auto 0;
		}
	}

	.money-box {
		background: $base-color;
		padding-top: var(--status-bar-height);
		height: 600rpx;
		color: #ffffff;
		// text-align: center;
		position: relative;

		.text {
			padding-top: 140rpx;
			font-size: 82rpx;
		}

		.money {
			padding: 120rpx 25rpx 0 25rpx;
			font-size: 24rpx;
		}

		.money-accum {
			display: flex;
			align-items: center;
			justify-content: space-around;
			margin-top: 44rpx;

			.money-frame {
				.money-num {
					font-size: 45rpx;
					font-weight: 500;
					color: rgba(255, 255, 255, 1);
				}

				.mon-text {
					font-size: 30rpx;
					font-weight: 500;
					color: rgba(255, 255, 255, 1);
				}
			}
		}

		.money-loca {
			width: 140rpx;
			height: 50rpx;
			background: #FFFFFF;
			color: #FA2740;
			font-size: $font-base;
			line-height: 50rpx;
			border-radius: 10rpx 0 0 10rpx;
		}

		// 立即提现
		.draw {
			position: absolute;
			right: 0;
			top: 64rpx;
		}

		// 余额支付
		.rech {
			position: absolute;
			right: 0;
			top: 134rpx;
		}
	}

	.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: $font-color-spec;

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

	// 列表

	.swiper-box {
		padding-top: 10rpx;

		.order-item {
			padding: 20rpx 30rpx;
			line-height: 1.5;

			.title-box {
				.title {
					font-size: $font-lg;
					color: $font-color-base;
				}

				.time {
					font-size: $font-base;
					color: $font-color-light;
				}
			}

			.money {
				color: #fd5b23;
				font-size: $font-lg;
			}
		}
	}

	.list-scroll-content {
		height: 100%;
	}

	.content {
		height: 100%;

		.empty-content {
			background-color: #ffffff;
		}
	}
</style>
