<template>
	<view class="body">
		<view class="header-bg">

		</view>
		<view class="header">
			<view class="title">
				昵称
			</view>
		</view>

		<view class="main">
			<view class="input-item inline-form">
				<input class="input" type="text" placeholder="请输入新昵称" v-model="form.nickname">
			</view>
		</view>
		<view class="submit-btn-wrapper">
			<button class="btn submit-btn" type="default" @tap="submit">确认修改</button>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					nickname: ""
				}
			}
		},
		onLoad() {
			this.form.nickname = this.$store.state.user.nickname
		},
		methods: {
			submit() {
				if (this.$verified.required(this.form.nickname, "请输入新昵称")) {
					this.$http.post({
						url: "/user/profile",
						data: this.form,
						success: (res) => {
							uni.$emit("refresh_userinfo")
							uni.showToast({
								title:"昵称修改成功",
								icon:"none",
								success() {
									setTimeout(uni.navigateBack(),1000)									
								}
							})
						}
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.body {
		position: relative;
		overflow: hidden;
	}

	.header-bg {
		background: $primary-color;
		height: 100upx;
		position: absolute;
		top: 0;
		width: 100%;
	}

	.header {
		margin: 20upx;
		background: white;
		text-align: center;
		border-radius: 20upx;
		position: relative;
		z-index: 1;

		.title {
			height: 100upx;
			font-size: 32upx;
			line-height: 100upx;
			// font-weight: bold;
		}
	}

	.main {
		margin: 20upx;
		background: white;
		border-radius: 10upx;
	}

	.input-item.inline-form {
		display: flex;
		align-items: center;
		height: 80upx;
		font-size: 28upx;
		padding: 0 20upx;
		position: relative;
		color: #999999;

		.label {
			width: 160upx;
			// flex: 1 1 160upx;

		}

		.input {
			flex-grow: 1;
			font-size: 28upx;
		}
	}

	.submit-btn-wrapper {
		margin-top: 80upx;

		.submit-btn {
			font-size: 30upx;
			line-height: 60upx;
			width: 250upx;
			background: $primary-color;
			color: white;
		}
	}
</style>
