<template>
	<view class="container">
		<view class="top">
			<view class="my">{{$t('home.d4')}}</view>
			<view class="userinfo flex">
				<view class="flex" @click="navTo('/pages/user/set/userinfo')">
					<image class="image margin-r-10" :src="userInfo.avatar || '/static/error/missing-face.png'"
						mode="scaleToFill">
					</image>
					<view class="info">
						<view class="infor margin-b-20">{{ userInfo.nickname || '游客' }}</view>
						<view class="uservip flex-start" v-if="userInfo.vip">
							<text>
							{{ userInfo.vip_name}}
							</text>
							<image class="vipIcon" :src="userInfo.vip_icon" mode="scaleToFill"></image>
						</view>
					</view>
				</view>
				<image @click="showY" class="inf" src="../../static/shouye/userinfo.png" mode="scaleToFill"></image>
			</view>
		</view>
		<!-- 余额 -->
		<view class="body">
			<template v-if="hasLogin">
				<view v-if="show" class="yue margin-b-30">
					<view class="te">
						{{$t('user.c1')}}
					</view>
					<view class="tex">
						{{userWallet}}U
					</view>
					<view class="btn flex">
						<button @click="navTo('/pages/user/money/recharge')" class="btn1"> <text>{{$t('user.a7')}}</text>
						</button>
						<button @click="navTo('/pages/user/money/withdrawal')" class="btn1"> <text>{{$t('user.a6')}}</text>
						</button>
					</view>
				</view>
				<view v-else class="yue1 margin-b-30">
					<view class="tj">{{$t('user.a1')}}</view>
					<view class="tj-item flex ">
						<view class="lj">{{$t('user.a4')}}{{$t('user.a7')}}</view>
						<view class="ljsu">{{userInfo.sum_recharge || 0}}</view>
					</view>
					<view class="tj-item flex">
						<view class="lj">{{$t('user.a4')}}{{$t('user.a6')}}</view>
						<view class="ljsu">{{userInfo.sum_extract || 0}}</view>
					</view>
					<view class="tj-item flex">
						<view class="lj">{{$t('user.a8')}}</view>
						<view class="ljsu">{{sum_win || 0}}</view>
					</view>
					<view class="tj-item flex">
						<view class="lj">{{$t('user.a9')}}</view>
						<view class="ljsu">{{sum_bet || 0}}</view>
					</view>
					<view class="tj-item flex">
						<view class="lj">{{$t('user.a10')}}</view>
						<view class="ljsu">{{group_sum_bet || 0}}</view>
					</view>
				</view>
			</template>
			<!-- 列表 -->
			<view class="gj">
				{{$t('user.b1')}}
			</view>
			<view class="user-list flex" @click="navTo('/pages/user/money/team')">
				<image src="../../static/shouye/yue.png" mode="scaleToFill" class="left-img"></image>
				<view class="item-name">
					{{$t('user.b2')}}
				</view>
				<image src="../../static/icon/back.png" mode="scaleToFill" class="right-img"></image>
			</view>
			
			<!-- 额外添加 -->
			<view class="user-list flex" @click="navTo('/pages/user/shareQrCode')">
				<image src="../../static/shouye/money.png" mode="scaleToFill" class="left-img"></image>
				<view class="item-name">
					{{$t('user.b3')}}
				</view>
				<image src="../../static/icon/back.png" mode="scaleToFill" class="right-img"></image>
			</view>
			<!-- 额外添加 -->
			<view class="user-list flex" @click="navTo('/pages/user/vip/tabulation')">
				<image src="../../static/shouye/liebiao.png" mode="scaleToFill" class="left-img"></image>
				<view class="item-name">
					{{$t('user.b4')}}
				</view>
				<image src="../../static/icon/back.png" mode="scaleToFill" class="right-img"></image>
			</view>
			<view class="user-list flex" @click="navTo('/pages/user/favorites')">
				<image src="../../static/shouye/liebiao.png" mode="scaleToFill" class="left-img"></image>
				<view class="item-name">
					{{$t('user.b5')}}
				</view>
				<image src="../../static/icon/back.png" mode="scaleToFill" class="right-img"></image>
			</view>
			<!-- <view class="user-list flex" @click="openKf()">
				<image src="../../static/shouye/liuyan.png" mode="scaleToFill" class="left-img"></image>
				<view class="item-name">
					{{$t('user.b6')}}
				</view>
				<image src="../../static/icon/back.png" mode="scaleToFill" class="right-img"></image>
			</view> -->
			<!-- <view class="user-list flex" @click="navTo('/pages/user/set/transaction')">
				<image src="../../static/shouye/jiaoyi.png" mode="scaleToFill" class="left-img"></image>
				<view class="item-name">
					{{$t('user.b7')}}
				</view>
				<image src="../../static/icon/back.png" mode="scaleToFill" class="right-img"></image>
			</view> -->
			<!-- <view class="user-list flex" @click="navTo('/pages/public/login')">
				<image src="../../static/shouye/tuichu.png" mode="scaleToFill" class="left-img"></image>
				<view class="item-name">
					{{$t('user.b8')}}
				</view>
				<image src="../../static/icon/back.png" mode="scaleToFill" class="right-img"></image>
			</view> -->
			
			 <!-- 跳转到联系客服 -->
			<view class="user-list flex" @click="nav()">
				<image src="../../static/shouye/yue.png" mode="scaleToFill" class="left-img"></image>
				<view class="item-name">
					{{$t('user.a2')}}
				</view>
				<image src="../../static/icon/back.png" mode="scaleToFill" class="right-img"></image>
			</view>
			<!-- todo -->
			<view class="user-list flex" @click="navTo('/pages/user/set/set')">
				<image src="../../static/shouye/shezhi.png" mode="scaleToFill" class="left-img"></image>
				<view class="item-name">
					{{$t('user.b9')}}
				</view>
				<image src="../../static/icon/back.png" mode="scaleToFill" class="right-img"></image>
			</view>
			
		</view>
		<taber tab='user'></taber>
	</view>
