<template>
	<view>
		<view class="top-cont">
			<image class="bg" src="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/bg_mine.png" mode="widthFix"></image>
			<view class="top-inner">
				<!-- 这里是状态栏 -->
				<view class="status_bar" :style="{height: statusBarHeight}"></view>
				<view class="content">
					<view class="user-info">
						<view class="left">
							<view class="head-img">
								<image :src="userInfo.avatar?userInfo.avatar:'https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/my_heads_icon.png'"
									mode="aspectFill">
								</image>
								<image class="gender"
									:src="isGirl==null?'https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/icon_girl.png':'https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/icon_boy.png'"
									mode="aspectFill"></image>
							</view>
							<view class="name-phone">
								<view class="x-f">
									<view class="name" v-if="UserInfo">{{userInfo.nickName||'未命名'}}</view>
									<view class="name" v-else>请先登录</view>
									<view class="lable" v-if="UserInfo.deptName">{{userInfo.deptName}}</view>
								</view>
							</view>
							<view class="txt" v-if="UserInfo">您已加入小蜜蜂{{joinDays||'0'}}天了~</view>
						</view>
					</view>

					<view class="task-list">
						<view class="item" v-for="(item,index) in tabs" :key="index" @click="openLink(item)">
							<view class="left">
								<image :src="item.icon" mode=""></image>
								<view class="title-l">{{item.name||''}}</view>
							</view>
							<view class="right">
								<image src="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/icon_my_more.png" mode=""></image>
							</view>
						</view>
					</view>

				</view>
			</view>
		</view>
	</view>
</template>

<script>
	
	import {
		getUserInfo
	} from '@/api/user'
	export default {
		data() {
			return {
				isGirl: false,
				count0: 0,
				count1: 0,
				count2: 0,
				afterSalesCount: 0,
				tabs: [
					{
						name: '个人信息',
						num: 3,
						icon: 'https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/icon_my_information.png',
						url: '/pages_user/userInfo'
					},
					{
						name: '设置中心',
						num: 8,
						icon: 'https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/icon_my_set.png',
						url: '/pages/auth/setting'
					},
				],
				userInfo: {},
				user: {
					isPromoter: 0,
					isWeixinAuth: 0,
					phone: "",
					nickname: "用户昵称",
					avatarUrl: "/static/images/detault_head.png"
				},
				// 状态栏的高度
				statusBarHeight: uni.getStorageSync('menuInfo')?.statusBarHeight || '0px',
				// 消息数量
				msgNum: 0,
				isShow: true,
				UserInfo: uni.getStorageSync('AppToken')
			};
		},
		onLoad() {
			console.log("onload")
		},
		onShow() {
			console.log("onshow")
			// 从本地缓存加载用户信息
			const userInfo = uni.getStorageSync('userInfo')
			if (userInfo) {
				this.userInfo = typeof userInfo === 'string' ? JSON.parse(userInfo) : userInfo
			}
			// 更新登录状态
			this.UserInfo = uni.getStorageSync('AppToken')
		},
		onReachBottom() {
			console.log("onReachBottom")
			if (this.$refs.product) {
				this.$refs.product.getGoodsProducts();
			}
		},
		methods: {
			seeChange() {
				this.isShow = !this.isShow
			},
			callService() {
				uni.makePhoneCall({
					phoneNumber: "4000717770",
					success: function() {
						console.log('拨打电话成功');
					},
					fail() {
						console.log('打电话失败了');
					}
				})
			},

			

			openLink(item) {
				if (item.name == '用户协议') {
					this.openH5()
					return;
				}
				uni.navigateTo({
					url: item.url
				})
			},
			toManager() {
				if (this.utils && this.utils.checkCompanyUserLoginState) {
					if (this.utils.checkCompanyUserLoginState()) {
						uni.navigateTo({
							url: '/pages_company/index'
						})
					} else {
						uni.navigateTo({
							url: '/pages_company/auth/login'
						})
					}
				}
			},
			openH5(url) {
				var requestPath = uni.getStorageSync('requestPath');
				uni.setStorageSync('url', requestPath + url);
				uni.navigateTo({
					url: '../home/web'
				})
			},
			getUserInfo() {
				getUserInfo().then(
					res => {
						if (res.code == 200) {
							if (res.user != null) {
								this.user = res.user;
							} else {
								if (this.utils && this.utils.loginOut) {
									this.utils.loginOut();
								}
							}

						} else {
							uni.showToast({
								icon: 'none',
								title: "请求失败",
							});
						}
					},
					rej => {}
				);
			},
			// 跳转页面
			navgetTo(url) {
				if (this.utils && this.utils.isLogin) {
					this.utils.isLogin().then(res => {
						if (res) {
							uni.navigateTo({
								url: url + '?userId=' + this.user.userId
							})
						}
					})
				}
			},
			// 查看订单
			showOrder(status) {
				uni.navigateTo({
					url: '/pages_user/user/storeOrder?status=' + status
				})
			}
		},
		computed: {
			joinDays() {
				if (!this.userInfo.createTime) return 0
				const createDate = new Date(this.userInfo.createTime.replace(/-/g, '/'))
				const now = new Date()
				const diffTime = now - createDate
				const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24))
				return diffDays
			}
		}
	}
</script>

