<template>
	<view class="">
		<navigation :showBack="false" :bgnum="true" class="head">
			<image src="../../../../static/tongyonh/Vector.png" mode="aspectFit" class="back" @click="back()"></image>
			<text class="big_title">
				{{coin.name}}
			</text>

		</navigation>
		<view class="main">
			<view class="money_con"
				:class="{'money_con': coin.type=='ETH', 'money_con2': coin.type=='BTC', 'money_con3': coin.type=='TRX'}">
				<view class="textcon1">
					<text class="text1">
						<view class="">
							{{coin.balance}} {{coin.name}}
						</view>
						<text class="text2">
							≈ {{currency=='USD'?'$ '+(!coin.balancePrice?0.00:coin.balancePrice):'￥ '+(!coin.balanceCnyPrice?0.00:coin.balanceCnyPrice)}}
							
							</text>
					</text>
					<image src="../../../../static/tongyonh/ethereum.png" mode="aspectFit" class="img1"
						v-if="coin.type=='ETH'&&!coin.contractAddress"></image>
					<image src="../../../../static/tongyonh/Frame28.png" mode="aspectFit" class="img1"
						v-if="coin.type=='BTC'&&!coin.contractAddress"></image>
					<image src="../../../../static/tongyonh/tronicon.png" mode="aspectFit" class="img1"
						v-if="coin.type=='TRX'&&!coin.contractAddress"></image>
				</view>
				<view class="textcon1">
					<view class="v1">
						<view class="t1">
							0.0
						</view>
						<view class="t2">
							{{i18n.Existingbalance}}
						</view>
					</view>
					<view class="v1 v2">
						<view class="t1">
							0.0
						</view>
						<view class="t2">
							{{i18n.Freezebalance}}
						</view>
					</view>
				</view>
			</view>

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

					<u-empty :text="teee" mode="list" v-if="showInfo"></u-empty>
<scroll-view  v-if="!showInfo":scroll-y="true" style="max-height: 880rpx;" @scrolltolower="scrollToPage" lower-threshold="50">
	<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="item.type=='in'"></image>
								<image src="../../../../static/tongyonh/arrow-up-left_1.png" mode="aspectFit"
									class="img1" v-if="item.type=='out'"></image>
								<view class="textcon">

									<view class="text1">
										{{item.address}}
									</view>
									<view class="text2">
										{{item.transactionTime}}
									</view>
								</view>
							</view>
							<view class="rig_con">
								<view class="text1">
									<text v-if="item.type=='in'">+</text>
									<text v-if="item.type=='out'">-</text>
									{{item.amount}}
									<text class="">
										{{item.network}}
									</text>
								</view>
								<image src="../../../../static/tongyonh/Shape.png" mode="aspectFit" class="img1">
								</image>
							</view>
						</view>
</scroll-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>
					{{i18n.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">{{i18n.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 {
				teee:this.$t('index').Nocontent,
				// 拿账单的address
				trxs: [],
				coin: {},
				currency:'USD',
				isNoData:false,
				showInfo: false,
				list: [{
					name: this.$t('index').All,

				}, {
					name: this.$t('index').Send,

				}, {
					name: this.$t('index').Receive,

				}],
				infoWallet: {},
				current: 0,
				pageSize: 20,
				pageNum: 1,
				balance: 0,
				address: '',
				type: 'all',
				trueType: '',
				contract: '',
				balancePrice: '',
			}
		},
		computed: {
			i18n() {
				return this.$t('index')
			},
		},
		methods: {
			back() {
				uni.reLaunch({
					url: '../../wallet/index'
				})
			},
			goSend() {
				uni.navigateTo({
					url: '/pages/menu/sendToken/transfer/index'
				})
			},
			goReceive() {
				uni.setStorageSync('infoWallet', this.infoWallet)
				uni.navigateTo({
					url: '/pages/menu/sendToken/index'
				})
			},
			goDetail(item, index) {
				console.log(this.trxs[index],444444)
				uni.setStorageSync('transDetail', this.trxs[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;
				this.pageNum = 1;
				this.trxs=[];
				this.getWalletInfo();
				this.isNoData=false;
			},
			// onReachBottom() {
			// 	if(!this.isNoData){
			// 	  console.log(445454545)
			// 		this.pageNum=this.pageNum+1;
			// 		this.getWalletInfo();
			// 	}
				
			// },
			// 给scrollview绑定下拉加载事件 代替onReachBottom
			scrollToPage(){
				if(!this.isNoData){
				  console.log(445454545)
					this.pageNum=this.pageNum+1;
					this.getWalletInfo();
				}
			},
			async getWalletInfo() {
				let params = {
					address: this.coin.address,
					chainName: this.coin.type,
					contract: this.coin.contractAddress,
					pageNum: this.pageNum,
					pageSize: this.pageSize
				}
				if (this.type === 'send') {
					params.fromAddress = this.coin.address;
				} else if (this.type === 'receive') {
					params.toAddress = this.coin.address
				}
				const response = await this.$api.getChainDataList(params)
				if (response.data.rows.length == 0 ) {
					this.isNoData=true;
					if(this.pageNum == 1){
						this.showInfo = true;
					}
					
				} else {
					this.showInfo = false;
				}
				
				this.trxs=this.trxs.concat(response.data.rows);
                  console.log(this.trxs,787878)

			}
		},
		onLoad() {
			this.coin = uni.getStorageSync('coin');
			this.change(0);
			let currency=uni.getStorageSync('currency');
			if(currency){
				this.currency=currency;
			}
		}
		
	};
</script>
<style scoped>
	page {
		background: #FAFAFA;

	}
</style>

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