<template>
	<view>
		<view class="page" v-if="isLogin && !showLogoutModal">

			<view class="nologin-top-bg"
			style="margin-top: calc(var(--status-bar-height) + 20rpx);
			position: absolute;z-index: 1;">
			</view>
			

			<view class="user">
				
				<view class=""
				style="height: 120rpx;padding-top: calc(var(--status-bar-height) + 20rpx);">
				</view>
				
				<!-- 用户信息区域 -->
				<view class="user-info">
					<image class="avatar" :src="userInfo.headImage" mode="aspectFill"></image>
					<view class="info">
						<view class="name">{{ userInfo.nickName }} 
							<!-- <text class="id"> (ID: {{ userInfo.id }})</text> -->
						</view>
						<view class="desc">{{ userInfo.details || '' }}</view>
						<view class="phone">手机号：{{ userInfo.phone }}</view>
					</view>
					<!-- <view class="more">
						<uv-icon name="more-dot-fill" size="46rpx" color="#999"></uv-icon>
					</view> -->
				</view>
				
				<!-- 图片区域 -->
				<view class="section">
					<view class="section-title">账户</view>
					<view class="section-list">
						<view class="section-item" @click="$utils.navigateTo('/pages_order/mine/Walletflow')">
							<view class="section-item-left">
								<uv-icon name="photo" size="40rpx" color="#333"></uv-icon>
								<text>钱包流水</text>
							</view>
							<uv-icon name="arrow-right" size="36rpx" color="#999"></uv-icon>
						</view>
						<!-- <view class="section-item" @click="$utils.navigateTo('/pages_order/novel/Giftbox')">
							<view class="section-item-left">
								<uv-icon name="gift" size="40rpx" color="#333"></uv-icon>
								<text>礼物盒</text>
							</view>
							<uv-icon name="arrow-right" size="36rpx" color="#999"></uv-icon>
						</view> -->
					</view>
				</view>
				
				<!-- 日常区域 -->
				<view class="section">
					<view class="section-title">日常</view>
					<view class="section-list">
						<view class="section-item" @click="$utils.navigateTo('/pages_order/comment/myComment')">
							<view class="section-item-left">
								<uv-icon name="chat" size="40rpx" color="#333"></uv-icon>
								<text>我的评论</text>
							</view>
							<view class="badge" v-if="commentNum">{{ commentNum }}</view>
							<uv-icon name="arrow-right" size="36rpx" color="#999"></uv-icon>
						</view>
						<view class="section-item" @click="$utils.navigateTo('/pages_order/novel/Translation')">
							<view class="section-item-left">
								<uv-icon name="list" size="40rpx" color="#333"></uv-icon>
								<text>任务中心</text>
							</view>
							<!-- <view class="badge">5</view> -->
							<uv-icon name="arrow-right" size="36rpx" color="#999"></uv-icon>
						</view>
					</view>
				</view>
				
				<!-- 设置区域 -->
				<view class="section">
					<view class="section-title">设置</view>
					<view class="section-list">
						<view class="section-item" @click="$utils.navigateTo('/pages_order/author/creator')">
							<view class="section-item-left">
								<uv-icon name="star" size="40rpx" color="#333"></uv-icon>
								<text v-if="userInfo.isUser == 'Y'">修改作者信息</text>
								<text v-else>申请成为作者</text>
							</view>
							<uv-icon name="arrow-right" size="36rpx" color="#999"></uv-icon>
						</view>
						
						<button open-type="contact" class="share">
							<view class="section-item">
								<view class="section-item-left">
									<uv-icon name="star" size="40rpx" color="#333"></uv-icon>
									<text>联系客服</text>
								</view>
								<uv-icon name="arrow-right" size="36rpx" color="#999"></uv-icon>
							</view>
						</button>
						
						<view class="section-item" @click="$utils.navigateTo('/pages_order/auth/Modifyinformation')">
							<view class="section-item-left">
								<uv-icon name="edit-pen" size="40rpx" color="#333"></uv-icon>
								<text>修改信息</text>
							</view>
							<uv-icon name="arrow-right" size="36rpx" color="#999"></uv-icon>
						</view>
						<view class="section-item" @click="$store.commit('logout')">
							<view class="section-item-left">
								<uv-icon name="star" size="40rpx" color="#333"></uv-icon>
								<text>退出登录</text>
							</view>
							<uv-icon name="arrow-right" size="36rpx" color="#999"></uv-icon>
						</view>
					</view>
				</view>
			</view>

		</view>
		
		
		<view v-else-if="!isLogin" class="nologin-page">
			<view class="nologin-top-bg">
				<view class="nologin-header">
					<image class="nologin-avatar" src="/static/image/center/headImage.png" mode="aspectFill" @click="$utils.toLogin" />
					<view class="nologin-text" @click="$utils.toLogin">点击登录</view>
				</view>
				<view class="nologin-header-right">
					<uv-icon name="more-dot-fill" size="40rpx" color="#bbb"></uv-icon>
				</view>
			</view>
			<view class="nologin-content-center">
				<button class="nologin-btn" @click="$utils.toLogin">立即登录</button>
				<view style="font-size: 24rpx;color: #999;">暂未登录，请先登录</view>
			</view>
		</view>
		
		<tabber select="center" />
	</view>
