<template>
	<view class="full-container">
		<uni-nav-bar id="nav-bar" status-bar="true"  @clickLeft="onBack()"
		 title="我的" color="#000000" fixed="true" :border="false">
			<view slot="left">
				<view class=" flex align-center margin-left">
					<image class="p-left-arrow" src="../../../static/p-left-arrow.png"></image>
				</view>
			</view>
		
		</uni-nav-bar>
		<!-- <view class="cu-bar ">
			<view class="action">
			</view>
			<view class="action">
				<text class="text-df text-purple" @tap="onNavUser">编辑</text>
			</view>
		</view> -->
		<image class="bg-image" src="../../../static/loginBg.png" mode="aspectFill"></image>
		<view class="card-view flex align-center " style="position: relative; margin-top: 113px;">
			<view class="avatar-size">
				<image class="avatar-img round" :src="avatarUrl"></image>
			</view>
			<view class="avatar-group text-upload">
				<view class="text-lg flex justify-between align-center justify-center">
					<text class="text-black text-bold">{{userName}}</text>
					<text class="text-black">达标{{days}}天</text>
				</view>
				<!-- <view class="text-xs padding-top">
					<text class="text-black">{{days}}</text>
				</view> -->
				<view class="text-gray padding-top">{{signature}}</view>
			</view>

			<view class="only-arrow" @tap="onNavUser"></view>

		</view>





		<view class="card-view article ">
			<view class="title">
				最近在玩
			</view>
			<view class="cu-item shadow">
				<view class="cu-form-group margin-top">
					<view v-if="playGames.length!=0" class="grid col-3 homepage-grid-square flex-sub ">
						<view v-for="(item,index) in playGames" :key="index" v-if="index<6" @tap="onViewImage(item)">
							<image class="item-img" :src="item.gameIcon" mode="aspectFill"></image>
							<view class="border text-center text-cut">{{item.gameName}}</view>
						</view>
					</view>
					<view v-else class="text-center text-gray" :style="{width:'100%'}">去玩吧~</view>
					<view v-if="playGames.length!=0" class="homepage-arrow" @tap="onNavList('recently')"></view>
				</view>
			</view>
		</view>
		<view v-if="favoriteGames.length==0" class="card-view flex align-center">
			<view class="content flex flex-direction align-start margin-top">
				<view class="title">关注</view>
				<view class="text-grey" style="margin: 0rpx 40rpx 40rpx;">有好多好玩的视频等着你关注哦</view>
			</view>
			<view class=" margin-sm button-fav " @tap="onGoToFollow">
				<image style="width: 21px;height: 21px; margin-right: 12rpx;" src="../../../static/add_w.png"></image>
				去关注
			</view>
		</view>
		<view v-else class="card-view article">
			<view class="title">
				已关注的
			</view>
			<view class="cu-item shadow">
				<view class="cu-form-group margin-top">
					<view v-if="favoriteGames.length!=0" class="grid col-3 homepage-grid-square flex-sub ">
						<view  class="text-center "  v-for="(item,index) in favoriteGames" :key="index" v-if="index<6" @tap="onViewImage(item)">
							<image class="item-img" :src="item.gameIcon" mode="aspectFill"></image>
							<view class="border text-cut">{{item.gameName}}</view>
						</view>
					</view>
					<view v-else class="text-center text-gray" :style="{width:'100%'}">去关注更多的游戏吧~</view>
					<view v-if="favoriteGames.length!=0" class="homepage-arrow" @tap="onNavList('watchGame')"></view>
				</view>
			</view>
		</view>
		
		<view class="homepage-action-row">
			<view class=" ">哔蹦</view>
			<view class="text-bold text-decoration" style="
		color: #007AFF; border-bottom: solid 1rpx #007AFF;" @tap="onSwitchAgree('agreement')">用户协议</view>
			<view class=" ">和</view>
			<view class="text-bold text-decoration" style="
		color: #007AFF; border-bottom: solid 1rpx #007AFF;" @tap="onSwitchAgree('privacy')">隐私政策</view>
		</view>
	</view>
</template>

