<template>
	<view class="all">
		<view class="top">
			<view class="zhiya"> {{ $t("myple.u1") }} </view>
			<view class="zhiyashu">
				<p class="shu">241,142,574.25</p>
				<p class="wen">USDT</p>
			</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 in 10"
								:key="item">
								<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>
					<!-- 上拉显示更多 -->
					<!-- <uni-load-more :status="tabItem.loadingType"
						v-if="!(tabItem.orderList.length == 0 && tabItem.loaded)"></uni-load-more> -->
				</scroll-view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	import { mapState, mapMutations } from "vuex";
	import { getCommissionInfo, getUserInfo } from "@/api/user.js";
	import { getLock } from "@/api/mypledge.js";
	import { getMoneyStyle } from "@/utils/rocessor.js";
	import { mapGetters } from "vuex";
	import empty from "@/components/empty";
	import {
		spreadCommission,
		userBalance,
		// extractBank,
	} from "@/api/wallet.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) {
						_this.height = resu.windowHeight - res[0].top + "px";
						console.log("打印页面的剩余高度", _this.height);
					});
				},
				fail: res => {},
			});
		},
		data() {
			return {
				userInfo: {},
				yj: "",
				height: "",
				// 头部图高度
				maxheight: "",
				tabCurrentIndex: 0,
				orderStatusSum: 0,
				recharge: 0,
				navList: [
					// {
					// 	state: 0,
					// 	text: '全部',
					// 	loadingType: 'more',
					// 	orderList: [],
					// 	page: 1, //当前页数
					// 	limit: 10 //每次信息条数
					// },
					{
						state: 4,
						text: "进行中",
						loadingType: "more",
						orderList: [],
						page: 1, //当前页数
						limit: 10, //每次信息条数
					},
					{
						state: 3,
						text: "已结束",
						loadingType: "more",
						orderList: [],
						page: 1, //当前页数
						limit: 10, //每次信息条数
					},
				],
				money: "",
			};
		},
		onLoad(options) {
			uni.setNavigationBarTitle({
				title: this.$t("tab.a1"),
				 
			});
		},
		onShow() {
			this.getUserInfo();
			this.loadData();
			this.getLock();
		},
		methods: {
			getUserInfo() {
				getUserInfo({}).then(({ data }) => {
					this.userInfo = data;
				});
			},
			async getLock() {
				const res = await getLock();
				console.log("123", res);
			},

			toBack() {
				uni.switchTab({
					url: "/pages/pledge/pledge",
				});
			},
			// 页面跳转
			navto(e) {
				uni.navigateTo({
					url: e,
				});
			},
			//获取收入支出信息
			async loadData(source) {
				let obj = this;
				//这里是将订单挂载到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) {
							data.forEach(e => {
								navItem.orderList = navItem.orderList.concat(
									e.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);
					});
			},

			//swiper 切换
			changeTab(e) {
				this.tabCurrentIndex = e.target.current;
				this.loadData("tabChange");
			},
			//顶部tab点击
			tabClick(index) {
				this.tabCurrentIndex = index;
			},
		},
	};
</script>

<style lang="scss">
	.all {
		width: 750rpx;
		height: 1660rpx;
		background-color: $page-color-base;
	}
	.top {
		margin-left: 30rpx;
		width: 690rpx;
		height: 137rpx;
		background-color: #191a1f;
	}
	.zhiya {
		margin-left: 28rpx;
		// margin-top: 31rpx;
		padding-top: 31rpx;
		height: 21rpx;
		font-size: 21rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #757c8f;
	}
	.zhiyashu {
		display: flex;
		justify-content: start;
	}
	.shu {
		margin-left: 29rpx;
		margin-top: 30rpx;
		font-size: 32rpx;
		height: 30rpx;
		color: #ffffff;
		font-family: PingFang SC;
		font-weight: bold;
	}
	.wen {
		margin-left: 20rpx;
		margin-top: 36rpx;
		height: 26rpx;
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #ffffff;
	}

	.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>
