<template>
	<view class="my__main">
		<!-- 账号 -->
		<view class="my__main-top">
			<view class="top-content">
				<button class="top-left" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
					<image class="img" :src="avatarUrl" mode="aspectFit"></image>
				</button>
				<view class="top-right">
					{{companyName}}
				</view>
			</view>
		</view>
		<!-- 功能部分 -->
		<view class="my__main-content">
			<view class="content-title">我的功能</view>
			<view class="content-cell">
				<u-cell-group :border="false">
					<u-cell class="content-cell-1" title="我的订单" isLink url="/pages/my/myOrder/myOrder">
						<u-icon slot="icon" size="18" name="list-dot"></u-icon>
					</u-cell>
					<u-cell class="content-cell-1" title="公司信息" isLink url="/pages/login/login">
						<u-icon slot="icon" size="18" name="man-add"></u-icon>
					</u-cell>
					<!-- <u-cell class="content-cell-1" isLink url="/pages/login/login">
						<view slot="title" class="u-slot-title">
							<view class="img">
								<image src="../../static/gongsimc.png" mode=""></image>
							</view>
							<view class="u-cell-text">公司信息</view>
						</view>
					</u-cell> -->
					<u-cell class="content-cell-1" :border="false" title="退出登录" @click="loginOut" isLink>
						<u-icon slot="icon" size="18" name="share-square"></u-icon>
					</u-cell>
				</u-cell-group>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getUserInfo,
	} from '@/api/login.js'
	export default {
		data() {
			return {
				avatarUrl: "../../static/avatar.png",
				companyName: '',
			};
		},
		methods: {
			// 头像账号
			onChooseAvatar(e) {
				// console.log(e)
				this.avatarUrl = e.detail.avatarUrl
				uni.setStorageSync('avatarUrl', this.avatarUrl); // 将头像 URL 存储到本地缓存中
			},
			loginOut() {
				uni.showModal({
					title: '提示',
					content: '确定退出吗?',
					success: res => {
						if (res.confirm) {
							uni.showToast({
								title: '操作成功',
								icon: 'none',
								duration: 800,
								mask: true,
								success: () => {
									setTimeout(() => {
										// uni.removeStorageSync(
										// 'avatarUrl'); // 移除本地缓存中的头像 URL
										uni.removeStorageSync('openId'); // 移除本地缓存中的openid
										uni.removeStorageSync('userInfo'); // 移除本地缓存中的公司信息
										uni.removeStorageSync('token')
										// uni.reLaunch({
										// 	url: '/pages/login/index',
										// })
										uni.navigateTo({
											url: '/pages/login/index',
										})
									}, 800)
								}
							})

						}
					}
				})
			}
		},
		onShow() {
			const avatarUrl = uni.getStorageSync('avatarUrl');
			if (avatarUrl) {
				this.avatarUrl = avatarUrl;
			}
			getUserInfo().then(res => {
				this.companyName = res.data.companyName
			}).catch(err => {});
		}
	}
</script>

<style lang="scss" scoped>
	.my__main {
		position: relative;
		width: 100%;
		height: 100%;
		background-color: #fff;

		// 顶部头像
		.my__main-top {
			height: 209px;
			// height: 132.4px;
			padding-top: 92px;
			// padding-top: 15.4px;
			background: linear-gradient(72deg, #2F74FF 28.55%, #4299FF 100.56%);

			.top-content {
				display: flex;
				width: 100%;
				height: 70px;

				.top-left {
					width: 70px;
					height: 70px;
					margin: 0px 17px 47px 20px;
					padding: 0 !important;
					border-radius: 50%;
					overflow: hidden;
					background: lightgray 50% / cover no-repeat;

					.img {
						width: 100%;
						height: 100%;
						// object-fit: contain;
					}
				}

				.top-right {
					color: #FFF;
					font-size: 20px;
					font-weight: 500;
					line-height: 70px;
				}
			}

		}

		// 功能列表
		.my__main-content {
			position: absolute;
			// top: 96.4px;
			top: 173px;
			width: 100%;
			border-radius: 22px;
			background-color: #fff;

			.content-title {
				color: #333;
				font-size: 18px;
				font-weight: 500;
				margin-left: 13px;
				margin-top: 16px;
			}

			.content-cell {
				padding: 0 16px;

				.content-cell-1 {
					height: 56px;
				}
			}
		}
	}

	.u-slot-title {
		display: flex;

		.img {
			width: 19.8px;
			height: 18px;
			margin-right: 9.2px;

			image {
				width: 100%;
				height: 100%;
				object-fit: contain;
			}
		}
	}

	::v-deep .u-cell__body {
		padding: 16px 0px !important;

	}

	::v-deep .u-icon__icon {
		margin-right: 9.2px;
	}
</style>