<template>
	<view class="revenue">
		
		
		<view class="top-jg">
			
		</view>
		<view class="nav-wrapper">
			<view class="nav-item" v-for="(item, index) in navList" :key="index" :class="{ active: currentIndex === index }" @click="navClick(index)">{{ item.title }}</view>
		</view>
		<view class="list">
			<view class="list-item flex">
				<view class="item-tpl">
					<view class="tpl name">有效算力</view>
					<view class="tpl num">{{list.doing}}{{navList[currentIndex].slUnit}}</view>
				</view>
				<view class="item-tpl">
					<view class="tpl name">待生效算力</view>
					<view class="tpl num">{{list.stand}}{{navList[currentIndex].slUnit}}</view>
				</view>
			</view>
			<view class="list-item">
				<view class="item-tpl tols">
					<view class="tpl name">累计挖币</view>
					<view class="tpl num">{{list.all_mining}}{{navList[currentIndex].unit}}</view>
				</view>
				<!-- <view class="item-tpl">
					<view class="tpl name">当前锁仓</view>
					<view class="tpl num">{{list.all_lock}}FIL</view>
				</view> -->
			</view>
		</view>
		<view class="all-num">
			<view class="">
				<view class="title">总收益</view>
				<view class="num">{{allIncome}}{{navList[currentIndex].unit}}</view>
			</view>
			<view class="">
				<view class="title">累计释放</view>
				<view class="num">{{ljIncome}}{{navList[currentIndex].unit}}</view>
			</view>
			<view class="">
				<view class="title">待释放</view>
				<view class="num">{{wait}}{{navList[currentIndex].unit}}</view>
			</view>
		</view>
		
		<view class="tip">
			<view class="line"></view>
			<view class="title">每日收益记录</view>
			<view class="line"></view>
		</view>
		<scroll-view :style="{ height: height }" class="days" scroll-y>
			<empty v-if="navList[currentIndex].loaded === true && navList[currentIndex].list.length === 0"></empty>
			<view class="day-item" v-for="(item,index) in navList[currentIndex].list" :key="index">
				<view class="item">
					<view class="item-title">结算日期：</view>
					<view class="item-value">2021-07-04</view>
				</view>
				<view class="item">
					<view class="item-title">今日可用<text>25%</text></view>
					<view class="item-value">0.09{{navList[currentIndex].unit}}</view>
				</view>
				<view class="item">
					<view class="item-title">今日冻结<text>25%</text></view>
					<view class="item-value">0.09{{navList[currentIndex].unit}}</view>
				</view>
				<view class="item">
					<view class="item-title">今日释放<text>1/150</text></view>
					<view class="item-value">0.09{{navList[currentIndex].unit}}</view>
				</view>
				<uni-load-more :status="item.loadingType"></uni-load-more>
			</view>
			
		</scroll-view>
	</view>
</template>

