<template>
	<view class="minebg">
		<uni-nav-bar title="" backgroundColor="rgba(0, 0, 0, 1);" :shadow="false" :border="false" :fixed="true" height="100rpx"></uni-nav-bar>
		<view class="v1">
			<uni-badge :text="noticeCount" absolute="rightTop" size="small"  class="item" type="error">
			  <uni-icons size="30" type="chat" @click="onTokenJump('/pages/mine/notice')"></uni-icons>
			</uni-badge>
			<uni-icons size="30" type="gear" @click="onTokenJump('/pages/Setting/index')"></uni-icons>
		</view>
		<view class="v2">
			<view style="width: 180rpx; float: left;" @click="onTokenJump('/pages/mine/info')">
				<image style="width: 160rpx; height: 160rpx" :src="user.avatar" mode="cover"></image>
			</view>
			<view class="login" @click="onPageJump('/pages/mine/login')" v-if="!islogin">
				{{$t('mine.text1')}}
			</view>
			<view class="login1" v-else>
				<view><span @click="onTokenJump('/pages/mine/info')" class="s">{{user.username}}</span></view>
				<span style="font-size: 28rpx; font-weight: 400; float: left;">ID：{{user.id}}</span>
				<image class="i" src="/static/images/copy.png" @click="copy(user.id)" mode="cover"></image>
			</view>
			<view style="clear: both;"></view>
		</view>
		<view class="v3">
			<view class="dj">
				<view style="width: 100rpx; float: left;">
					<image style="width: 66rpx; height: 50rpx; margin: 40rpx auto;" src="/static/images/image.png" mode="cover"></image>
				</view>
				<view class="sj" v-if="user.role_id == 1">
					<view class="sj1">{{$t('mine.text2')}} </view>
					<view class="sj2">{{$t('mine.text3')}} 🚀 </view>
				</view>
				<view class="sj" v-else>
					<view class="sj1" style="margin-top: 20rpx;">{{$t('mine.text4')}}</view>
				</view>
				<view class="sj3">
					<button type="primary" class="b" @click="onTokenJump('/pages/mine/upgrade')" style="margin-left: 13%;" v-if="user.role_id == 1">{{$t('buttonUpgrade')}}</button>
					<button type="primary" class="b" @click="onTokenJump('/pages/mine/upgrade')" style="margin: auto;" v-else>{{$t('buttonDetails')}}</button>
				</view>
			</view>
		</view>
		<view class="v4">
			<uni-row :gutter="20">
			  <uni-col :span="12">
				  <view class="wallet" @click="onTokenJump('/pages/wallet/index')">
					  <view class="title">{{$t('mine.text5')}}</view>
					  <view class="num">{{user.money.toFixed(4)}}</view>
				  </view>
			  </uni-col>
			  <uni-col :span="12">
				  <view class="wallet" @click="onTokenJump('/pages/power/index')">
					  <view class="title">{{$t('mine.text6')}}</view>
					  <view class="num1">{{user.score.toFixed(2)}}</view>
				  </view>
			  </uni-col>
			</uni-row>
			<uni-row :gutter="20">
			  <uni-col :span="24" style="margin-top: 20rpx;">
				  <view class="wallet" style="padding: 40rpx 20rpx;" @click="onTokenJump('/pages/address/index')">
					  <image class="i" src="/static/images/5.png" mode="cover"></image>
					  <span class="s">{{$t('mine.text7')}}</span>
					  <uni-icons size="20" type="right" style="float: right;"></uni-icons>
					  <view style="clear: both;"></view>
				  </view>
			  </uni-col>
			  <uni-col :span="24" style="margin-top: 20rpx;">
			  	  <view class="wallet" style="padding: 40rpx 20rpx;" @click="onTokenJump1('/pages/im/index')">
			  	  	 <image class="i" src="/static/images/m4.png" fit="cover"></image>
			  	  	 <span class="s">{{$t('mine.text8')}}</span>
			  	  	 <uni-icons size="20" type="right" style="float: right;"></uni-icons>
			  	  	 <view style="clear: both;"></view>
			  	  </view>
			  </uni-col>
			  <uni-col :span="24" style="margin-top: 20rpx;">
				  <view class="wallet" style="padding: 40rpx 20rpx;" @click="onTokenJump('/pages/about/help')">
				  	 <image class="i" src="/static/images/m6.png" fit="cover"></image>
				  	 <span class="s">{{$t('mine.text9')}}</span>
				  	 <uni-icons size="20" type="right" style="float: right;"></uni-icons>
				  	 <view style="clear: both;"></view>
				  </view>
			  </uni-col>
			  <uni-col :span="24" style="margin-top: 20rpx;">
				  <view class="wallet" style="padding: 40rpx 20rpx;" @click="onTokenJump('/pages/about/index')">
				  	 <image class="i" src="/static/images/m3.png" fit="cover"></image>
				  	 <span class="s">{{$t('mine.text10')}}</span>
				  	 <uni-icons size="20" type="right" style="float: right;"></uni-icons>
				  	 <view style="clear: both;"></view>
				  </view>
			  </uni-col>
			</uni-row>
		</view>
		<zNavigation></zNavigation>
	</view>
