<template>
	<view class="edit">
		<view class="head-box">
			<image @click="chooseHead"  class="head" :src="headImg||defaultImg" mode=""></image>
			<image class="icon" src="../../static/take_photo.png" mode=""></image>
		</view>
		<view class="">
				<u-cell size="large" title="修改昵称" :isLink="true" url="/my/edit/editName"></u-cell>
				<u-cell size="large" title="关于" :isLink="true"></u-cell>
		</view>
		<button class="login-out" @click="loginOut">退出当前账号</button>
	</view>
</template>

<script>
	import {uploadImg} from '@/api/common.js'
	export default {
		data() {
			return {
				headImg:'',
				defaultImg:'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fci.xiaohongshu.com%2Fc34b7b74-ba38-0456-982a-43c0f97522fe%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fci.xiaohongshu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1693532127&t=a2e186c12aecaab7723611cb52a6778f',
				userId:'',
				userInfo:null
			}
		},
		methods: {
			chooseHead() {
				let that = this
				uni.chooseImage({
					count:1,
					success(r) {
						that.headImg = r.tempFilePaths[0]
						uploadImg({imgPath:r.tempFilePaths[0],userId:that.userId}).then(res=>{
							uni.showToast({
								title: '上传成功',
							});
							that.userInfo.imgPath = r.tempFilePaths[0]
							uni.setStorageSync('userInfo',JSON.stringify(this.userInfo))
						})
					}
				})
			},
			loginOut(){
				uni.clearStorageSync()
				uni.switchTab({
					url:'/pages/index/index'
				})
			}
		},
		created() {
			this.userInfo = JSON.parse(uni.getStorageSync('userInfo'))
			this.headImg = this.userInfo.imgPath||''
			this.userId = this.userInfo.userId||''
			console.log(this.userId);
			
		}
	}
</script>

<style lang="scss" scoped>
.edit{
	.head-box{
		margin: 80rpx auto 50rpx;
		width: 150rpx;
		height: 150rpx;
		position: relative;
		.head{
			width: 150rpx;
			height: 150rpx;
			border-radius: 50%;
		}
		.icon{
			position: absolute;
			width: 44rpx;
			height: 44rpx;
			bottom: 0%;
			right: 0;
		}
	}
	.login-out{
		position: fixed;
		bottom: 150rpx;
		left: 50%;
		width: 400rpx;
		line-height: 110rpx;
		text-align: center;
		color: #fff;
		background: rgb(164, 173, 179);
		border-radius: 55rpx;
		transform: translateX(-50%);
		font-size: 30rpx;
	}
}
</style>