<template>
	<view class="content">
		<view class="listBox">
			<view class="row flex" @click="imgsub">
				<text class="tit">头像</text>
				<view>
					<image class="background-img" v-model="userInfo.avatar" :src="userInfo.avatar" mode="aspectFill">
					</image>
				</view>
			</view>
			<view class="list">
				<view class="flex listItem">
					<view class="flex titleBox">
						<text class="title">昵称</text>
					</view>
					<view class="right flex">
						<input class="input" type="text" v-model="userInfo.nickname" placeholder="请输入昵称" placeholder-class="placeholder" />
					</view>
				</view>
				<view class="flex listItem">
					<view class="flex titleBox">
						<text class="title">ID</text>
					</view>
					<view class="right flex">
						<text>{{userInfo.uid}}</text>
						<!-- <image class="img" src="../../static/icon/next1.png" mode="widthFix"></image> -->
					</view>
				</view>
				<!-- <view class="flex listItem">
					<view class="flex titleBox">
						<text class="title">账户</text>
					</view>
					<view class="right flex">
						<text>{{userInfo.account}}</text>
					</view>
				</view> -->
			</view>
		</view>
		<view class="base-buttom" @click="confirm">提交</view>
	</view>
</template>

<script>
	import {
		mapState,
	} from 'vuex';
	import {
		userEdit,
		upload
	} from '@/api/set.js';

	export default {
		data() {
			return {

			}
		},
		onLoad() {
			console.log(this.userInfo)
		},
		computed: {
			...mapState('user', ['userInfo'])
		},
		methods: {
			imgsub() {
				console.log('上传头像')
				upload({
					filename: ''
				}).then(data => {
					console.log("data", data);
					this.userInfo.avatar = data[0].img;
				})
			},
			confirm() {
				userEdit({
						avatar: this.userInfo.avatar,
						nickname: this.userInfo.nickname
					})
					.then(e => {
						this.$api.msg('修改成功');
						setTimeout(() => {
							uni.switchTab({
								url: '/pages/userhome/user'
							});
						}, 1000);
						console.log(e);
					})
					.catch(e => {
						console.log(e);
					});
			},
		}
	}
</script>

<style lang="scss">
	.content {
		padding-top: 30rpx;
	}
	.listBox {
		margin: 0 $page-row-spacing;
		border-radius: 20rpx;
		overflow: hidden;
		background-color: #FFFFFF;
	}

	.list {
		.listItem {
			padding: 35rpx 40rpx;
			border-bottom: 1px solid $page-color-light;
		}

		.listIconImg {
			width: 36rpx;
		}

		.right {
			color: $font-color-light;
			font-size: $font-base;
			flex-grow: 1;
			justify-content: flex-end;
			.img {
				width: 26rpx;
			}
		}
		.input {
			flex-grow: 1;
			text-align: right;
			font-size: $font-base;
			color: $color-gray;
		}
		
		.titleBox {
			.title {
				color: $font-color-base;
				font-size: $font-base;
			}
		}
	}

	
	.row {
		display: flex;
		align-items: center;
		padding: 35rpx 40rpx;
		background: #fff;
		border-bottom: 1px solid $page-color-light;

		.background-img {
			width: 80rpx;
			height: 80rpx;
			border-radius: 50%;
			background: #f2f2f2;
		}

		.tit {
			flex-shrink: 0;
			width: 120upx;
			font-size: $font-base;
			color: $font-color-base;
		}
	}

</style>
