<template>
	<view class="content">

		<RefreshView ref="mescrollRef" :pageBg="EDEDED" text="个人中心" :useUpScroll="false" :useDownScroll="false"
		  :useTitleLeftBtn="1" titleLeftBtnSource="管理" :dropLeftList="page.btnList" @drop="drop">

			<view class="top">

				<image class="touxiang" :src="page.headImage" mode="aspectFill"></image>

				<view class="top-right">
					<text class="name" @click="bind()">{{page.userNickName}}</text>
					<view style="display: flex;align-items: center;margin-right: 30rpx; margin-top: 35rpx;"
						@click="baseInfo()" v-if="!this.IsEmpty(page.loginName)">
						<text class="name2" style="flex: 1;">{{page.loginName}}</text>
						<image src="../../static/home-icon/more.png" style="width: 35rpx;height: 35rpx;"></image>
					</view>
				</view>
			</view>
			<view @click="click(2)" class="menu-item">
				<image class = "icon" src="../../static/home-icon/game.png" ></image>
				<text class="text">我的活动</text>
				<text class="explain">{{page.participateInActivityExplain}}</text>
				<image class = "more" src="../../static/home-icon/more.png" ></image>
			</view>
			<view class="line-wide"></view>
			<view @click="click(3)" class="menu-item">
				<image class = "icon" src="../../static/home-icon/game.png" ></image>
				<text class="text">我的队伍</text>
				<image class = "more" src="../../static/home-icon/more.png" ></image>
			</view>
			<view class="line-wide"></view>
			<view @click="click(4)" class="menu-item">
				<image class = "icon" src="../../static/home-icon/about.png" ></image>
				<text class="text">实名信息</text>
				<image class = "more" src="../../static/home-icon/more.png" ></image>
			</view>
			<view class="line-thin"></view>
			<view @click="click(5)" class="menu-item">
				<image class = "icon" src="../../static/home-icon/shezhi.png" ></image>
				<text class="text">设置</text>
				<image class = "more" src="../../static/home-icon/more.png" ></image>
			</view>
		</RefreshView>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page: {
					btnList: [{
							'name': '报名管理',
							'src': '../../static/game-icon/renyuanguanli.png',
							'id': 0
						}, {
							'name': '删除活动',
							'src': '../../static/game-icon/shanchu.png',
							'id': 1
						}, {
							'name': '取消关闭',
							'src': '../../static/game-icon/fanhui.png',
							'id': -1
						}],
					userNickName: "微信登录/注册",
					headImage: "http://www.ourpyw.com/upload//touxiang/default_tx.jpg",
					isRealAttestation: "",
					participateInActivityExplain: "",
					realAttestationExplain: "认证后可发布活动。未认证",
					loginName: ""
				},

			}
		},
		methods: {
			
			drop(index, isLeft, selectData) {
				let _this = this;
			
				let id = selectData.id
			
				if (id == 0) {
					// 报名管理
					uni.navigateTo({
						url: './ManagerHappyGameMembersActivity?gameSid=' + this.page.gameSid
					})
				} else if (id == 1) {
					// 删除活动
					uni.showModal({
						title: '温馨提示',
						content: '确定删除此赛事？',
						success(res) {
							if (res.confirm) {
								_this.confirm()
							}
						}
					});
				} else if (id == -1) {
					// 关闭
				}
			},
			baseInfo() {
				// 信息中心
				let _this = this
				this.Login()
					.then((res) => {
						getApp().globalData.memberSid = res
						_this.WritePreference("memberSid", res)
						getApp().globalData.isLogin = true
						// // 真实信息
						// uni.navigateTo({
						// 	url: '../info/RealMessageActivity'
						// })
						uni.navigateTo({
							url: '../user/baseInfo'
						})
					})
			},
			click(id) {
				let _this = this
				switch (id) {
					case 1:
						// 信息中心
						this.Login()
							.then((res) => {
								getApp().globalData.memberSid = res
								_this.WritePreference("memberSid", res)
								getApp().globalData.isLogin = true
								// // 真实信息
								// uni.navigateTo({
								// 	url: '../info/RealMessageActivity'
								// })
								console.log("asdasdas")
								uni.navigateTo({
									url: '../user/baseInfo'
								})
							})

						break;
					case 2:
						// 我的活动
						this.Login()
							.then((res) => {
								getApp().globalData.memberSid = res
								_this.WritePreference("memberSid", res)
								getApp().globalData.isLogin = true
								uni.navigateTo({
									url: '../games/MyGamesActivity'
								})

							})
						// uni.navigateTo({
						// 	url: '../web/WebActivity?url=' + this.putWEBExtra("https://www.ourpyw.com/hide/#/")
						// })
						break;
					case 3:
						// 我的队伍
						uni.navigateTo({
							url: "../me/myteam/CreateTeam"
						})
					case 4:
						uni.navigateTo({
							url: '../index/UserAuthentication'
						})
						// // 分享
						// this.$refs.popup.open()
						break;
					case 5:
						// 设置
						this.Login()
							.then((res) => {
								getApp().globalData.memberSid = res
								_this.WritePreference("memberSid", res)
								getApp().globalData.isLogin = true
								uni.navigateTo({
									url: '../setup/setUp'
								})

							})
						break;
				}
			},
			bind() {
				if (!this.IsEmpty(getApp().globalData.memberSid)) {
					return;
				}
				// 进入登录页面
				uni.navigateTo({
					url: '../me/Login'
				})
				// 绑定手机号
				// uni.navigateTo({
				// 	url: '../index/BindPhone?sysUserLoginAuthSid=' +
				// 		getApp().globalData.sysUserLoginAuthSid
				// })
			},
			refresh() {
				let _this = this
				if (this.IsEmpty(getApp().globalData.memberSid)) {
					_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/aosUserManagement/getMyPage/' + getApp().globalData.memberSid,
					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.$refs.mescrollRef.refreshFinished()

					}

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

				});;

			},

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

<style lang="scss">
	@import url("../../styles/master.css");
	.content {
		display: flex;
		flex-direction: column;
		height: 100%;
		background-color: #EDEDED;
		box-sizing: border-box;

		.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>
