<template>
	<view class="">
		<navigation :showBack="true" :bgnum="true">
			<text class="big_title" v-if="userObject.coinList[0].xname=='Bitcoin'">
				BTC
			</text>
			<text class="big_title" v-if="userObject.coinList[0].xname=='Ethereum'">
				ETH
			</text>
			<text class="big_title" v-if="userObject.coinList[0].xname=='TRON'">
				TRX
			</text>
		</navigation>
		<view class="main">
			<view class="money_con"
				:class="{'money_con': userObject.coinList[0].xname=='Ethereum', 'money_con2': userObject.coinList[0].xname=='Bitcoin', 'money_con3': userObject.coinList[0].xname=='TRON'}">
				<view class="textcon1">
					<text class="text1">
						<view class="" v-if="userObject.coinList[0].xname=='Bitcoin'">
							0.00 BTC
						</view>
						<view class="" v-if="userObject.coinList[0].xname=='Ethereum'">
							0.00 ETH
						</view>
						<view class="" v-if="userObject.coinList[0].xname=='TRON'">
							0.00 TRX
						</view>
						<text class="text2">≈ $0.0</text>
					</text>
					<image src="../../../../static/tongyonh/ethereum.png" mode="aspectFit" class="img1"
						v-if="userObject.coinList[0].xname=='Ethereum'"></image>
					<image src="../../../../static/tongyonh/Frame28.png" mode="aspectFit" class="img1"
						v-if="userObject.coinList[0].xname=='Bitcoin'"></image>
					<image src="../../../../static/tongyonh/tronicon.png" mode="aspectFit" class="img1"
						v-if="userObject.coinList[0].xname=='TRON'"></image>
				</view>
				<view class="textcon1">
					<view class="v1">
						<view class="t1">
							0.0
						</view>
						<view class="t2">
							Existing balance
						</view>
					</view>
					<view class="v1 v2">
						<view class="t1">
							0.0
						</view>
						<view class="t2">
							Freeze balance
						</view>
					</view>
				</view>
			</view>

			<view class="select_con">
				<view class="select">
					<u-tabs height="120" bar-width="172" active-color="#6F69FF" inactive-color="#A3AED0" :list="list"
						:is-scroll="false" :current="current" @change="change"></u-tabs>

					<u-empty text="No content" mode="list" v-if="showInfo"></u-empty>

					<view class="" v-if="!showInfo">
						<view class="item1" v-for="(item,index) in trxs" v-if="current==1&&address==item.from"
							@click="goDetail(item,index)">
							<view class="lef_con">
								<image src="../../../../static/tongyonh/arrow-up-left_1.png" mode="aspectFit"
									class="img1" v-if="address==item.from"></image>
								<view class="textcon">
									<view class="text1" v-if="address==item.from">
										{{item.to}}
									</view>

									<view class="text2" v-if="address==item.from">
										{{item.time}}
									</view>
								</view>
							</view>
							<view class="rig_con">
								<view class="text1">
									<text v-if="address==item.from">-</text>
									{{item.value}}
									<text class="">
										{{item.network}}
									</text>



								</view>
								<image src="../../../../static/tongyonh/Shape.png" mode="aspectFit" class="img1">
								</image>
							</view>
						</view>


						<view class="item1" v-for="(item,index) in trxs" v-if="current==0"
							@click="goDetail(item,index)">
							<view class="lef_con">
								<image src="../../../../static/tongyonh/arrow-up-left.png" mode="aspectFit" class="img1"
									v-if="address==item.to"></image>
								<image src="../../../../static/tongyonh/arrow-up-left_1.png" mode="aspectFit"
									class="img1" v-if="address==item.from"></image>
								<view class="textcon">
									<view class="text1" v-if="address==item.from">
										{{item.to}}
									</view>
									<view class="text1" v-if="address==item.to">
										{{item.from}}
									</view>
									<view class="text2">
										{{item.time}}
									</view>
								</view>
							</view>
							<view class="rig_con">
								<view class="text1">
									<text v-if="address==item.to">+</text>
									<text v-if="address==item.from">-</text>
									{{item.value}}
									<text class="">
										{{item.network}}
									</text>



								</view>
								<image src="../../../../static/tongyonh/Shape.png" mode="aspectFit" class="img1">
								</image>
							</view>
						</view>

						<view class="item1" v-for="(item,index) in trxs" v-if="current==2&&address==item.to"
							@click="goDetail(item,index)">
							<view class="lef_con">
								<image src="../../../../static/tongyonh/arrow-up-left.png" mode="aspectFit" class="img1"
									v-if="address==item.to"></image>
								<view class="textcon">
									<view class="text1" v-if="address==item.to">
										{{item.from}}
									</view>

									<view class="text2" v-if="address==item.to">
										{{item.time}}
									</view>
								</view>
							</view>
							<view class="rig_con">
								<view class="text1">
									<text v-if="address==item.to">+</text>
									{{item.value}}
									<text class="">
										{{item.network}}
									</text>



								</view>
								<image src="../../../../static/tongyonh/Shape.png" mode="aspectFit" class="img1">
								</image>
							</view>
						</view>

					</view>
				</view>

			</view>


			<view class="btnconn">
				<view class="btn active" @click="goSend">
					<image src="../../../../static/tongyonh/arrow-up-leftw.png" mode="aspectFit" class="arrow-up-left">
					</image>
					Send
				</view>
				<view class="btn" @click="goReceive">
					<image src="../../../../static/tongyonh/arrow-up-leftp.png" mode="aspectFit" class="arrow-up-left">
					</image>
					<text class="btn13">Receive</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import cont from "@/components/navigation/navigation.vue"
	import api from '@/utils/api'
	import index from '@/utils/index.js'
	export default {
		data() {
			return {
				// 拿账单的address
				coinInfo: {},
				trxs: [],
				trxs2: [],
				address: '',
				userObject: {},
				showInfo: false,
				list: [{
					name: 'All'
				}, {
					name: 'Send'
				}, {
					name: 'Receive',
				}],
		     infoWallet:{},
				current: 0,
				pageSize:10,
				pageNum:1,
				param : {
					'address':'',
					'pageNum':1,
					'pageSize':10,
				},
			}
		},
		methods: {
			goSend(){
				let itemm = JSON.stringify(this.infoWallet)
				uni.navigateTo({
					url: '/pages/menu/sendToken/transfer2/index?item=' + itemm
				})
			},
			goReceive() {
				let itemm = JSON.stringify(this.infoWallet)
				uni.navigateTo({
					url: '/pages/menu/sendToken/index?item=' + itemm
				})
			},
			goDetail(item, index) {
				let itemm = JSON.stringify(this.trxs2[index])
				uni.navigateTo({
					url: '/pages/menu/transction/detail/index?item=' + itemm
				})

			},
			change(index) {
				console.log(index)
				this.current = index;
				console.log(this.current)

			},
			getWalletInfo(){
				if (this.infoWallet.coinList[0].xname == 'Ethereum') {
					this.address = this.infoWallet.address
					this.address2 = this.infoWallet.address
					this.param.address=this.address
					this.userObject = this.infoWallet
					const post = api.address(
					this.param
					)
					post.then(res => {
						console.log(res, 77)
						if (res.data.code == 404) {
							this.showInfo = true;
							return;
						}
						if (res.data.data.network == 'ETH') {
							this.trxs = res.data.data.txs
							for (var i = 0; i < this.trxs.length; i++) {
								this.trxs[i].from = this.trxs[i].from.substring(0, 6) + '...' + this.trxs[i].from
									.substring(35, this.trxs[i].from.length);
								this.trxs[i].to = this.trxs[i].to.substring(0, 6) + '...' + this.trxs[i].to.substring(
									35, this.trxs[i].to.length);
								this.trxs[i].time = index.formatyymmddhhmmss(this.trxs[i].time);
								this.trxs[i].value = parseFloat(this.trxs[i].value).toFixed(5)
							}
						}
				
					})
					this.address = this.address.substring(0, 6) + '...' + this.address.substring(35, this.address.length);
				    this.getInfo()
				} else if (this.infoWallet.coinList[0].xname == 'TRON') {
				   this.address = this.infoWallet.address
				   	this.param.address=this.address
				   this.address2 = this.infoWallet.address
				   this.userObject =this.infoWallet
				   const post = api.addresstrx(
				   this.param
				   )
				   post.then(res => {
				   	if (res.data.code == 404) {
				   		this.showInfo = true;
				   		return;
				   	}
				   	if (res.data.data.network == 'TRX') {
				   		this.trxs = res.data.data.txs
				   		for (var i = 0; i < this.trxs.length; i++) {
				   			this.trxs[i].from = this.trxs[i].from.substring(0, 6) + '...' + this.trxs[i].from
				   				.substring(35, this.trxs[i].from.length);
				   			this.trxs[i].to = this.trxs[i].to.substring(0, 6) + '...' + this.trxs[i].to.substring(
				   				35, this.trxs[i].to.length);
				   			this.trxs[i].time = index.formatyymmddhhmmss(this.trxs[i].time);
				   			this.trxs[i].value = parseFloat(this.trxs[i].value).toFixed(5)
				   		}
				   	}
				   
				   })
				   this.address = this.address.substring(0, 6) + '...' + this.address.substring(35, this.address.length);
				}
			},
		getInfo() {
			this.param.address=this.address2
			const post = api.address(
			this.param
			)
			post.then(res => {
			this.trxs2 = res.data.data.txs
			})
		}
		},
		onLoad(option) {
			const item = JSON.parse(option.item);
			this.infoWallet = item
		
            this.getWalletInfo()
		},
		onReachBottom() {
			this.param.pageSize+=5;
			this.getWalletInfo()
		}
	};
</script>
<style scoped>
	page {
		background: #FAFAFA;

	}
</style>

<style>
	@import './index.css';
</style>
