<template>
	<el-layout class="container">
		<view class="top-wrap">
			<el-status-bar :customStyle="{ background: 'linear-gradient(90deg, #e4edf8, #cee9fd)' }"></el-status-bar>
			<view class="top-background">
				<image v-if="domain" :src="domain + '/static/mobile/ucenter/1.png'"></image>
			</view>
			<view class="top-user">
				<view class="user-box">
					<view class="avatar">
						<el-avatar @click="jump('pages/ucenter/user/user')" v-if="isLogin && user != undefined" size="60" :src="user.avatar"></el-avatar>
						<el-avatar v-if="!isLogin && site != undefined" size="60" :src="site.avatar"></el-avatar>
					</view>
					<view @click="jump('pages/ucenter/user/user')" class="user" v-if="isLogin && !isEmpty(user)">
						<view>{{ user.username }}</view>
						<view>
							<!-- <text>普通会员</text> -->
							<text v-if="!isEmpty(user.mobile)">手机：{{ user.mobile }}</text>
							<text v-else>UID: {{ user.id }}</text>
						</view>
					</view>
					<view class="user" v-else>
						<view @click="navigateTo('pages/user/login')">点击登录</view>
						<view>
							<text>点击登录帐号</text>
						</view>
					</view>
				</view>
			</view>
			
			<view class="m-user">
				<view class="user">
					<view class="user-info" :style="{ 'background-image': 'url('+domain+'/static/mobile/ucenter/2.png)' }">
						<view><text>普通会员</text></view>
						<view>
							<text>普通会员</text>
							<!-- <uni-icons class="user-info-icon" type="forward" size="15" color="#666"></uni-icons> -->
						</view>
					</view>
					<view class="user-info" @click="jump('pages/ucenter/share/index')" :style="{ 'background-image': 'url('+domain+'/static/mobile/ucenter/4.png)' }">
						<view><text>我的邀请</text></view>
						<view>
							<text>邀请好友</text>
							<uni-icons class="user-info-icon" type="forward" size="15" color="#666"></uni-icons>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<view class="list-wrap">
			
			<view class="order">
				<view class="content">
					<view class="content-item" @click="jump('pages/order/index?type=payment')">
						<view>
							<image :src="domain + '/static/mobile/ucenter/7.png'"></image>
							<text v-if="isLogin && user.order.payment" class="num">{{ user.order.payment }}</text>
						</view>
						<view>待付款</view>
					</view>
					<view class="content-item" @click="jump('pages/order/index?type=delivery')">
						<view>
							<image :src="domain + '/static/mobile/ucenter/8.png'"></image>
							<text v-if="isLogin && user.order.delivery" class="num">{{ user.order.delivery }}</text>
						</view>
						<view>待发货</view>
					</view>
					<view class="content-item" @click="jump('pages/order/index?type=received')">
						<view>
							<image :src="domain + '/static/mobile/ucenter/9.png'"></image>
							<text v-if="isLogin && user.order.received" class="num">{{ user.order.received }}</text>
						</view>
						<view>待收货</view>
					</view>
					<view class="content-item" @click="jump('pages/order/index?type=evaluate')">
						<view>
							<image :src="domain + '/static/mobile/ucenter/10.png'"></image>
							<text v-if="isLogin && user.order.evaluate" class="num">{{ user.order.evaluate }}</text>
						</view>
						<view>待评价</view>
					</view>
					<view class="content-item" @click="jump('pages/refund/index')">
						<view>
							<image :src="domain + '/static/mobile/ucenter/11.png'"></image>
							<!-- <text class="num">11</text> -->
						</view>
						<view>退款/售后</view>
					</view>
				</view>
			</view>
			
			<view class="wallet">
				<view class="title">
					<view>我的钱包</view>
					<view @click="jump('pages/ucenter/wallet/index')">进入钱包<uni-icons class="user-info-icon" type="forward" size="15" color="#666"></uni-icons></view>
				</view>
				<view class="content">
					<view class="content-item" @click="jump('pages/ucenter/coupon/index')">
						<view v-if="isLogin && user.coupon">{{ user.coupon }}</view>
						<view v-else>--</view>
						<view>优惠券</view>
						<view>已领优惠券</view>
					</view>
					<view class="content-item" @click="jump('pages/ucenter/point/index')">
						<view v-if="isLogin && user.score > 0">{{ user.score }}</view>
						<view v-else>--</view>
						<view>积分</view>
						<view>积分详情</view>
					</view>
					<view class="content-item" @click="jump('pages/ucenter/wallet/index')">
						<view v-if="isLogin && user.money > 0">{{ user.money }}</view>
						<view v-else>--</view>
						<view>余额</view>
						<view>我的钱包</view>
					</view>
				</view>
			</view>
			
			<view class="activity-center">
				<view class="content">
					<view class="content-item" @click="jump('pages/coupon/index')">
						<view class="l">
							<view>优惠券</view>
							<view>天天领好券 > </view>
						</view>
						<view class="r"><image :src="domain + '/static/mobile/ucenter/5.png'"></image></view>
					</view>
					<view class="content-item-line"></view>
					<view class="content-item" @click="navigateTo('pages/activity/point/index')">
						<view class="l">
							<view>积分商城</view>
							<view>前往兑换商品 > </view>
						</view>
						<view class="r"><image :src="domain + '/static/mobile/ucenter/6.png'"></image></view>
					</view>
				</view>
			</view>
			
			<view class="service">
				<view class="title">
					<view>我的服务</view>
				</view>
				<view class="content">
					<view class="content-item" @click="jump('pages/ucenter/wallet/index')">
						<view><image :src="domain + '/static/mobile/ucenter/12.png'"></image></view>
						<view>我的钱包</view>
					</view>
					<view class="content-item" @click="jump('pages/ucenter/withdraw/index')">
						<view><image :src="domain + '/static/mobile/ucenter/withdraw.png'"></image></view>
						<view>申请提现</view>
					</view>
					<view class="content-item" @click="jump('pages/ucenter/invoice/index')">
						<view><image :src="domain + '/static/mobile/ucenter/18.png?v=1'"></image></view>
						<view>我的发票</view>
					</view>
					<view class="content-item" @click="jump('pages/ucenter/visit/index')">
						<view><image :src="domain + '/static/mobile/ucenter/19.png'"></image></view>
						<view>我的足迹</view>
					</view>
					<view class="content-item" @click="jump('pages/ucenter/collect/index')">
						<view><image :src="domain + '/static/mobile/ucenter/13.png'"></image></view>
						<view>我的收藏</view>
					</view>
					<view class="content-item" @click="jump('pages/ucenter/address/index')">
						<view><image :src="domain + '/static/mobile/ucenter/14.png'"></image></view>
						<view>我的地址</view>
					</view>
					<view class="content-item" @click="jump('pages/ucenter/user/setting')">
						<view><image :src="domain + '/static/mobile/ucenter/16.png'"></image></view>
						<view>会员设置</view>
					</view>
					<view class="content-item" @click="jump('pages/ucenter/help/index')">
						<view><image :src="domain + '/static/mobile/ucenter/17.png'"></image></view>
						<view>帮助中心</view>
					</view>
				</view>
			</view>
			
		</view>
		
		<tabbar></tabbar>
	</el-layout>
