<template>
	<view class="container">
		<view class="body">
			<!-- 个人头像区域 -->
			<view class="body_box">
				个人头像
				<view class="box_right" @click="handleClickPhoto">
					<img mode="aspectFill" class="img" :src="imgUrl || '../../static/my/portrait.png'" />

					<img class="img2" src="../../static/my/right.png" />
				</view>
			</view>

			<!-- 账号名区域 -->
			<view class="body_box" @click="handleClickName">
				账号名
				<view class="box_right">
					<view class="msg">{{ name }}</view>
					<img class="img2" src="../../static/my/right.png" />
				</view>
			</view>

			<!-- ID区域 -->
			<view class="body_box">
				ID
				<view class="box_right">
					<view class="msg">1925689</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			// 头像
			imgUrl: '',
			// 账号名
			name: '张三'
		}
	},
	methods: {
		// 点击头像图片回调
		handleClickPhoto() {
			uni.showActionSheet({
				itemList: ['更换头像'],
				success: (res) => {
					if (res.tapIndex === 0) {
						this.changeImg()
					}
				}
			})
		},
		// 更换头像回调
		changeImg() {
			uni.chooseImage({
				count: 1,
				sizeType: ['compressed'],
				sourceType: ['album'], //从相册选择
				success: (res) => {
					// console.log(res.tempFilePaths)
					this.imgUrl = res.tempFilePaths[0]
				}
			})
		},
		// 点击账号名回调
		handleClickName() {
			uni.showActionSheet({
				itemList: ['修改账号名'],
				success: (res) => {
					if (res.tapIndex === 0) {
						this.changeName()
					}
				}
			})
		},
		// 修改账号名回调
		changeName() {
			uni.showModal({
				title: '请输入账号名',
				editable: true,
				success: (res) => {
					if (res.confirm) {
						if (!res.content) {
							uni.showToast({
								title: '账号名不能为空',
								icon: 'none'
							})
							setTimeout(() => {
								this.changeName()
							}, 1500)
						} else {
							this.name = res.content
						}
					}
				}
			})
		}
	}
}
</script>

<style lang="scss" scoped>
.container {
	display: flex;
	flex-direction: column;
	min-height: 100vh;
	background-color: #ebeced;

	.body {
		box-sizing: border-box;
		margin-top: 20rpx;
		padding: 0 30rpx;
		height: calc(100vh - 20rpx);
		background-color: #fff;

		.body_box {
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 100rpx;
			font-size: 28rpx;
			border-bottom: 1rpx solid #e6e6e6;

			.box_right {
				display: flex;
				justify-content: flex-end;
				align-items: center;
				height: 100rpx;

				.img {
					width: 64rpx;
					height: 64rpx;
					border-radius: 50%;
				}

				.img2 {
					margin-left: 7rpx;
					width: 47rpx;
					height: 47rpx;
				}

				.msg {
					color: #808080;
				}
			}
		}
	}
}
</style>