<style lang="scss">
	.top-cont {
		width: 100%;
		height: 600rpx;
		position: relative;

		.bg {
			width: 100%;
			position: absolute;
			top: 0;
			left: 0;
		}

		.top-inner {
			width: 100%;
			height: 100%;
			position: absolute;
			top: 0;
			left: 0;
			z-index: 2;
		}
	}
	.content {
		background: linear-gradient(360deg, rgba(244, 249, 255, 0.6) 0%, #FFFFFF 100%);
		border-radius: 40rpx 40rpx 24rpx 24rpx;
		border: 2rpx solid #FFFFFF;
		margin-top: 222upx;
		align-items: center;
		justify-content: center;
		position: relative;

		.user-info {
			position: relative;
			top: -72rpx;
			left: 46rpx;
			z-index: 4;

			.left {
				position: relative;
				display: flex;
				flex-direction: column;

				.head-img {
					width: 112upx;
					height: 112upx;
					border-radius: 50%;
					margin-right: 32upx;
					border: 4upx solid #FFFFFF;
					position: relative;

					image {
						width: 112upx;
						height: 112upx;
						border-radius: 50%;
					}

					.gender {
						width: 36rpx;
						height: 36rpx;
						position: absolute;
						right: 0;
						bottom: 0;
					}
				}

				.name-phone {
					display: flex;
					align-items: flex-start;
					flex-direction: column;
					justify-content: space-around;
					margin-top: 30rpx;

					.name {
						font-size: 40upx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #111111;
						line-height: 1;
					}

					text {
						font-family: PingFang SC, PingFang SC;
						font-weight: 600;
						font-size: 28rpx;
					}

					.lable {
						padding: 4rpx 16rpx;
						font-weight: 500;
						font-size: 22rpx;
						color: #FFFFFF;
						background: #FAAB0C;
						margin-left: 18rpx;
						border-radius: 38rpx 38rpx 38rpx 38rpx;
					}

					.phone {
						width: 220rpx;
						height: 48rpx;
						margin-top: 30upx;
						background: linear-gradient(90deg, #FEA501 0%, #FECB8A 100%);
						border-radius: 24rpx 24rpx 24rpx 24rpx;
						border: 1rpx solid #FEDDB9;
						display: flex;
						align-items: center;
						justify-content: center;

						text {
							font-size: 24upx;
							font-family: PingFang SC;
							font-weight: 500;
							color: #fff;
							line-height: 1;
							margin-left: 4rpx;
						}

					}

				}

				.txt {
					font-size: 28rpx;
					color: #666666;
					margin-top: 12rpx;
				}
			}

			.right {
				display: flex;
				align-items: center;
				justify-content: center;


				.set {

					width: 48rpx;
					height: 48rpx;

				}
			}
		}

		.task-list {
			display: flex;
			align-items: center;
			flex-direction: column;
			justify-content: flex-start;
			width: 100%;

			.item {
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 28rpx 24rpx;
				box-sizing: border-box;
				.left {
					display: flex;
					align-items: center;
					justify-content: center;

					image {
						width: 48rpx;
						height: 48rpx;
						margin-right: 32rpx;
					}

					.title-l {
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 32rpx;
						color: #333333;
					}
				}

				.right {
					display: flex;
					align-items: center;

					.num {
						text-align: center;
						width: 50rpx;
						height: 36rpx;
						line-height: 36rpx;
						background: rgba(56, 139, 255, 0.16);
						border-radius: 34rpx 34rpx 34rpx 34rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 24rpx;
						color: #388BFF;
					}

					image {
						width: 32rpx;
						height: 32rpx;
						margin-left: 12rpx;
					}
				}
			}
		}

		.used-tools {
			box-sizing: border-box;
			background: #FFFFFF;
			border-radius: 16upx;
			padding: 40upx 30upx;

			.title {
				font-size: 36upx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #222222;
				line-height: 1;
			}

			.tools-list {
				margin-top: 50upx;
				display: flex;
				flex-wrap: wrap;
				width: 100%;

				.item {
					box-sizing: border-box;
					width: 25%;
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;
					margin-bottom: 50upx;
					position: relative;

					image {
						width: 48upx;
						height: 48upx;
					}

					.text {
						font-size: 24upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #333;
						line-height: 1;
						margin-top: 20upx;
					}

					.contact-btn {
						display: inline-block;
						position: absolute;
						top: 0;
						left: 0;
						width: 100%;
						height: 100%;
						opacity: 0;
					}
				}
			}
		}

		.log-out {
			height: 88upx;
			line-height: 88upx;
			text-align: center;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #666666;
			background: #FFFFFF;
			border-radius: 16upx;
			margin-top: 52upx;
		}
	}

	.sub-btn {
		position: absolute;
		width: 100%;
		height: 100%;
		opacity: 0;
	}

	.like-product {
		padding: 0 20rpx;

	}

	.banner {
		padding: 20rpx 20rpx 0rpx 20rpx;
		height: 200rpx;
		position: relative;
		display: flex;
		align-items: center;
		justify-content: center;

		image {
			width: 100%;
			height: 100%;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
		}

		.tel_btn {
			width: 100%;
			height: 100%;
			top: 0upx;
			position: absolute;
			opacity: 0.0;
		}
	}
</style>