<template>
	<view class="page">
		<view style="padding:30rpx;">
			<view style="display: flex;align-items: center;">
				<view style="width: 100%;">
					<input placeholder-class="plasty" placeholder="输入您的昵称" class="input" v-model="form.nickname" />
				</view>
			</view>
		</view>
		<view class="btn_1" @click="save()">保存</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			form: {
				nickname: '',
			},
		}
	},
	onLoad() {
		this.form.nickname = uni.getStorageSync('userInfo').nickname;
	},
	methods: {
		
		save() {
			if (this.form.nickname == '') {
				uni.showToast({
					title: '请输入昵称',
					icon: "none",
					duration: 1500,
				});
				return;
			}
			let nickname = this.form.nickname;
			uni.$u.http
				.post("/api/user/profile", {
					nickname: nickname,
					update_fields: ['nickname']
				})
				.then((res) => {
					console.log(res);
					if (res.code == 1) {
						uni.showToast({
							title: '保存成功',
							icon: "none",
							duration: 1500,
							complete: function () {
								setTimeout(function () {
									uni.navigateBack(1);
								}, 1500);
							}
						});
						uni.setStorageSync('userInfo', {
							...uni.getStorageSync('userInfo'),
							nickname: nickname
						});
						uni.setStorageSync('niName', nickname);
					} else {
						uni.showToast({
							title: res.msg,
							icon: "none",
							duration: 2000,
						});
					}
				})
		}
	}
}
</script>

<style lang="scss" scoped>
.page {
	font-family: PingFang SC Bold, PingFang SC Bold;
}

.input {
	border-radius: 18rpx 18rpx 18rpx 18rpx;
	border: 1rpx solid #707070;
	height: 80rpx;
	padding-left: 10rpx;
	color: #999999;
}

.plasty {
	font-weight: 300;
	font-size: 28rpx;
	color: #999999;
	
}

.btn_1 {
	width: 95%;
	height: 90rpx;
	background: #323232;
	border-radius: 198rpx 198rpx 198rpx 198rpx;
	font-family: YouSheBiaoTiHei, YouSheBiaoTiHei;
	font-weight: 400;
	font-size: 32rpx;
	color: #BBFC5B;
	line-height: 90rpx;
	text-align: center;
	margin: 0 auto;
	position: fixed;
	bottom: 5%;
	left: 0;
	right: 0;
}
</style>
