<template>
	<view class="content">
		<view class="bg">
		</view>
		<view class="content-money">
			<view class="conetnt-box">
				<view class="money-box">
					<view class="text">可用佣金（元）</view>
					<view class="money">{{ money | getMoneyStyle }}</view>
				</view>

				<view class="detailBox flex">
					<view class="item">
						<view class="nametype">
							提现中
						</view>
						<view class="moneyNum font-color-red">
							{{addMoney||0}}
						</view>
					</view>
					<view class="item">
						<view class="nametype">
							即将到账
						</view>
						<view class="moneyNum ">
							{{timeMoney||0}}
						</view>
					</view>
					<view class="item">
						<view class="nametype">
							累计收益
						</view>
						<view class="moneyNum ">
							{{allMoney||0}}
						</view>
					</view>
				</view>
				<view class="flex buttom-box">
					<view class="buttom geMoney" @click="navto('./withdrawal')">
						<text>提现</text>
					</view>
				</view>
			</view>
		</view>
		<view class="listbox">
			<view class="navbar flex">
				<view class="title">
					佣金变动明细
				</view>
				<view class="alllist" @click="navto('./awardList')">
					全部
				</view>
			</view>
			<view class="conetntList">
				<view class="listItem flex" v-for="(item, tabIndex) in navList[0].orderList">
					<view class="itemLeft">
						<view class="itemTitle flex">
							<text>{{item.title}}</text>
							<text class="font-size-sm font-color-red" v-if="item.status==0">(未到账)</text>
						</view>
						<view class="itemBottom">
							{{item.add_time}}
						</view>
					</view>
					<view class="itemRight">
						<view class="itemTitle">
							{{(item.pm == 0 ? '-' : '+')+item.number}}
						</view>
						<!-- <view class="itemBottom">
								余额{{item.yue}}
							</view> -->
					</view>
				</view>
				<uni-load-more :status="navList[0].loadingType"></uni-load-more>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		spreadCommission,
		extractBank
	} from '@/api/wallet.js';
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import {
		getMoneyStyle
	} from '@/utils/rocessor.js';
	// import empty from '@/components/empty';
	export default {
		filters: {
			getMoneyStyle
		},
		// components: {
		// 	empty,
		// },
		data() {
			return {
				tabCurrentIndex: 0,
				navList: [{
					state: 3,
					text: '收入',
					loadingType: 'more',
					orderList: [],
					page: 1, //当前页面
					limit: 10 //每次信息条数
				}],
				money: 0, //可提现佣金
				addMoney: 200, //提现中到账
				timeMoney: 200, //即将到账
				allMoney: 1000, //累计收益

			};
		},
		onLoad(options) {
			this.loadData();
		},
		onShow() {
			//获取用户余额
			extractBank({}).then(({
				data
			}) => {
				this.money = data.commissionCount;
				this.addMoney = data.ext_broerage;
				this.timeMoney = data.not_broerage;
				this.allMoney = data.total_brokerage;
			});
		},
		// 页面到底部后加载数据
		onReachBottom() {
			this.loadData();
		},
		methods: {
			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[0].list);
							console.log(navItem.orderList);
							navItem.page++;
						}
						//判断是否还有数据, 有改为more, 没有改为noMore
						if (navItem.limit == data.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">
	page {
		height: 100%;
	}

	.content-money {
		position: relative;
		padding: 20rpx;
		z-index: 1;

		.conetnt-box {
			border-radius: 20rpx;
			background-color: #ffffff;
			padding-bottom: 50rpx;

			// height: 400rpx;
			.detailBox {
				justify-content: space-around;
				padding-top: 30rpx;

				.item {
					text-align: center;
					color: $font-color-light;

					.nametype {
						color: $font-color-disabled;
						font-size: 24rpx;
					}

					.moneyNum {
						margin-top: 20rpx;
						font-size: 28rpx;
						font-weight: bold;
					}
				}
			}
		}

		.buttom-box {
			text-align: center;
			margin: 0 30rpx;
			margin-top: 50rpx;

			.buttom {
				flex-grow: 1;
				border-radius: 100rpx;
				font-size: $font-lg;
				width: 300rpx;
				height: 80rpx;
				line-height: 80rpx;
				background-color: $color-green;
				color: #FFFFFF;

				&.geMoney {
					border: 1px solid $font-color-disabled;
					color: $font-color-disabled;
					background-color: #FFFFFF;
				}
			}
		}
	}

	.money-box {
		text-align: center;
		color: $font-color-dark;
		font-weight: bold;

		.text {
			padding-top: 85rpx;
			font-size: 24rpx;
			margin-bottom: 20rpx;
		}

		.money {
			font-size: 60rpx;
		}
	}

	.listbox {
		margin: 0 20rpx;
		border-radius: 20rpx;
		position: relative;
	}

	.navbar {
		background: #fff;
		padding: 30rpx;
		border-bottom: 1px solid $page-color-light;
		border-top-left-radius: 20rpx;
		border-top-right-radius: 20rpx;

		.title {
			font-size: 32rpx;
			font-weight: bold;
		}

		.alllist {
			font-size: 28rpx;

		}
	}


	.content {
		height: 100%;

		.bg {
			background-color: #f6ab0b;
			width: 950rpx;
			position: absolute;
			left: -100rpx;
			border-bottom-left-radius: 1000rpx;
			border-bottom-right-radius: 1000rpx;
			top: 0rpx;
			height: 300rpx;
		}

	}

	.conetntList {
		padding: 30rpx;
		background-color: #FFFFFF;
		border-bottom-left-radius: 20rpx;
		border-bottom-right-radius: 20rpx;

		.listItem {
			font-size: 30rpx;
			color: $font-color-dark;
			align-items: flex-start;
		}

		.itemBottom {
			font-size: 24rpx;
			color: $font-color-disabled;
		}
	}
</style>
