<template>
	<view class="content">
		<!-- <view class="navbar">
			<view v-for="(item, index) in navList" :key="index" class="nav-item" :class="{ current: tabCurrentIndex === index }" @click="tabClick(index)">{{ item.text }}</view>
		</view> -->
		<view class="header">
			<image src="../../static/user/shopping.png" mode=""></image>
			<view class="integral">
				{{ integral || 0 }}
			</view>
			<!-- <navigator url="/pages/money/conversionIntegral"><view class="right">转换USDT</view></navigator> -->
		</view>
		<view class="navbar ">
			<view class="nav-item" v-for="(item,index) in navList" :key="index"
				:class="{current:tabCurrentIndex===index}" @click="tabClick(index)">{{item.text}}</view>
		</view>
		<swiper class="swiper-box" duration="300" :style="{ height: maxheight }" :current="tabCurrentIndex"
			@change="changeTab">
			<swiper-item class="tab-content" v-for="(item,index) in navList">
				<scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadData">
					<!-- 空白页 -->
					<!-- <empty v-if="tabItem.loaded === true && tabItem.orderList.length === 0"></empty> -->
					<empty v-if="item.loaded ===true && item.orderList.length===0"></empty>

					<!-- 订单列表 -->
					<view v-else class="order-item flex " v-for="orderItem in item.orderList">
						<view class="title-box ">
							<view class="title">
								<text>{{orderItem.mark}}</text>
							</view>
							<view class="time">
								<text>{{orderItem.add_time}}</text>
							</view>
						</view>
						<view class="money">
							<text>{{(orderItem.pm == 0?'-':'+')+orderItem.number}}</text>
						</view>
					</view>
					<!-- <uni-load-more :status="tabItem.loadingType"></uni-load-more> -->
					<uni-load-more :status="item.loadingType"></uni-load-more>
				</scroll-view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	import {
		moneyLog,
		wallet
	} from '@/api/finance.js';
	import { integral } from '@/api/wallet.js';
	//下拉加载
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import empty from '@/components/u-empty/u-empty.vue';
	export default {
		components: {
			uniLoadMore,
			empty
		},
		computed: {
			//积分
			// integral() {
			// 	return this.$store.state.user.userInfo.integral

			// }
			// ...mapState('user',['userInfo'])
		},
		onReady(res) {
			var _this = this;
			uni.getSystemInfo({
				success: resu => {
					const query = uni.createSelectorQuery();
					query.select('.swiper-box').boundingClientRect();
					query.exec(function(res) {
						_this.maxheight = resu.windowHeight - res[0].top + 'px';
						console.log('打印页面的剩余高度', _this.height);
					});
				},
				fail: res => {}
			});
		},
		onLoad() {

			wallet({}).then(({
				data
			}) => {

				const obj = this
				const arr = Object.keys(data.back)
				console.log(data.back, '000');
				arr.forEach(e => {
					if (e == 'USDT') {
						obj.integral = (data.back[e].money.money * 1)
						console.log(obj.integral, '666');
					}
				})
			})
			this.loadData();
		},
		data() {
			return {
				tabCurrentIndex: 0, //判断亮不亮
				integral: 0, //我的积分
				maxheight: '',
				navList: [{
						state: 1,
						text: '收入',
						orderList: [], //里面的数据
						loadingType: 'More', //是否还有更多数据
						limit: 10, //一页10条
						page: 1
					},
					{
						text: '支出',
						state: 0,
						orderList: [],
						limit: 10,
						page: 1,
						loadingType: 'More'

					}
				]
			};
		},
		onShow() {
			this.loadData()
		},
		methods: {
			// 下拉刷新
			async loadData(source) {
				console.log(source, "222");
				// 将订单挂载到tab列表下
				let index = this.tabCurrentIndex
				let item = this.navList[index];
				console.log(item);
				let state = item.state
				if (source === 'tabChange' && item.loaded === true) {
					return
				}
				if (item.loadingType === 'loading') {
					//防止重复加载
					return
				}
				//修改当前数据为加载中
				item.loadingType = 'loading'
				console.log(item.limit, '123456789987654321')
				integral({
					page: item.page,
					limit: item.limit,
					pm: item.state

				}).then(({
					data
				}) => {
					console.log(data, '123456');
					
						item.orderList = item.orderList.concat(data)
						item.page++
					
					//判断是否还有数据，没有就把提示语改成nomore，有就为more
					if (item.limit == data.length) {
						item.loadingType = 'more'
						return
					} else {
						item.loadingType = 'noMore'
					}
					this.$set(item, 'loaded', true)

				}).catch(e => {
					console.log(e)
				})

			},
			//tab点击
			tabClick(index) {
				this.tabCurrentIndex = index
				this.loadData('tabChange')

				console.log(this.tabCurrentIndex)
			},
			changeTab(e) {
				this.tabCurrentIndex = e.target.current
				console.log(this.tabCurrentIndex, '21')
				this.loadData('tabChange')
			}
		},

	};
</script>

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

	.header {
		image {
			width: 100%;
			height: 400rpx;
		}

		.integral {
			width: 100%;
			text-align: center;
			position: absolute;
			top: 160rpx;
			color: #fff;
			font-size: 80rpx;
			font-weight: bold;
		}

		.right {
			position: absolute;
			top: 120rpx;
			right: 0;
			background-color: #fff;
			border-radius: 10rpx 0 0 10rpx;
			color: #438BED;
			padding: 5rpx 15rpx;
			font-size: 28rpx;
		}
	}

	.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: #438BED;

				&:after {
					content: '';
					position: absolute;
					left: 50%;
					bottom: 0;
					transform: translateX(-50%);
					width: 44px;
					height: 0;
					border-bottom: 2px solid #438BED;
				}
			}
		}
	}

	// 列表

	.swiper-box {
		height: calc(100% - 180rpx - 400rpx);
		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: #EF3A55;
				font-size: $font-lg;
			}
		}
	}

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

	.content {
		height: 100%;

		.empty-content {
			background-color: #ffffff;
		}
	}

	.button {
		height: 180rpx;
		width: 100%;
		display: flex;
		position: absolute;
		padding: 40rpx 30rpx 60rpx 30rpx;
		bottom: 0;
		text-align: center;

		.b-left,
		.b-right {
			flex: 1;
			height: 80rpx;
			line-height: 80rpx;
			margin: 0 30rpx;
			border-radius: 50rpx;
		}

		.b-left {
			color: #438BED;
			border: solid 1rpx #438BED;
		}

		.b-right {
			background: linear-gradient(90deg, #438BED 0%, #44BFEC 100%);
			color: #fff;
		}
	}
</style>