</template>

<script>
	import tabber from '@/components/base/tabbar.vue'
	import uvIcon from '@/uni_modules/uv-icon/components/uv-icon/uv-icon.vue'
	export default {
		components: {
			tabber,
			uvIcon,
		},
		data() {
			return {
				commentNum : 0,
			}
		},
		onShow() {
			if(this.isLogin){
				this.$store.commit('getUserInfo')
				this.getMyCommentNum()
			}
		},
		methods: {
			async getMyCommentNum(){
				this.commentNum = await this.$fetch('getMyCommentNum')
			},
		}
	}
</script>

<style scoped lang="scss">
	.page {
		background-color: #f5f5f5;
	}

	.user {
		padding: 20rpx 30rpx;
		position: relative;
		z-index: 2;
		.user-info {
			display: flex;
			align-items: center;
			padding: 30rpx 20rpx;
			// background: linear-gradient(135deg, #e8e6fa 0%, #fbeff3 100%);
			border-radius: 20rpx;
			margin-bottom: 20rpx;
			
			.avatar {
				width: 120rpx;
				height: 120rpx;
				border-radius: 50%;
				margin-right: 20rpx;
			}
			
			.info {
				flex: 1;
				
				.name {
					font-size: 32rpx;
					font-weight: bold;
					margin-bottom: 10rpx;
					
					.id {
						font-size: 24rpx;
						font-weight: normal;
						color: #999;
					}
				}
				
				.desc {
					font-size: 26rpx;
					color: #666;
					margin-bottom: 10rpx;
				}
				
				.phone {
					font-size: 26rpx;
					color: #666;
				}
			}
			
			.more {
				padding: 10rpx;
			}
		}
		
		.section {
			margin-bottom: 20rpx;
			
			.section-title {
				font-size: 28rpx;
				color: #999;
				padding: 20rpx 10rpx 10rpx;
			}
			
			.section-list {
				background-color: #fff;
				border-radius: 20rpx;
				overflow: hidden;
				
				.section-item {
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding: 30rpx 20rpx;
					border-bottom: 1px solid #f5f5f5;
					
					&:last-child {
						border-bottom: none;
					}
					
					.section-item-left {
						display: flex;
						align-items: center;
						
						text {
							margin-left: 20rpx;
							font-size: 28rpx;
						}
					}
					
					.badge {
						background-color: #FA5A0A;
						color: #fff;
						font-size: 22rpx;
						padding: 2rpx 12rpx;
						border-radius: 20rpx;
						margin-right: auto;
						margin-left: 20rpx;
					}
				}
			}
		}
	}

	.nologin-page {
		background: #fff;
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
		position: relative;
	}
	.nologin-top-bg {
		width: 100vw;
		height: 580rpx;
		background: linear-gradient(180deg, #f3eafe 0%, #f5f5f5 100%);
		position: relative;
		z-index: 2;
		display: flex;
		flex-direction: row;
		align-items: flex-start;
		justify-content: flex-start;
	}
	.nologin-header {
		display: flex;
		flex-direction: row;
		align-items: center;
		margin-left: 36rpx;
		margin-top: 218rpx;
		
	}
	.nologin-avatar {
		width: 80rpx;
		height: 80rpx;
		border-radius: 50%;
		background: #eee;
		margin-right: 18rpx;
	}
	.nologin-text {
		font-size: 28rpx;
		color: #000;
		font-weight: 900;
	}
	.nologin-header-right {
		position: absolute;
		right: 36rpx;
		top: 48rpx;
	}
	.nologin-content-center {
		position: fixed;
		top: 50%;
		left: 0;
		width: 100vw;
		display: flex;
		flex-direction: column;
		align-items: center;
		transform: translateY(-50%);
		z-index: 2;
	}
	.nologin-btn {
		width: 380rpx;
		height: 74rpx;
		background: #132a57;
		color: #fff;
		font-size: 28rpx;
		border-radius: 38rpx;
		margin-bottom: 18rpx;
		font-weight: bold;
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>