<template>
	<view>
		<uni-popup ref="userProfileShow" type="bottom" background-color="#fff">
			<view class="userProfile-box">
				<view class="title">获取你的昵称、头像</view>
				<view class="describe">获取用户头像、昵称，主要用于向用户提供具有辨识度的用户中心界面</view>
				<view class="form-box">
					<view class="picture-box">
						<text class="text">头像</text>
						<button class="button" open-type="chooseAvatar" @chooseavatar="onChooseAvatar" hover-class="none">
							<image class="avatar" :src="userForm.userAvatarUrl || 'https://life.cloud.hjxbc.cn/sys/common/static/miniapp/avatar.png'" mode="aspectFill"></image>
						</button>
					</view>
					<view class="picture-box">
						<text class="text">姓名</text>
						<input class="input" type="nickname" v-model="userForm.nickname" @change="getNickname" placeholder="请输入昵称" maxlength="14" />
					</view>
				</view>
				<view class="submit-box"><button :disabled="isDisabled" style="width: 200px" type="primary" @click="userSubmit">确认</button></view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userForm: {
					userAvatarUrl: '',
					nickname: '',
					isTmp: false
				}
			}
		},
		computed: {
			isDisabled() {
				return !this.userForm.userAvatarUrl || !this.userForm.nickname;
			}
		},
		methods: {
			onChooseAvatar(data) {
				this.userForm.userAvatarUrl = data.detail.avatarUrl;
				this.userForm.isTmp = true
			},
			getNickname(e) {
				this.userForm.nickname = e.detail.value;
			},
			userSubmit() {
				this.$refs.userProfileShow.close()
				this.$emit('saveUserOk', this.userForm)
			}
		}
	}
</script>

<style lang="scss" scoped>
.userProfile-box {
	width: 100%;
	padding: 20px 25px;
	box-sizing: border-box;

	.title {
		font-size: 18px;
		font-weight: bold;
		color: #000;
	}

	.describe {
		font-size: 14px;
		color: #9c9c9c;
		margin-top: 15px;
	}

	.form-box {
		margin-top: 10px;

		.picture-box {
			width: 100%;
			height: 74px;
			display: flex;
			align-items: center;
			border-bottom: 1rpx solid #f1f1f1;

			&:first-child {
				border-top: 1rpx solid #f1f1f1;
			}

			.text {
				font-size: 14px;
				color: #000;
				margin-right: 20px;
			}

			.button {
				width: 54px;
				height: 54px;
				padding: 0;
				margin: inherit;

				&::after {
					border: none;
				}

				.avatar {
					width: 54px;
					height: 54px;
					border-radius: 5px;
				}
			}

			.input {
				height: 74px;
				line-height: 74px;
			}
		}
	}

	.submit-box {
		margin-top: 30px;
	}
}
</style>
