<template>
	<view class="edit-name">
		<input class="input" type="nickname" placeholder="修改昵称" v-model="nickname" />
		<button class="save" @click="updateNickname">保存</button>
	</view>
</template>

<script>
	import {updateNickname} from '@/api/common.js'
import { nextTick } from 'process'
	export default {
		data() {
			return {
				nickname:'',
				userId:'',
				userInfo:null
			}
		},
		methods: {
			// 修改昵称
			updateNickname() {
				if(!this.nickname){
					return uni.showToast({
						title:'昵称不能为空'
					})
				}
				updateNickname({nickname:this.nickname,userId:this.userId}).then(res=>{
					
					if(res.msg == '成功'){
						uni.showToast({
							title:'修改成功'
						})
						this.userInfo.nickname = this.nickname
						uni.setStorageSync('userInfo',JSON.stringify(this.userInfo))
						// uni.switchTab({
						// 	url:'../../pages/my/index'
						// })
					}
				})
			}
		},
		onLoad() {
			this.userInfo = JSON.parse(uni.getStorageSync('userInfo'))
			this.nickname = this.userInfo.nickname
			this.userId = this.userInfo.userId
		}
	}
</script>

<style lang="scss" scoped>
.edit-name{
	.input{
		height: 80rpx;
		line-height: 180rpx;
		border-bottom: 1px solid #f1f1f1;
		padding-left: 60rpx;
	}
	.save{
		width: 450rpx;
		line-height: 110rpx;
		border-radius: 55rpx;
		margin-top: 50rpx;
		
	}
}
</style>