</template>
<script>
	import {
		getIndex,
	} from "@/api/index.js";
	
	import {
		gameWallet,
	} from "@/api/game.js";
	import taber from "@/components/footer/footer.vue";
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import {
		getUserInfo,
		getUser
	} from '@/api/user.js';
	import {
		saveUrl,
		interceptor
	} from '@/utils/loginUtils.js';
	export default {
		components: {
			taber
		},
		data() {
			return {
				current: 2,
				show: true,
				userWallet: 0, //余额 
				extractTotalPrice: '', //累计体现
				sum_win: '', //累计收益
				sum_bet: '', //个人交易量
				group_sum_bet: '', // 团队交易量
				user:{},
				service: ""
			};
		},
		onShow() {
			// 判断是否已经登录
			if (this.hasLogin) {
				this.getUserWallet();
				this.getUser();
			}
			this.loadBaseData();
			this.getIndex()
		},
		computed: {
			...mapState('user', [ 'hasLogin','userInfo'])
		},
		methods: {
			...mapMutations('user', ['setUserInfo']),
			showY() {
				this.show = !this.show
			},
			async getIndex() {
				const res = await getIndex()
				this.service = res.data.service		
			},
			// 统计表
			async getUser() {
				const res = await getUser();
				this.user = res.data;
				this.recharge = res.data.recharge;
				this.extractTotalPrice = res.data.extractTotalPrice;
				this.sum_win = res.data.sum_win.toFixed(2);
				this.sum_bet = res.data.sum_bet
				this.group_sum_bet = res.data.group_sum_bet
			},
			// 跳转到联系客服
			nav() {
				window.location.href = this.service
			},
			// 获取用户余额信息
			getUserWallet() {
				gameWallet().then((res) => {
					this.userWallet = +res.data.back.USDT.money.money
				})
			},
			// 加载初始数据
			loadBaseData() {
				const obj = this
				getUserInfo({})
					.then(({
						data
					}) => {
						obj.setUserInfo(data);

					})
					.catch(e => {
						console.log(e);
					});

			},
			/**
			 * 统一跳转接口,拦截未登录路由
			 * navigator标签现在默认没有转场动画，所以用view
			 */
			navTo(url) {
				if (!this.hasLogin) {
					// 保存地址
					saveUrl();
					// 登录拦截
					interceptor();
				} else {
					uni.navigateTo({
						url
					});
				}
			},
		}
	};
</script>
<style lang="scss">
	.container {
		height: 100%;
		line-height: 1;
	}

	.top {
		height: 327rpx;
		background-color: #000000;
		padding: 0 45rpx;

		.my {
			padding-top: 40rpx;
			font-size: 48rpx;
			font-weight: 500;
			color: #FFFFFF;
		}

		.userinfo {
			padding-top: 40rpx;

			.image {
				border-radius: 100rpx;
				overflow: hidden;
				width: 125rpx;
				height: 125rpx;
			}

			.info {
				.infor {
					font-size: 30rpx;
					font-weight: 500;
					color: #FFFFFF;
				}
				.vipIcon{
					width: 40rpx;
					height: 40rpx;
					margin-left: 10rpx;
				}
				.uservip {
					font-size: 20rpx;
					font-weight: 500;
					color: #93794B;
				}
			}
		}
	}

	.inf {
		margin-top: 25rpx;
		width: 48rpx;
		height: 48rpx;
	}

	//  body
	.body {
		background-color: #191a1f;
		padding: 30rpx;
		border-top-right-radius: 60rpx;
		border-top-left-radius: 60rpx;
		color: #FFFFFF;

		.yue {
			border-radius: 60rpx;
			background-color: #000000;
			text-align: center;
			padding-top: 40rpx;
			padding-bottom: 35rpx;

			.te {
				font-size: 26rpx;
				font-weight: 500;
				padding-bottom: 30rpx;
			}

			.tex {
				font-size: 48rpx;
				font-weight: bold;
				padding-bottom: 50rpx;
			}

			.btn {
				padding: 0 50rpx;

				.btn1 {
					min-width: 270rpx;
					background: #FDB242;
					border-radius: 10rpx;
					font-size: $font-base;
				}
			}
		}

		.yue1 {
			background-color: #000000;
			padding: 30rpx;
			color: #FFFFFF;
			border-radius: 60rpx;

			.tj {
				font-size: 30rpx;
				font-weight: bold;
				text-align: center;
			}

			.tj-item {
				padding-top: 26rpx;
				font-size: 24rpx;
				opacity: 0.65;
			}
		}
	}

	.gj {
		margin-left: 20rpx;
		padding-top: 10rpx;
		font-size: 36rpx;
		font-weight: bold;
		color: #FFFFFF;
		padding-bottom: 10rpx;
	}

	.user-list {
		background: #191a1f;
		box-shadow: 0px 0px 20rpx 0px rgba(50, 50, 52, 0.06);
		margin: 0 auto;
		padding: 30rpx 25rpx;
		border-bottom: 1px solid rgba(240, 240, 240, 0.2);

		.left-img {
			width: 40rpx;
			height: 40rpx;
			margin-right: 20rpx;
		}

		.item-name {
			flex-grow: 1;
			font-size: 29rpx;
			font-weight: bold;
			color: #FFF;
		}

		.right-img {
			width: 18rpx;
			height: 27rpx;
		}
	}
</style>