<template>
	<view class="my__main">
		<!-- 背景 -->
		<view class="my__main-top">
		</view>
		<view class="top-content">
			<image class="top-content-img" src="../../static/card.png" mode=""></image>
			<view class="top-content-main">
				<view class="content-main-id">
					<p>{{userInfo.userType==0? '巡更员':'管理员'}}</p>
				</view>
				<view v-if="!userInfo" class="content-main-text1">
					请先登录~
				</view>
				<view v-else class="content-main-text2">
					<view class="main-text2-1">
						{{userInfo.idName}}
					</view>
					<view class="main-text2-2">
						{{userInfo.username}}
					</view>
				</view>
			</view>
		</view>
		<view v-if="userInfo" class="my__main-content-box">
			<view v-if="userInfo.userType==0" class="my__main-content">
				<u-cell-group :border="false">
					<u-cell :border="false" title="签到打卡" isLink url="/pages/home/home"></u-cell>
				</u-cell-group>
			</view>
			<view v-else class="my__main-content">
				<u-cell-group :border="false">
					<u-cell title="签到打卡" isLink url="/pages/home/home"></u-cell>
					<u-cell :border="false" title="更新巡更点信息" isLink url="/pages/my/myRenew/myRenew"></u-cell>
				</u-cell-group>
			</view>
		</view>

		<view :class="{ 'my__main-btn': true, 'mine-bgc': userInfo }">
			<button class="btn-1" v-if="userInfo" @click="loginOut">
				退出登录
			</button>
			<button class="btn-1" v-else @click="goLogin">
				登录
			</button>
		</view>
	</view>
</template>

<script>
	import {
		getUserInfo,
	} from '@/api/login.js'
	export default {
		data() {
			return {
				userInfo: null
			};
		},
		methods: {
			loginOut() {
				uni.showModal({
					title: '提示',
					content: '确定退出吗?',
					success: res => {
						if (res.confirm) {
							uni.showToast({
								title: '操作成功',
								icon: 'none',
								duration: 800,
								mask: true,
								success: () => {
									setTimeout(() => {
										uni.removeStorageSync('userInfo'); // 移除本地的信息
										uni.removeStorageSync('token')
										uni.clearStorageSync()
										uni.navigateTo({
											url: '/pages/login/index',
										})
									}, 800)
								}
							})

						}
					}
				})
			},
			goLogin() {
				uni.navigateTo({
					url: '/pages/login/index',
				});
			},
			// 获取信息
			checkUserInfo() {
				getUserInfo().then(res => {
					uni.setStorageSync('userInfo', res.data)
					// this.userInfo = res.data
					this.userInfo.userType = res.data.userType
				}).catch(err => {});
			},
		},
		onShow() {
			this.checkUserInfo()
			// const userInfo = uni.getStorageSync("userInfo");
			// this.userInfo = userInfo
		},
		onLoad() {
			// this.checkUserInfo()
			const userInfo = uni.getStorageSync("userInfo");
			this.userInfo = userInfo
		}
	}
</script>

<style lang="scss" scoped>
	.my__main {
		position: relative;
		width: 100%;
		height: 100%;

		// 背景
		.my__main-top {
			height: 140px;
			background: #3D8EFE;
			border-bottom-left-radius: 8%;
			border-bottom-right-radius: 8%;
		}

		.top-content {
			margin-top: -70px;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 100%;
			height: 150px;
			margin-bottom: 10px;

			.top-content-img {
				width: 100%;
				height: 100%;
				object-fit: cover;
			}

			.top-content-main {
				width: 96%;
				height: 135px;
				position: fixed;
				top: 75px;
				display: flex;
				align-items: center;
				justify-content: center;

				.content-main-id {
					position: fixed;
					left: 9px;
					top: 75px;
					background-color: #fff;
					border-radius: 16px 6px;
					padding: 3px 16px;
					color: #3E8AFF;
					font-weight: 500;
					font-size: 13px;
				}

				.content-main-text1 {
					text-align: center;
					font-size: 20px;
					font-weight: 700;
					color: #fff;
				}

				.content-main-text2 {
					color: #fff;
					text-align: center;

					.main-text2-1 {
						line-height: 36px;
						font-weight: 700;
						font-size: 24px;
					}

					.main-text2-2 {
						line-height: 27px;
						font-weight: 500;
						font-size: 18px;
					}
				}
			}
		}

		.my__main-content-box {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 100%;
			// height: 100px;
			margin-bottom: 15px;

			.my__main-content {
				width: 95%;
				border-radius: 10px;
				display: flex;
				align-items: center;
				background-color: #fff;

				.my__main-content-item {
					height: 90px;
				}
			}
		}


		.my__main-btn .btn-1 {
			background-color: #4065FB;
			color: #fff;
			// height: 48px;
			// line-height: 48px;
			width: 95%;
			border-radius: 10px;
			border: none !important;
		}

		.mine-bgc .btn-1 {
			border: none !important;
			background-color: #fff;
			color: #333;
		}
	}

	::v-deep .u-cell__body {
		padding: 15px 15px !important;
	}

	::v-deep .u-line {
		width: 93% !important;
		margin-left: 13px !important;
	}
</style>