<script>
	import config from '../../../common/config.js';
	import reqUtil from "@/util/util-js/requstUtil.js";
	import {
		mapState
	} from 'vuex'

	export default {
		computed: mapState(['forcedLogin', 'hasLogin', 'userName', 'avatarUrl', 'playGames', 'favoriteGames', 'days',
			'signature','platform','gamePlatform'
		]),
		onLoad() {
			let that = this;
			reqUtil.requestData(config.URL.RECENTLYPLAYINGGETBYPLATFORM).then(res => {
					console.log('RECENTLYPLAYINGGETBYPLATFORM =====', res);
					if (res.code == 0) {
						that.$store.state.playGames = res.data.gameList;
					}

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

			reqUtil.requestData(config.URL.FAVORITESGETBYPLATFORM).then(res => {
					console.log('FAVORITESGETBYPLATFORM =====', res);
					if (res.code == 0) {
						that.$store.state.favoriteGames = res.data.gameList;
					}

				},
				e => {
					console.log(e)
				});
		},
		methods: {
			onViewImage(item) {
				let temItem = encodeURIComponent(JSON.stringify(item));
				uni.navigateTo({
					url: "../../game-page/game-detail/game-detail?item=" + temItem
				})
			},
			onNavUser() {
				uni.navigateTo({
					url: '../userInfo/userInfo'
				});
			},
			onNavList(type) {
				if (type == "recently" && this.playGames.length == 0) {
					uni.showModal({
						title: "提示",
						content: "没有最近在玩的游戏数据"
					})
					return;
				} else if (type == "watchGame" && this.favoriteGames.length == 0) {
					uni.showModal({
						title: "提示",
						content: "没有关注的游戏数据"
					})
					return;
				}


				uni.navigateTo({
					url: '../../personal-page/list/list?type='+type
				});
			},
			onGoToFollow() {
				// uni.showModal({
				// 	title: "提示",
				// 	content: "功能尚未开放"
				// })
				uni.navigateTo({
					url: '../../game-page/game/game'
				});
			},
			onBack(){
				uni.navigateBack({
					delta:1
				})
			},
			onSwitchAgree(data) {
				uni.navigateTo({
					url: "../../login-page/userAgreement/userAgreement?type=" + data
				})
			},
		}
	}
</script>

<style>
	.avatar-group {
		display: flex;
		flex-direction: column;
		/* justify-content: center; */
		/* align-items: center; */
		text-align: start;
		background-color: #FFFFFF;
		display: block;
		border-radius: 10rpx;
		margin: 0 54rpx 0 30rpx;
		width: 100%;
	}


	.avatar-size {
		position: relative;
		margin-left: 47rpx;
		width: 140rpx;
		height: 140rpx;
		flex-shrink: 0;
	}

	.avatar-img {
		position: absolute;
		top: 0px;
		left: 0;
		width: 140rpx;
		height: 140rpx;
	}

	.text-upload {
		font-size: 13px;
		color: rgba(166, 166, 166, 1);
		padding: 40px 35rpx 40px 0;
	}

	.homepage-grid-square {
		width: 250rpx;
		/* height: 250rpx; */
		align-items: start;

	}

	.homepage-grid-square image {
		width: 176rpx;
		height: 176rpx;
	}

	.homepage-arrow {
		position: relative;
		width: 35rpx;
	}

	.homepage-arrow::before {
		position: absolute;
		top: 0;
		right: 0upx;
		bottom: 0;
		display: block;
		margin: auto;
		width: 30upx;
		height: 30upx;
		color: #8799a3;
		content: "\e6a3";
		text-align: center;
		font-size: 34upx;
		font-family: cuIcon;
		line-height: 30upx
	}

	.button-fav {
		background-color: rgba(153, 150, 252, 255);
		color: #FFFFFF;
		border-radius: 10px;
		width: 184rpx;
		height: 90rpx;
		display: flex;
		justify-content: center;
		text-align: center;
		align-items: center;
	}

	.title {
		text-align: justify;
		/* padding: 40rpx 30rpx; */
		font-size: 15px;
		position: relative;
		height: 30px;
		line-height: 60upx;
		margin: 20rpx 40rpx;
		font-weight: 400;
		color: rgba(26, 26, 26, 1);
	}

	.bg-image {
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 159px;
		opacity: 1;
	}
	
	.border{
		width: 176rpx;
		font-size: 30rpx;
		color:rgba(175, 175, 175, 1);
		font-weight: 400;
		text-align: center;
		margin-top: 22rpx;
		margin-bottom: 40rpx;
	}
	
	.item-img{
		border-radius: 20rpx;
		/* border: 1rpx solid #EEEEEE; */
		box-shadow: 0px 1px 2px 0px rgba(113, 113, 219, 0.23);
	}
	
	.homepage-action-row{
		margin-top: 25px;
		display: flex;
		flex-direction: row;
		justify-content: center;
		padding: 20px;
	}
</style>