</template>

<script>
	import zNavigation from '@/components/module/navigation.vue';
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		components: {
			zNavigation
		},
		data() {
			return {
				islogin: false,
				noticeCount: 0,
				identity: '',
				user:{
					noticeTotal: 0,
					money: 0.0000,
					score: 0.0000,
					avatar: '/static/images/tx.png',
					username: '',
					id: '',
					role_id: 1,
				}
			}
		},
		computed: {
			...mapState(['userInfo'])
		},
		//第一次加载
		onLoad(e) {
			// if(this.userInfo.token === typeof(undefined) || this.userInfo.token === undefined){
			// 	this.islogin = false;
			// }else{
			// 	this.islogin = true;
			// 	this.user.money = parseFloat(this.userInfo.money);
			// 	this.user.score = parseFloat(this.userInfo.score);
			// 	this.user.username = this.userInfo.username;
			// 	this.user.id = this.userInfo.id;
			// 	if(this.userInfo.avatar !== '' && this.userInfo.avatar != null){
			// 		this.user.avatar = this.userInfo.avatar;
			// 	}
			// }
			// this.$http.get('/api/role/detail?lang='+this.$i18n.locale).then(res => {
			// 	if(res.code == 0){
			// 		this.user.role_id =  res.data.id;
			// 	}
			// });
			
		},
		created() {
			uni.hideTabBar()
		},
		onShow(){
			uni.showLoading({
				title: this.$t('loading')
			})
			if(this.userInfo.token === typeof(undefined) || this.userInfo.token === undefined){
				this.islogin = false;
				uni.hideLoading();
			}else{
				this.islogin = true;
				this.islogin = true;
				this.user.money = parseFloat(this.userInfo.money);
				this.user.score = parseFloat(this.userInfo.score);
				this.user.username = this.userInfo.username;
				this.user.id = this.userInfo.id;
				if(this.userInfo.avatar !== '' && this.userInfo.avatar != null){
					this.user.avatar = this.userInfo.avatar;
				}
				this.getnotice();
				this.$http.get('/api/role/detail?lang='+this.$i18n.locale).then(res => {
					if(res.code == 0){
						this.user.role_id =  res.data.id;
						uni.hideLoading();
					}
				}).catch(err => {
					uni.hideLoading()
				});
			};
			
		},
		methods: {
			getnotice(){
				let data = {
					category_id: 10,
					page: 1,
					limit: 20,
					lang: this.$i18n.locale
				}
				this.$http.post('/api/article/list', data).then(res => {
					if(res.code == 0){
						let newList = res.data.data.filter(item => item.is_read == 0);
						this.noticeCount = newList.length;
					}
				});
			},
			onPageJump(url) {
				uni.navigateTo({
					url: url
				});
			},
			onTokenJump(url) {
				if(this.userInfo.token === typeof(undefined) || this.userInfo.token === undefined){
					uni.showModal({
						title: this.$t('gotoLogin.title'),
						content: this.$t('gotoLogin.content'),
						confirmText: this.$t('gotoLogin.login'),
						cancelText: this.$t('gotoLogin.cancel'),
						success: (res) => {
							if (res.confirm) {
								uni.navigateTo({
									url: "/pages/mine/login"
								});
							}
						}
					});
				}else{
					uni.navigateTo({
						url: url
					});
				}
			},
			onTokenJump1(url) {
				if(this.userInfo.token === typeof(undefined) || this.userInfo.token === undefined){
					uni.showModal({
						title: this.$t('gotoLogin.title'),
						content: this.$t('gotoLogin.content'),
						confirmText: this.$t('gotoLogin.login'),
						cancelText: this.$t('gotoLogin.cancel'),
						success: (res) => {
							if (res.confirm) {
								uni.navigateTo({
									url: "/pages/mine/login"
								});
							}
						}
					});
				}else{
					uni.switchTab({
						url: url
					});
				}
			},
			copy(val = ''){
				// #ifdef APP-PLUS
				uni.setClipboardData({
				    data: val, // e是你要保存的内容
				    success: function () {
						uni.showToast({
							title:this.$t('copySuccess'),
							icon:'none'
						})
				    }
				})
				// #endif
				// #ifdef H5
				this.$copyText(val).then(res => {
					uni.showToast({title: this.$t('copySuccess'), icon: 'none'});
				});
				// #endif
			},
		}
	}
