<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="flex buttom-box">
					<view class="buttom" @click="navto('./recharge')">
						<text>充值</text>
					</view>
				</view>
			</view>
		</view>
		<view class="listbox">
			<view class="navbar flex">
				<view class="title">
					卡券变动明细
				</view>
				<view class="alllist" @click="navto('./walletList')">
					全部
				</view>
			</view>
			<view class="conetntList">
				<view class="listItem flex" v-for="(item, tabIndex) in navList[0].orderList">
					<view class="itemLeft">
						<view class="itemTitle">
							{{item.title}}
						</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,
		userBalance
	} from '@/api/wallet.js';
	import {
		getMoneyStyle
	} from '@/utils/rocessor.js';
	export default {
		filters: {
			getMoneyStyle
		},
		data() {
			return {
				// 头部图高度
				maxheight: '',
				tabCurrentIndex: 0, //当前选中的
				navList: [{
					state: 0,
					text: '全部',
					loadingType: 'more',
					orderList: [],
					page: 1, //当前页数
					limit: 10 //每次信息条数
				}, ],
				money: ''
			};
		},
		onLoad(options) {
			this.loadData();
			console.log('进入');
		},
		onShow() {
			// 获取用户余额
			userBalance({}).then(({
				data
			}) => {
				this.money = data.now_money;
			});
		},
		// 页面到底部后加载数据
		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++;
						}
						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);
						this.$set(navItem, 'loaded', true);
					});
			}
		}
	};
</script>

<style lang="scss">
	page {
		height: 100%;
	}

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

		.conetnt-box {
			border-radius: 20rpx;
			background-color: #ffffff;
			height: 400rpx
		}

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

			.buttom {
				flex-grow: 1;
				border-radius: 100rpx;
				font-size: $font-lg;
				width: 300rpx;
				height: 80rpx;
				line-height: 80rpx;
				background-color: $base-color;
				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;
	}

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