</template>

<script setup>
	import { onShow } from "@dcloudio/uni-app";
	import { ref } from "vue";
	import { storeToRefs } from 'pinia';
	import { useUserStore } from "@/store/user";
	import { useAppStore } from "@/store/app";
	import { isEmpty } from "@/el-ui/libs/check";
	import { navigateTo } from "@/el-ui/libs/navigate";
	import { px2rpx } from "@/el-ui/libs/utils";
	
	const appStore           = useAppStore();
	const userStore 		 = useUserStore();
	const { isLogin,user }   = storeToRefs(userStore);
	const { site } 			 = storeToRefs(appStore);
	const domain 			 = ref("");
	const userHeight    	 = ref(280);
	
	onShow(()=>{
		userStore.getUser();
		domain.value = uni.$http.getDomain();
		userHeight.value  = 280;
		userHeight.value += px2rpx(uni.getSystemInfoSync().statusBarHeight);
		userHeight.value += 'rpx';
	});
	
	const jump = (value)=>{
		if(!isLogin.value){
			navigateTo("pages/user/login");
			return false;
		}
		
		navigateTo(value);
	}
	
</script>

<style lang="scss" scoped>
	.container { background-color: #e5edf8; }
	.top-wrap {
		position: relative;
		.top-background {
			height: 360rpx;
			overflow: hidden;
			image {
				width: 100%;
			}
		}
		.top-user {
			position: absolute;
			left: 0;
			top: 60px;
			width: 100%;
			.user-box {
				display: flex;
				align-items: center;
				width: 95%;
				margin: 0 auto;
				.user {
					padding-left: 15rpx;
					flex: 1;
					view {
						&:nth-child(1){
							color: #1D2541;
							font-weight: bold;
							font-size: 36rpx;
							padding-top: 15rpx;
						}
						&:nth-child(2){
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;
							text {
								color: #aaa;
								font-size: 25rpx;
								&:nth-child(2){
									padding-left: 10rpx;
								}
							}
						}
					}
				}
			}
		}
		.m-user {
			width: 95%;
			height: 80rpx;
			line-height: 80rpx;
			background-color: #fff;
			position: absolute;
			left: 50%;
			top: v-bind(userHeight);
			transform: translateX(-50%);
			border-radius: 6rpx;
			display: flex;
			.user {
				width: 100%;
				display: flex;
				.user-info {
					width: 100%;
					font-size: 28rpx;
					background-repeat: no-repeat;
					background-size: 21px;
					background-position: 10px center;
					view {
						display: inline-block;
						&:nth-child(1){ 
							text-indent: 40px;
							color: #333;
						}
						&:nth-child(2){ 
							font-size: 24rpx;
							color: #666;
							padding-left: 12px;
						}
					}
					.user-info-icon {
						position: relative;
						top: 1px;
					}
				}
			}
		}
	}
	
	.list-wrap {
		display: flex;
		flex-direction: column;
		align-items: center;
		
		.order {
			width: 95%;
			background-color: #fff;
			border-radius: 6rpx;
			margin-top: 20rpx;
			display: flex;
			flex-direction: row;
			justify-content: center;
			align-items: center;
			.content {
				width: 100%;
				display: flex;
				flex-direction: row;
				align-items: center;
				justify-content: center;
				padding: 10rpx 0;
				.content-item {
					width: 100%;
					display: flex;
					flex-direction: column;
					text-align: center;
					view {
						&:nth-child(1){
							position: relative;
							image {
								width: 80rpx;
								height: 80rpx;
							}
							.num {
								position: absolute;
								top: 10rpx;
								right: 38rpx;
								box-sizing: border-box;
								min-width: 32rpx;
								padding: 0 6rpx;
								color: #fff;
								font-weight: 500;
								font-size: 24rpx;
								line-height: 28rpx;
								text-align: center;
								background-color: #ee0a24;
								border: 1px solid #fff;
								border-radius: 32rpx;
								transform: translate(50%,-50%);
								transform-origin: 100%;
							}
						}
						&:nth-child(2){
							font-size: 26rpx;
							color: #666;
							position: relative;
							top: -10rpx;
						}
					}
				}
			}
		}
		
		.wallet {
			width: 95%;
			min-height: 100px;
			background-color: #fff;
			border-radius: 6rpx;
			margin-top: 20rpx;
			.title {
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				padding: 0 20rpx;
				height: 80rpx;
				line-height: 80rpx;
				border-bottom: 1px solid #f4f4f4;
				view {
					display: flex;
					&:nth-child(1){
						font-size: 30rpx;
						color: #333;
					}
					&:nth-child(2){
						font-size: 26rpx;
						color: #666;
					}
				}
			}
			.content {
				display: flex;
				flex-direction: row;
				align-items: center;
				justify-content: center;
				.content-item {
					width: 100%;
					padding: 25rpx 0;
					view {
						width: 100%;
						display: flex;
						justify-content: center;
						align-items: center;
						&:nth-child(1){
							color: #2f2f2f;
							font-size: 32rpx;
							font-weight: bold;
							padding-bottom: 5rpx;
						}
						&:nth-child(2){
							color: #2f2f2f;
							font-size: 28rpx;
							padding-bottom: 2rpx;
						}
						&:nth-child(3){
							color: #999;
							font-size: 22rpx;
						}
					}
				}
			}
		}
		
		.activity-center {
			width: 95%;
			background-color: #fff;
			border-radius: 6rpx;
			margin-top: 20rpx;
			.content {
				display: flex;
				flex-direction: row;
				align-items: center;
				.content-item-line {
					width: 1px;
					height: 30px;
					background-color: #b1afb3;
					margin: 0 10rpx;
				}
				.content-item {
					width: 99.5%;
					display: flex;
					flex-direction: row;
					justify-content: space-between;
					padding: 20rpx 20rpx;
					.l {
						view {
							&:nth-child(1){
								font-size: 29rpx;
								color: #333;
							}
							&:nth-child(2){
								font-size: 24rpx;
								color: #999;
								margin-top: 10rpx;
							}
						}
					}
					.r {
						image {
							width: 80rpx;
							height: 80rpx;
						}
					}
				}
			}
		}
		
		.service {
			width: 95%;
			min-height: 100px;
			background-color: #fff;
			border-radius: 6rpx;
			margin-top: 20rpx;
			margin-bottom: 30rpx;
			.title {
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				padding: 0 20rpx;
				height: 80rpx;
				line-height: 80rpx;
				border-bottom: 1px solid #f4f4f4;
				view {
					display: flex;
					&:nth-child(1){
						font-size: 30rpx;
						color: #333;
					}
				}
			}
			.content {
				display: flex;
				flex-wrap: wrap;
				flex-direction: row;
				padding: 10rpx 0rpx 20rpx 0rpx;
				.content-item {
					width: 25%;
					display: flex;
					flex-direction: column;
					text-align: center;
					margin-top: 10rpx;
					view {
						&:nth-child(1){
							image {
								width: 90rpx;
								height: 90rpx;
							}
						}
						&:nth-child(2){
							font-size: 26rpx;
							color: #666;
						}
					}
				}
			}
		}
	}
	
</style>
