<template>
	<view class="">
		<navigation :showBack="false" :bgnum="true" class="head">
			<image src="../../../static/tongyonh/san.png" mode="aspectFit" class="renYou" slot="logo"
				@click="goCwallet()"></image>
			<image src="../../../static/tongyonh/erwei.png" mode="aspectFit" class="renYou2" slot="logo"
				@click="chooseImage()"></image>
			<text class="big_title">
				{{i18n.Wallet}}
			</text>
		</navigation>
		<view class="main">
			<view
				:class="{'money_con': userObj.coinList[0].xname=='Ethereum', 'money_con2': userObj.coinList[0].xname=='Bitcoin', 'money_con3': userObj.coinList[0].xname=='TRON'}">
				<image src="../../../static/tongyonh/ethereum.png" mode="aspectFit" class="imgicon"
					v-if="userObj.coinList[0].xname=='Ethereum'"></image>
				<image src="../../../static/tongyonh/Frame28.png" mode="aspectFit" class="imgicon"
					v-if="userObj.coinList[0].xname=='Bitcoin'"></image>
				<image src="../../../static/tongyonh/tronicon.png" mode="aspectFit" class="imgicon"
					v-if="userObj.coinList[0].xname=='TRON'"></image>
				<view class="textcon1 flex">
					<text class="text">{{this.userObj.name}}</text>
					<image src="../../../static/tongyonh/visibility_24px.png" mode="aspectFit" class="img1"
						@click="showMoney()" v-if="showMoney1"></image>
					<image src="../../../static/tongyonh/eyeno.png" mode="aspectFit" class="img1" @click="showMoney22()"
						v-if="showMoney2"></image>
				</view>
				<view class="textcon2" v-if="showMoney1">
					{{currency=='USD'?'$ '+(!userObj.totalBalancePrice?0.00:userObj.totalBalancePrice):'￥ '+(!userObj.totalBalanceCnyPrice?0.00:userObj.totalBalanceCnyPrice)}}
				</view>
				<view class="textcon2" v-if="showMoney2">
					***
				</view>
				<view class="textcon3">
					{{this.userObj.ellipsisAddress}}
				</view>
			</view>

			<view class="bot_con">
				<view class="jiacon">
					<view class="title">
						{{i18n.assets}}
					</view>
					<image src="../../../static/tongyonh/IconGroup.png" mode="aspectFit" class="jiaimg"
						v-if="userObj.coinList[0].xname!='Bitcoin'&&userObj.coinList[0].xname!='TRON'" @click="goOther">
					</image>
				</view>
				<!-- <view class="scroll"> -->
					<scroll-view :scroll-y="true" style="max-height: 880rpx;"  lower-threshold="50">
					<view class="item flexx" @click="goTrans(item,index)" v-for="item,index in this.userObj.coinList">
						<view class="left flex ">
							<view class="img1">
								<image :src="item.icon" mode="aspectFit" class="icon"></image>
							</view>

							<view class="textcon">
								<view class="text1">
									{{item.name}}
								</view>
								<view class="text2">
									{{item.xname}}
								</view>
							</view>
						</view>
						<view class="rig">
							<view class="text1">
								{{item.balance}}
							</view>
							<view class="text2" v-if="item.balancePrice">

								≈
								{{currency=='USD'?'$ '+(!item.balancePrice?0.00:item.balancePrice):'￥ '+(!item.balanceCnyPrice?0.00:item.balanceCnyPrice)}}
							</view>
							<view class="text2" v-if="!item.balancePrice">
								≈ $ 0.00
							</view>
						</view>
					</view>
				<!-- </view> -->
</scroll-view>


			</view>



		</view>
		<tab-bar :selectActive="1"></tab-bar>
	</view>
</template>

<script>
	import cont from "@/components/navigation/navigation.vue"
	import token from "@/utils/TokenUtil"
	export default {
		data() {
			return {
				eth: '',
				trc: 'Hello',
				currency: 'USD',
				walletInfo: {},
				userObj: {},
				userObj2: {},
				showMoney1: true,
				showMoney2: false,
				btcBalance: 0,
				isStop: false
			}
		},
		onUnload: function() {
			this.isStop = true
			uni.setStorageSync('isWallet', false);
		},
		async onLoad() {
			
			let currency = uni.getStorageSync('currency');
			if (currency) {
				this.currency = currency;
			}
			
			// 拿钱包
			//console.log(this.$TronUtil.decode("TBk72yKTJWppCsa7XrsU7Qhfo4yNvbm8rE"))
			
			this.userObj = uni.getStorageSync('wallet');
			this.userObj = await this.$walletUtil.updateBalance();
			uni.setStorageSync('isWallet', false);
			// #ifdef APP-PLUS
			this.appVersion()
			// #endif


		},
		computed: {
			i18n() {
				return this.$t('index')
			},
		},
		async onPullDownRefresh() {
			this.userObj = await this.$walletUtil.updateBalance();
			
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 500);
		},
		methods: {
			async appVersion() {
				let param = {
					'appId': uni.getSystemInfoSync().platform
				}
				console.log('ss' + JSON.stringify(uni.getSystemInfoSync()))
				const response = await this.$api.versionUpgrade(param)
				plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
					console.log('当前版本号' + wgtinfo.versionCode)
					
					console.log((wgtinfo.versionCode < response.data.versionId))
					if (wgtinfo.versionCode < response.data.versionId) {
						let that=this;
						// uni.showModal({
						// 	title: that.i18n.updateTitle,
						// 	content: that.i18n.updateMsg,
						// 	success: function (res) {
						// 		if (res.confirm) {
						// 			plus.runtime.openURL(response.data.appUrl);
						// 		}
						// 	}
						// });
						
					} 
				});
			},
			goOther() {

				uni.navigateTo({
					url: 'otherCoin/index'
				})
			},
			showMoney() {
				this.showMoney1 = false
				this.showMoney2 = true
			},
			showMoney22() {
				this.showMoney1 = true
				this.showMoney2 = false
			},
			setStorage() {

			},
			goTrans(itemm, index) {
				let coin = this.userObj.coinList[index];
				coin.type = this.userObj.type;
				coin.privateKey = this.userObj.privateKey;
				coin.address = this.userObj.address;
				coin.password = this.userObj.password;
				uni.setStorageSync('coin', coin)
				uni.navigateTo({
					url: '/pages/menu/token/btc/index'
				})
			},

			// 唤醒摄像头
			chooseImage() {
				var _this = this
				uni.scanCode({
					success: function(res) {
						uni.setStorageSync('address',res.result)
						uni.navigateTo({
							url: '/pages/menu/sendToken/transfer/index?item=index'
						})
					}
				});	
			},

			goCwallet() {
				this.isStop = true
				uni.navigateTo({
					url: './cwallet/index'
				})
			}
		}
	};
</script>
<style scoped>
	page {
		background: #FAFAFA;
	}
</style>

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