<template>	
	<view>
		<RefreshView ref="mescrollRef" :pageBg="EDEDED" text="" :useUpScroll="false" :useDownScroll="false" text="个人中心">
			<view class="top" @click="toBaseInfo()">
				<image class="touxiang" :src="page.headImage" mode="aspectFill"></image>
				<view class="top-right">
					<text class="name" >{{page.userNickName}}</text>
					<view style="display: flex;align-items: center;margin-right: 30rpx; margin-top: 35rpx;"
						 v-if="!this.IsEmpty(page.loginName)">
						<text class="name2" style="flex: 1;">{{page.loginName}}</text>
						<image src="../../static/img/public/more.png" style="width: 35rpx;height: 35rpx;"></image>
					</view>
				</view>
			</view>
			<view class="line-wide"></view>
			<view @click="toMyGamesActivity()" class="menu-item">
				<image class = "icon" src="../../static/img/personal/game.png" ></image>
				<text class="text">我的活动</text>
				<text class="explain">{{page.participateInActivityExplain}}</text>
				<image class = "more" src="../../static/img/public/more.png" ></image>
			</view>
			<view class="line-wide"></view>
			<view @click="toMyTeam()" class="menu-item">
				<image class = "icon" src="../../static/img/personal/game.png" ></image>
				<text class="text">我的队伍</text>
				<image class = "more" src="../../static/img/public/more.png" ></image>
			</view>
			<view class="line-wide"></view>
			<view @click="toRealInfo()" class="menu-item">
				<image class = "icon" src="../../static/img/personal/about.png" ></image>
				<text class="text">实名信息</text>
				<image class = "more" src="../../static/img/public/more.png" ></image>
			</view>
			<view class="line-thin"></view>
			<view @click="toSetup()" class="menu-item">
				<image class = "icon" src="../../static/img/personal/shezhi.png" ></image>
				<text class="text">设置</text>
				<image class = "more" src="../../static/img/public/more.png" ></image>
			</view>
		</RefreshView>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page: {
					userNickName: "微信登录/注册",
					headImage: "http://www.ourpyw.com/upload//touxiang/default_tx.jpg",
					isRealAttestation: "",
					participateInActivityExplain: "",
					realAttestationExplain: "认证后可发布活动。未认证",
					loginName: ""
				},
				parameter:{
					sysUserInfoSid:""
				}
			}
		},
		methods: {				
			toBaseInfo(options) {
				// 信息中心
				if (getApp().globalData.isLogin ) {
						uni.navigateTo({
							url: 'BaseInfo?sysUserSid=' + getApp().globalData.sysUserSid
						})
					}
				else{
					// 调用登陆后刷新当前页，参见麦当劳小程序
					uni.navigateTo({
						url: 'AuthLogin',
					})
				}
				return;
			},
			toMyGamesActivity(){
				// 我的活动
				if (getApp().globalData.isLogin ) {
						uni.navigateTo({
							url: '../me/MyActivity'
						})
					}
			},
			toMyTeam(){
				// 我的队伍
				if (getApp().globalData.isLogin ) {
					uni.navigateTo({
						url: "MyTeam"
					})
				}
			},
			toRealInfo(){
				if (getApp().globalData.isLogin ) {
					uni.navigateTo({
						url: 'RealInfo?sysUserSid=' + getApp().globalData.sysUserSid
					})
				}
			},
			toSetup(){
				if (getApp().globalData.isLogin ) {
					uni.navigateTo({
						url: 'Setup'
					})
				}
			},
			refresh() {
				if (getApp().globalData.isDebug) {
					console.log('用户Sid', getApp().globalData.sysUserSid)
					console.log('用户是否登陆', getApp().globalData.isLogin)
				}
				let _this = this
				if (!getApp().globalData.isLogin) {
					_this.page.userNickName = "微信登录/注册",
						_this.page.headImage = "http://www.ourpyw.com/upload//touxiang/default_tx.jpg",
						_this.page.isRealAttestation = "",
						_this.page.participateInActivityExplain = "",
						_this.page.realAttestationExplain = "认证后可发布活动。未认证",
						_this.page.loginName = ""
					return;
				}
				_this.HTTP({
					url: 'aos/v1/aosUser/getMyPage/' + getApp().globalData.sysUserSid,
					method: 'GET',
					data: {},
					paramsType: "FORM",
					loading: true
				}).then((res) => {

					console.log("我的页面初始化", res);
					if (res.code == 200) {
						_this.page = res.data
						_this.page.loginName = "用户号：" + res.data.loginName
						_this.parameter.sysUserInfoSid = res.data.sysUserInfoSid
						// 成功关闭刷新状态
						_this.$refs.mescrollRef.refreshFinished()

					}

				}, (err) => {
					// 失败重置刷新状态
					_this.$refs.mescrollRef.refreshError()

				});;

			},

		},
		onShow() {
			this.refresh()
		}
	}
</script>

<style lang="scss">
	@import url("../../static/master.css");
	.top {
		display: flex;
		flex-direction: row;
		padding-bottom: 35rpx;
		padding-top: 55rpx;
		width: 100%;
		background-color: #FFFFFF;
		box-sizing: border-box;

		.touxiang {
			width: 150rpx;
			height: 150rpx;
			border-radius: 10%;
			margin-left: 35rpx;
			margin-right: 35rpx;
			flex-shrink: 0;
		}

		.top-right {
			display: flex;
			flex-direction: column;
			flex: 1;
			box-sizing: border-box;

			.name {
				font-family: sans-serif;
				font-weight: 500;
				color: #101010;
				font-size: 40rpx;
			}

			.name2 {
				display: -webkit-box;
				-webkit-line-clamp: 1;
				overflow: hidden;
				text-overflow: ellipsis;
				-webkit-box-orient: vertical;
				word-break: break-all;
				color: #828282;
				font-size: 28rpx;
			}
		}
	}

	.user-item-bg {
		background-color: #FFFFFF;
		margin-top: 20rpx;
	}
	
</style>
