<template>
	<view class="content">
		<view class="row1">
			<text class="tit">头像</text>
			<view class="background-img" @click.stop="imgsub"><image class="background-img" v-model="userInfo.avatar" :src="userInfo.avatar" mode="aspectFill"></image></view>
		</view>
		<view class="row">
			<text class="tit">家长</text>
			<input class="input" type="text"  disabled="true" v-model="userInfo.real_name" placeholder-class="placeholder" />
		</view>
		<view class="row">
			<text class="tit">学生</text>
			<input class="input" type="text"  disabled="true" v-model="student" placeholder-class="placeholder" />
		</view>
		<view class="row">
			<text class="tit">手机号</text>
			<input class="input" type="text"  disabled="true" v-model="userInfo.phone" placeholder-class="placeholder" />
		</view>
		<button class="add-btn" @click="confirm">提交</button>
	</view>
</template>

<script>
import { mapState } from 'vuex';
import { uploads,my } from '@/api/user.js';
import {userEdit} from '@/api/set.js'
export default{
	data(){
		return{
			student:''
		}
	},
	onLoad() {
		this.loadData();
		console.log(this.userInfo)
	},
	computed: {
		...mapState( ['userInfo'])
	},
	methods: {
		async loadData(){
			my({}).then(({ data }) => {
				this.student = data.full_name;
			});
		},
		imgsub() {
			console.log('上传头像')
			uploads({
				filename: ''
			}).then(data => {
				console.log("data",data);
				this.userInfo.avatar = data[0].url;
			})
		},
		confirm() {
			userEdit({ avatar: this.userInfo.avatar })
				.then(e => {
					this.$api.msg('修改成功');
					setTimeout(()=> {
						uni.switchTab({
							url:'/pages/user/user'
						});
					}, 1000);
					console.log(e);
				})
				.catch(e => {
					console.log(e);
				});
		}
	}
}
</script>

<style lang="scss">
	.row1 {
		display: flex;
		align-items: center;
		justify-content: space-between;
		position: relative;
		padding: 0 30upx;
		height: 110upx;
		background: #fff;
		margin-bottom: 20upx;
		.tit {
			flex-shrink: 0;
			width: 120upx;
			font-size: $font-lg;
			color: $font-color-dark;
		}
		
		.background-img {
			width: 80rpx;
			height: 80rpx;
			border-radius: 50%;
			background: #f2f2f2;
		}
	}
	.row {
		display: flex;
		align-items: center;
		padding: 0 30upx;
		height: 110upx;
		background: #fff;
	
		.tit {
			flex-shrink: 0;
			width: 120upx;
			font-size: $font-lg;
			color: $font-color-dark;
		}
		.input {
			flex: 1;
			text-align: right;
			font-size: $font-base;
			color: $color-gray;
		}
	}
	.add-btn {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 690upx;
		height: 80upx;
		margin: 60upx auto;
		font-size: $font-lg;
		color: #fff;
		background-color: #1CC7C7;
		border-radius: 10upx;
	}
</style>
