<template>
	<view class="content">
		<scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadData">
			<!-- 空白页 -->
			<empty v-if="navList[0].loaded === true && navList[0].orderList.length === 0"></empty>
			<!-- 订单列表 -->
			<view class="momBox" v-for="(list, index) in navList[0].orderList" :key="index">
				<view class="topMon">
					<view>
						<text class="mon">{{list.time}}</text>
						<!-- <text class="font-size-sm margin-l-10">月</text> -->
						<image class="iconRight margin-l-10" src="../../../static/icon/dom.png" mode="widthFix"></image>
					</view>
					<!-- <view class="textSm font-color-gray">
						<text>支出：{{list.out}}</text>
						<text class="margin-l-20">支出：{{list.get}}</text>
					</view> -->
				</view>
				<view v-for="(item,index) in list.list" class="order-item flex">
					<view class="title-box">
						<view class="title">
							<text>{{ item.title }}</text>
						</view>
						<view class="time">
							<text>{{ item.add_time }}</text>
						</view>
					</view>
					<view class="money">
						<text>{{ (item.pm == 0 ? '-' : '+') + item.number }}</text>
					</view>
				</view>
			</view>
			<uni-load-more :status="navList[0].loadingType"></uni-load-more>
		</scroll-view>
	</view>
</template>

<script>
	import {
		spreadCommission,
	} from '@/api/wallet.js';
	export default {
		data() {
			return {
				// 头部图高度
				maxheight: '',
				tabCurrentIndex: 0,
				navList: [{
					state: 0,
					text: '全部',
					loadingType: 'more',
					orderList: [],
					page: 1, //当前页数
					limit: 10 //每次信息条数
				}, ],
				money: ''
			};
		},
		onLoad(options) {
			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);
							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);
					});
			}
		}
	};
</script>

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

	.money-box {
		padding-top: var(--status-bar-height);
		text-align: center;
		color: $font-color-dark;
		font-weight: bold;

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

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


	// 列表
	.order-item {
		padding: 20rpx 30rpx;
		line-height: 1.5;
		border-bottom: 1px solid $page-color-light;
		margin-left: 20rpx;
		.title-box {
			.title {
				font-size: $font-lg;
				color: $font-color-base;
			}
			.time {
				font-size: $font-base;
				color: $font-color-light;
			}
		}
		.money {
			font-size: $font-lg;
		}
	}

	.list-scroll-content {
		height: 100%;
		padding-top: 30rpx;
		.momBox{
			background-color: #FFFFFF;
			margin: $page-row-spacing;
			margin-top: 0rpx;
			border-radius: 20rpx;
			overflow: hidden;
			.topMon{
				padding: 30rpx 20rpx;
				border-bottom: 1px solid $page-color-light;
				.iconRight{
					width: 22rpx;
				}
				.mon{
					font-size: 36rpx;
					font-weight: 400;
				}
				.textSm{
					color: $font-color-light;
					font-size: 22rpx;
				}
			}
		}
	}

	.content {
		height: 100%;
	}
</style>