</script>

<style scoped>
	.uni-page-body{background-color: #F8F8F8 !important;}
	.page{min-height: 93vh;position: relative; background-color: #F8F8F8;}
	.minebg{
		width: 100vw;
		min-height: 93vh;
		background: url('/static/images/minebg.png') #F8F8F8;;
		background-size: 100%;
		background-repeat: repeat-x;
		font-family: Poppins, Poppins;
	}
	.minebg .v1{
		float: right; padding-right: 20upx;
	}
	.minebg .v2{
		clear: both; width: 90vw; margin: auto;
	}
	.minebg .v2 .login{
		width: 300upx; float: left; font-size: 16pt; font-weight: 700; height:160upx; line-height: 160upx;
	}
	.minebg .v2 .login1{
		width: 65%; float: left; font-size: 16pt; font-weight: 700; height:160upx; line-height: 60upx; padding-top: 40rpx;
	}
	.minebg .v2 .login1 .s{
		overflow: hidden; white-space: nowrap; text-overflow: ellipsis; width: 440rpx; display: block;
	}
	.minebg .v2 .login1 .i{
		width: 24rpx; height: 24rpx; float:left; margin-top: 16rpx; margin-left: 10rpx;
	}
	.minebg .v3{
		width: 94vw; height: 120upx; background-color:#333; margin: 20upx auto; border-radius: 30upx;
	}
	.minebg .v3 .dj{
		background: url('/static/images/hybg.png'); background-size: 100%; height: 120upx; border-radius: 30upx;
	}
	.minebg .v3 .dj .sj{
		width: 53%; float: left; padding-top: 25upx;
	}
	.minebg .v3 .dj .sj3{
		width: 28%; float: left; padding-top: 35upx;
	}
	.minebg .b{
		width: 160rpx; height: 60rpx; 
		background: linear-gradient( 270deg, #F8E0D3 0%, #FFAF85 100%); 
		border-radius: 12rpx;
		font-family: Poppins, Poppins;
		font-weight: bold;
		font-size: 26rpx;
		color: #610855;
		line-height: 60rpx;
		text-align: center;
		font-style: normal;
		text-transform: none;
		padding: 0rpx;
	}
	.minebg .v3 .dj .sj1{
		width: 100%; height: 42rpx; font-family: Poppins, Poppins; font-weight: 700; font-size: 26rpx; line-height: 40rpx; text-align: left; color: #F8E1D6;
	}
	.minebg .v3 .dj .sj2{
		width: 100%; height: 42rpx; font-family: Poppins, Poppins; font-weight: 400; font-size: 24rpx; line-height: 40rpx; text-align: left; color: #A7A8B4;
	}
	.minebg .v4{
		width: 94vw;margin: 20upx auto; border-radius: 30upx;
	}
	.minebg .v4 .wallet{
		background-color: #fff; border-radius: 20rpx; padding: 20rpx 30rpx;
	}
	.minebg .v4 .wallet .title{
		font-weight: 500; font-size: 28rpx; color: #999999; line-height: 36rpx;
	}
	.minebg .v4 .wallet .num{
		width: 100%; line-height: 80rpx; margin-top: 10rpx; font-size: 36rpx; background: url('/static/images/109.png'); background-size: 35%; height: 80rpx; background-repeat: no-repeat;background-position:right bottom
	}
	.minebg .v4 .wallet .num1{
		width: 100%; line-height: 80rpx; margin-top: 10rpx; font-size: 36rpx; background: url('/static/images/4.png'); background-size: 35%; height: 80rpx; background-repeat: no-repeat;background-position:right bottom
	}
	.minebg .v4 .wallet .s{
		font-weight: 500;font-size: 32rpx;color: #3D3D3D;line-height: 40rpx; float: left; margin-left: 20rpx;
	}
	.minebg .v4 .wallet .i{
		width: 40rpx; height: 36rpx; float: left;
	}
	.item{
		margin: 0upx 20upx;
	}
</style>
