<template>
	<view class="all">
		<view class="top padding-v-30 padding-c-30">
			<view class="zhiya padding-b-10"> {{ $t("myple.u1") }} </view>
			<view class="zhiyashu">
				<text class="shu">{{money|getMoneyStyle}}</text>
				<text class="wen padding-l-10">USDT</text>
			</view>
		</view>
		<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>
		<swiper :current="tabCurrentIndex" :style="{ height: height }" class="swiper-box" duration="300"
			@change="changeTab">
			<swiper-item class="tab-content" v-for="(tabItem, tabIndex) in navList" :key="tabIndex">
				<scroll-view scroll-y="true" class="list-scroll-content" @scrolltolower="loadData">
					<!-- 空白页 -->
					<empty v-if="
							tabItem.loaded === true &&
							tabItem.orderList.length === 0
						"></empty>
					<!-- 订单列表 -->
					<view>
						<!-- <view class="order-item flex" > -->
						<view class="order-item">
							<view class="title-box">
								<view class="title">
									<text>{{ $t("myple.u4") }}</text>
								</view>
								<view class="title">
									<text>{{ $t("myple.u5") }}</text>
								</view>
								<view class="title">
									<text>{{ $t("myple.u6") }}</text>
								</view>
								<view class="title">
									<text>{{ $t("myple.u7") }}</text>
								</view>
								<view class="title">
									<text>{{ $t("myple.u8") }}</text>
								</view>
							</view>
							<view class="heng"></view>
							<view class="all-list" v-for="(item,ind) in navList[tabCurrentIndex].orderList" :key="ind">
								<view class="list">
									<view class="list-item">
										<view class="item"> 100 </view>
										<view class="item"> USDT </view>
									</view>
									<view class="list-item">
										<view class="item"> 100 </view>
										<view class="item"> USDT </view>
									</view>
									<view class="list-item">
										<view class="item" style="margin-top: 18rpx">
											7天
										</view>
									</view>
									<view class="list-item">
										<view class="l-item"> 2023.12.02 </view>
										<view class="l-item" style="margin-top: 20rpx">
											12:00:00
										</view>
									</view>
									<view class="list-item">
										<view class="l-item"> 2023.12.02 </view>
										<view class="l-item" style="margin-top: 20rpx">
											12:00:00
										</view>
									</view>
								</view>
								<view class="heng"></view>
							</view>
							<!-- <view class="money">
								<view>{{ (item.pm == 0 ? '-' : '+') + item.number * 1 }}</view>
							</view> -->
						</view>
					</view>
				</scroll-view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	import {
		getUserInfo
	} from "@/api/user.js";
	import {
		getLock
	} from "@/api/mypledge.js";
	import empty from "@/components/empty";
	import {
		getTime
	} from '@/utils/rocessor.js';
	import { getMoneyStyle } from "@/utils/rocessor.js";
	export default {
		filters: {
			getMoneyStyle,
		},
		components: {
			empty,
		},
		onReady(res) {
			var _this = this;
			uni.getSystemInfo({
				success: resu => {
					const query = uni.createSelectorQuery();
					query.select('.swiper-box').boundingClientRect();
					query.exec(function(res) {
						console.log(resu);
						_this.height = resu.windowHeight - res[0].top + 'px';
						console.log('打印页面的剩余高度', _this.height);
					});
				},
				fail: res => {}
			});
		},
		data() {
			return {
				userInfo: {},
				height: "",
				tabCurrentIndex: 0,
				navList: [{
						state: 1,
						text: "进行中",
						loadingType: "more",
						orderList: [],
						page: 1, //当前页数
						limit: 10, //每次信息条数
						loaded: false
					},
					{
						state: 2,
						text: "已结束",
						loadingType: "more",
						orderList: [],
						page: 1, //当前页数
						limit: 10, //每次信息条数
						loaded: false
					},
				],
				money: "",
			};
		},
		onLoad(options) {
			uni.setNavigationBarTitle({
				title: this.$t("tab.a1"),

			});
			uni.setNavigationBarColor({
				frontColor: '#ffffff',
				backgroundColor: '#000000',
			})
		},
		onShow() {
			this.getUserInfo();
			this.loadData();
		},
		methods: {
			getTime,
			getUserInfo() {
				getUserInfo({}).then(({
					data
				}) => {
					this.userInfo = data;
				});
			},
			toBack() {
				uni.switchTab({
					url: "/pages/pledge/pledge",
				});
			},
			// 页面跳转
			navto(e) {
				uni.navigateTo({
					url: e,
				});
			},
			//获取收入支出信息
			async loadData(source) {
				const that = this;
				//这里是将订单挂载到tab列表下
				let index = that.tabCurrentIndex;
				let navItem = that.navList[index];
				let state = navItem.state;
				if (source === 'tabChange' && navItem.loaded === true) {
					//tab切换只有第一次需要加载数据
					return;
				}
				if (navItem.loadingType === 'loading') {
					//防止重复加载
					return;
				}
				if (navItem.loadingType === 'noMore') {
					//防止重复加载
					return;
				}
				// 修改当前对象状态为加载中
				navItem.loadingType = 'loading';

				getLock({
						status: state,
						page: navItem.page,
						limit: navItem.limit
					})
					.then(({
						data
					}) => {
						// 保存我的总金额
						that.money = data.sum;
						
						let arr = data.list.map(e => {
							return e;
						});
						navItem.orderList = navItem.orderList.concat(arr);
						if (navItem.limit == data.length) {
							navItem.page++;
							//判断是否还有数据， 有改为 more， 没有改为noMore
							navItem.loadingType = 'more';
							return;
						} else {
							//判断是否还有数据， 有改为 more， 没有改为noMore
							navItem.loadingType = 'noMore';
						}
						uni.hideLoading();
						that.$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">
	.all {
		width: 750rpx;
		background-color: $page-color-base;
	}

	.top {
		margin: 0 30rpx;
		height: 138rpx;
		background-color: #191a1f;
		font-weight: bold;
		color: #ffffff;
		border-radius:20rpx ;

		.zhiya {
			font-size: $font-sm;
			color: #757c8f;
		}

		.zhiyashu {
			.shu {
				font-size: $font-lg;
			}

			.wen {
				font-size: $font-base;
			}
		}
	}





	.body {
		background-color: #191a1f;
		margin-left: 30rpx;
		margin-top: 20rpx;
		width: 690rpx;
		height: 137rpx;
	}

	.navbar {
		margin-top: 20rpx;
		display: flex;
		height: 88rpx;
		padding: 0 5px;
		background: #191a1f;
		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: #999999;
			position: relative;

			&.current {
				color: #fff;

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

	// 列表样式
	.order-item {
		background: #191a1f;
	}

	.title-box {
		margin-left: 38rpx;
		display: flex;
		justify-content: space-between;
		width: 690rpx;
	}

	.title {
		flex: 1;
		margin-top: 30rpx;
		width: 43rpx;
		height: 50rpx;
		font-size: 22rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #ffffff;
		line-height: 28rpx;
		opacity: 0.53;
	}

	.list {
		margin-top: 40rpx;
		margin-left: 38rpx;
		display: flex;
		justify-content: space-between;
		width: 690rpx;
	}

	.item {
		height: 40rpx;
		font-size: 22rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #ffffff;
		line-height: 23rpx;
	}

	.l-item {
		height: 15rpx;
		font-size: 18rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #ffffff;
	}

	.heng {
		margin-top: 30rpx;
		width: 750rpx;
		height: 2rpx;
		background: #e9e9e9;
	}

	.btn-box {
		width: 674rpx;
		height: 88rpx;
		background: linear-gradient(0deg, #2e58ff, #32c6ff);
		border-radius: 44rpx;
		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #ffffff;
		text-align: center;
		line-height: 88rpx;
		position: fixed;
		bottom: 48rpx;
		left: 0;
		right: 0;
		margin: 0 auto;
	}
</style>