<template>
	<view class="container" style="padding-top: 100rpx;">
		<topView :backg="'#1A1A17'"></topView>
		<view class="infoBox">
			<view class="navBack" @click="navTo">
				<u-icon name="arrow-left" size="25" color="#fff" style="position: absolute;left: 0;top: 0;font-weight: bold;"></u-icon>
				<view class="title">{{$t("detailsTpl.我的矿机")}}</view>
			</view>
			<view class="infoItem" v-for="item,index in myLists" :key="index" v-if="item.status == 1">
				<view class="itemInfo">
					<view class="itemName">{{$t("detailsTpl.当前矿机")}}</view>
					<view class="flex infos">
						<view class="infoTip flex_item">
							<image :src="'https://www.bscnice.com'+item.machine.image" style="width: 130rpx;height:130rpx;border: 2rpx solid #8D7049;
								border-radius: 25rpx;"></image>
							<view class="nameBox">
								<view class="nameTip">{{item.machine.name}}</view>
								<view class="price">{{$t("details.价格")}}：<text class="priTip">{{item.machine.price * 1}}NUSD</text></view>
							</view>
						</view>
						<view class="statusBox flex_item">
							<view class="status">{{$t("detailsTpl.工作中")}}</view>
							<view class="statusTip"></view>
						</view>
					</view>
				</view>
				<view class="flex numBox">
					<view class="numTpl">
						<view class="num">{{info.sent * 1}}</view>
						<view class="name">{{$t("detailsTpl.已释放")}}</view>
					</view>
					<view class="partition"></view>
					<view class="numTpl">
						<view class="num">{{info.wait}}</view>
						<view class="name">{{$t("detailsTpl.待释放")}}</view>
					</view>
				</view>
			</view>
			<view class="noDate" v-if="myLists.length == 0">{{$t("detailsTpl.暂无工作中的矿机列表")}}</view>
			<view class="navList flex">
				<view class="navItem" v-for="item,index in navList" :key="index" @click="clickTab(index)">
					<view class="navName" :class="{ active: currTab == index }">{{item}}</view>
					<image v-if="currTab == index" src="/static/img/img28.png" class="navTip"></image>
				</view>
			</view>
			<view class="listBox" v-if="list.length > 0">
				<view class="listTpl flex" v-for="item,index in list" :key="index">
					<view class="tpl">
						<view class="addr">{{currTab == 0?typeList[item.type]:item.machine.name}}</view>
						<view class="time">{{item.createtime }}</view>
					</view>
					<view class="num add" v-if="currTab == 0">+{{item.money * 1}}</view>
					<view class="num" v-if="currTab == 1">-{{item.machine.price * 1}}</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import topView from '../components/topView.vue';
	import { myList,getTokenLog} from '@/api/index.js';
	import{ getTime } from '@/utils/rocessor.js';
	export default {
		components: {
			topView
		},
		data () {
			return {
				myLists:[],//我的矿机列表
				list:[],
				navList:[this.$t("detailsTpl.释放记录"),this.$t("detailsTpl.购买记录")],
				currTab:0,
				info:'',
				typeList:''
			}
		},
		onShow () {
			this.loadData();
			this.getLog()
		},
		methods: {
			clickTab(index){
				this.currTab = index
				this.list = []
				if(index == 0){
					this.getLog()
				}else{
					this.loadData()
				}
			},
			loadData () {
				let obj = this
				myList({}).then(function(res){
					res.data.list.forEach(item => {
						item.createtime = getTime(item.createtime)
					})
					obj.myLists = res.data.list
					obj.info = res.data
					if(obj.currTab == 1){
						obj.list = res.data.list
					}
				})
			},
			getLog(){
				let obj = this
				getTokenLog({
					page:1,
					limit:100000,
					token:'NICE',
					pm:'',
					type:'day_mining'
				}).then(function(res){
					res.data.list.forEach(item => {
						item.createtime = getTime(item.createtime)
					})
					obj.list = res.data.list
					obj.typeList = res.data.type
				})
			},
			change(currentPage,type) {
				this.page.currentPage = currentPage;
				this.loadData()
			},
			navTo(){
				uni.navigateBack({
					delta: 1
				});
			},
		},
	}
</script>

