<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="" >
							{{infoWallet.balance}}
						</view>
						<text class="text2">≈ $ {{balancePrice}}</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"
							@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">
										{{item.address}}
									</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>
				</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: 20,
				pageNum: 1,
		        
			   balance:0,
				
				address:'',
				type:'all',
				trueType:'',
				contract:'',
				balancePrice:'',
			}
		},
		methods: {
			goSend() {
				uni.setStorageSync('infoWallet',this.infoWallet)
				uni.navigateTo({
					url: '/pages/menu/sendToken/transfer/index'
				})
			},
			goReceive() {
				uni.setStorageSync('infoWallet',this.infoWallet)
				uni.navigateTo({
					url: '/pages/menu/sendToken/index'
				})
			},
			goDetail(item, index) {
				uni.setStorageSync('transDetail',this.trxs2[index])
				uni.navigateTo({
					url: '/pages/menu/transction/detail/index'
				})

			},
			change(index) {
			if(index==0){
					this.type='all'
				}
				if(index==1){
					this.type='send'
				}
				if(index==2){
					this.type='receive'
				}
				this.current = index;
				console.log(this.current)
			this.getWalletInfo();
			},

			getWalletInfo() {
				this.userObject = this.infoWallet
				var that = this
				console.log(this.trueType, this.type, this.address, this.contract,
					this.pageNum, this.pageSize)
				this.$dataUtil.transactionData(this.trueType, this.type, this.address, this.contract,
					this.pageNum, this.pageSize,
					function(data) {
						console.log(data,121211212112121)
						if(data.length==0){
							that.showInfo=true;
						}else{
							that.showInfo=false;
						}
						that.trxs = data
						that.trxs2 = data
						console.log(that.trxs, 12121)
					})







			},
			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 = uni.getStorageSync('wallet')
			console.log(item,2222)
			this.infoWallet = item
			this.address=item.address
			this.trueType=item.type	
			this.balancePrice=item.balancePrice
           console.log(this.infoWallet,1111)
			this.getWalletInfo()
		},
		onPullDownRefresh() {
			console.log('refresh');
			this.getWalletInfo();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 500);
		},
		onReachBottom() {
			this.pageSize += 5;
			this.getWalletInfo()
		}
	};
</script>
<style scoped>
	page {
		background: #FAFAFA;

	}
</style>

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