<script>
import empty from '@/components/empty';
import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
import { mining,miningIndex } from '@/api/calculation.js';
export default {
	components:{
		empty,
		uniLoadMore
	},
	data() {
		return {
			list: '',
			navList: [
				{
					title: 'Fil',
					unit: 'FIL',
					slUnit:'T',
					list: [],
					page: 1,
					limit: 10,
					loadingType: 'more',
				},
				{
					title: 'Chia',
					unit: 'XCH',
					slUnit:'T',
					list: [],
					page: 1,
					limit: 10,
					loadingType: 'more',
				},
				{
					title: 'Bzz',
					unit: 'BZZ',
					slUnit:'节点',
					list: [],
					page: 1,
					limit: 10,
					loadingType: 'more',
				}
			],
			currentIndex: 0,
			height: 0,
			allIncome: 0,//总收益
			ljIncome: 0,//累计收益
			wait: 0//待释放
		};
	},
	onReady(res) {
		var _this = this;
		uni.getSystemInfo({
			success: resu => {
				const query = uni.createSelectorQuery();
				query.select('.days').boundingClientRect();
				query.exec(function(res) {
					console.log(res, 'ddddddddddddd');
					_this.height = resu.windowHeight - res[0].top + 'px';
					console.log('打印页面的剩余高度', _this.height);
				});
			},
			fail: res => {}
		});
	},
	onLoad() {
		let userInfo = uni.getStorageSync('userInfo') || '';
		this.level = userInfo.level;
		this.loadData();
		this.loadTopDate('FIL')
	},
	methods: {
		async loadTopDate(type) {
			uni.showLoading({
				title: '加载中...'
			})
			let obj = this;
			miningIndex({
				type: type
			}).then(({ data }) => {
				obj.list = data;
				uni.hideLoading()
				console.log(obj.list)
			});
		},
		//切换币种
		navClick(index) {
			if(index !== this.currentIndex ){
				this.currentIndex = index;
				this.loadTopDate(this.navList[index].unit)
				this.loadData('tabChange')
			}
			
		},
		loadData(source) {
			//这里是将list挂载到nav列表下
			let index = this.currentIndex;
			let navItem = this.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';

			// orderList({
			// 	type: state,
			// 	page: navItem.page,
			// 	limit: navItem.limit
			// })
			// 	.then(({ data }) => {
			// 		let arr = data.map(e => {
			// 			return e;
			// 		});
			// 		navItem.list = navItem.list.concat(arr);
			// 		// console.log(navItem.orderList);
			// 		navItem.page++;
			// 		if (navItem.limit == data.length) {
			// 			//判断是否还有数据， 有改为 more， 没有改为noMore
			// 			navItem.loadingType = 'more';
			// 			return;
			// 		} else {
			// 			//判断是否还有数据， 有改为 more， 没有改为noMore
			// 			navItem.loadingType = 'noMore';
			// 		}
			// 		this.$set(navItem, 'loaded', true);
			// 	})
			// 	.catch(e => {
			// 		console.log(e);
			// 	});
			//假数据
			let arr = []
			navItem.list = navItem.list.concat(arr)
			navItem.page++
			navItem.loadingType = 'noMore'
			this.$set(navItem, 'loaded', true)
			console.log(this.navList)
		}
	}
};
</script>

<style lang="scss" scoped>
page {
	width: 100%;
}
.top-jg {
	height: 55rpx;
}
.nav-wrapper {
	margin: 0rpx auto 10rpx;
	width: 627rpx;
	height: 60rpx;
	border: 2px solid #5771df;
	border-radius: 5rpx;
	display: flex;
	.nav-item {
		width: 209rpx;
		text-align: center;
		line-height: 60rpx;
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #5771df;
	}
	.active {
		background: #5771df;
		color: #fff;
	}
}
.all-num {
	width: 627rpx;
	margin: 0 auto;
	display: flex;
	justify-content: space-between;
	font-size: 30rpx;
	font-family: PingFang SC;
	font-weight: bold;
	color: #333333;
	view {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		.title {
			padding-bottom: 20rpx;
		}
		.num {
			font-weight: 500;
		}
	}
}
.tip {
	width: 627rpx;
	margin: 80rpx auto 70rpx;
	display: flex;
	justify-content: space-between;
	align-items: center;
	.line {
		width: 193rpx;
		height: 2rpx;
		background: #5771df;
	}
	.title {
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #5771df;
	}
}
.days {
	// background-color: red;
	padding: 0 65rpx;
	.day-item {
		height: 230rpx;
		border-bottom: 1px solid #F3F4F6;
		background-color: #fff;
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
		display: flex;
		flex-direction: column;
		justify-content: space-around;
		padding: 20rpx 0;
		.item {
			display: flex;
			justify-content: space-between;
			text {
				display: inline-block;
				margin-left: 10rpx;
			}
		}
	}
}
.list {
	padding:10rpx 65rpx 0;
	.list-item{
			// padding: 90rpx 118rpx 0 118rpx;
			
			margin-bottom: 15rpx;
			.item-tpl{
				background-color: #f7f6fb;
				text-align: center;
				// background-color: #FFFFFF;
				padding: 41rpx 0;
				width: 48%;
				.name{
					color: #666666;
					font-size: 24rpx;
				}
				.num{
					font-size: 32rpx;
					color: #333333;
					font-weight: bold;
					padding-top: 10rpx;
				}
			}
		}
		.tols{
			width: 100% !important;
			
		}
}

</style>