<style lang="scss">
	page {
		width: 100%;
		min-height: 100vh;
		.container {
			width: 100%;
			min-height: 100vh;
			padding-bottom: 25rpx;
		}
	}
	.noDate{
		text-align: center;
		padding-top: 25rpx;
		opacity: 0.3;
	}
	.infoBox{
		padding: 0rpx 25rpx;
		color: #fff;
		.infoItem{
			margin-bottom: 25rpx;
			background: #1A1A17;
			padding: 35rpx 0rpx;
			border-radius: 20rpx;
			.numBox{
				padding-top: 25rpx;
				.numTpl{
					width: 45%;
					text-align: center;
					.name{
						font-weight: 500;
						font-size: 26rpx;
						color: #FFFFFF;
						padding-top: 10rpx;
					}
					.num{
						font-weight: bold;
						font-size: 34rpx;
						color: #FFFFFF;
					}
				}
				.partition{
					width: 2rpx;
					height: 119rpx;
					background: linear-gradient(0deg, rgba(255,255,255,0), #FFFFFF, rgba(255,255,255,0));
				}
			}
		}
	}
	.itemInfo{
		padding: 0rpx 25rpx;
		.itemName{
			font-weight: bold;
			font-size: 27rpx;
			padding-bottom: 20rpx;
		}
		.infos{
			border-bottom: 1rpx solid rgba(221, 225, 235, 0.2);
			padding-bottom: 25rpx;
			.infoTip{
				align-items: flex-start;
				.nameBox{
					padding-left: 25rpx;
					.nameTip{
						font-weight: bold;
						font-size: 32rpx;
						color: #FFFFFF;
					}
					.price{
						font-weight: 500;
						font-size: 24rpx;
						color: #999999;
						padding-top: 30rpx;
						.priTip{
							font-weight: 500;
							font-size: 26rpx;
							color: #999999;
							line-height: 44rpx;
							background: linear-gradient(258deg, #FFF0CF 0%, #CBA16B 30.0048828125%, #FCE9CF 67.67578125%, #C29963 100%);
							-webkit-background-clip: text;
							-webkit-text-fill-color: transparent;
						}
					}
				}
			}
			.statusBox{
				.status{
					font-weight: bold;
					font-size: 32rpx;
					color: #999999;
					background: linear-gradient(258deg, #FFF0CF 0%, #CBA16B 30.0048828125%, #FCE9CF 67.67578125%, #C29963 100%);
					-webkit-background-clip: text;
					-webkit-text-fill-color: transparent;
				}
				.statusTip{
					margin-left: 15rpx;
					width: 15rpx;
					height: 15rpx;
					background: linear-gradient(137deg, #FFF0CF, #CBA16B, #FCE9CF, #C29963);
					border-radius: 50%;
				}
			}
			
		}
	}
	.listBox{
		margin-top: 25rpx;
		background: #1A1A17;
		padding: 0rpx 25rpx;
		border: 4rpx solid #D7B381;
		border-radius: 30rpx;
		.listTpl{
			padding: 30rpx 0rpx;
			border-bottom: 1rpx solid rgba(240, 240, 240, 0.3);
			.tpl{
				.addr{
					
				}
				.time{
					font-weight: 500;
					font-size: 22rpx;
					padding-top: 15rpx;
					color: #999999;
				}
			}
			.num{
				font-weight: 400;
				font-size: 36rpx;
				color: #fff;
			}
			.add{
				color: #4C5D97;
				background: linear-gradient(258deg, #FFF0CF 0%, #CBA16B 30.0048828125%, #FCE9CF 67.67578125%, #C29963 100%);
				-webkit-background-clip: text;
				-webkit-text-fill-color: transparent;
			}
		}
		.listTpl:last-child{
			border-bottom: none !important;
		}
	}
	.navList{
		padding: 43rpx 120rpx;
		.navItem{
			width: 120rpx;
			position: relative;
			.navName{
				font-weight: bold;
				font-size: 29rpx;
				color: #FFFFFF;
			}
			.active{
				font-weight: bold;
				font-size: 29rpx;
				color: #FFFFFF;
				background: linear-gradient(258deg, #FFF0CF 0%, #CBA16B 30.0048828125%, #FCE9CF 67.67578125%, #C29963 100%);
				-webkit-background-clip: text;
				-webkit-text-fill-color: transparent;
			}
			.navTip{
				position: absolute;
				top: 45rpx;
				left: 35rpx;
				width: 45rpx;
				height: 11rpx;
			}
		}
	}
	.navBack{
		position: relative;
		color: #fff;
		text-align: center;
		margin: 30rpx 0rpx 40rpx 0rpx;
		.title{
			font-weight: bold;
			font-size: 34rpx;
		}
	}
</style>