<template>
	<view class="content">
		<view class="row flex">
			<text class="tit">头像</text>
			<view class="background-img" @click="imgsub"><image class="background-img" v-model="userInfo.avatar" :src="userInfo.avatar" mode="aspectFill"></image></view>
		</view>
		<view class="row flex">
			<text class="tit">昵称</text>
			<input class="input" type="text" v-model="userInfo.nickname" placeholder-class="placeholder"/>
		</view>
		<view class="row flex">
			<text class="tit">账号</text>
			<view class="input">
				{{userInfo.phone}}
			</view>
		</view>
		<!-- <view class="row">
			<text class="tit">ID</text>
			<input class="input" type="text"  disabled="true" v-model="userInfo.uid" placeholder-class="placeholder" />
		</view> -->
		<view class="list-cell log-out-btn" @click="confirm">
			<text class="cell-tit">修改</text>
		</view>
	</view>
</template>

<script>
import { mapState,mapMutations } from 'vuex';
import { upload } from '@/api/order.js';
import {userEdit,logout} from '@/api/set.js';
export default {
	data(){
		return{
			show:false,
			password: '',
		}
	},
	onLoad() {
		console.log(this.userInfo)
	},
	computed: {
		...mapState('user',['userInfo'])
	},
	methods: {
		...mapMutations('user',['logout']),
		imgsub() {
			console.log('上传头像')
			upload({
				filename: ''
			}).then(data => {
				console.log("data",data);
				this.userInfo.avatar = data[0].url;
			})
		},
		confirm() {
			userEdit({ avatar: this.userInfo.avatar ,nickname: this.userInfo.nickname})
				.then(e => {
					uni.showToast({
						// title: '修改成功',
						title: this.$t("safe.d3"),
						icon:"success",
						mask:true
					});
					setTimeout(()=> {
						uni.switchTab({
							url:'/pages/user/user'
						});
					}, 1000);
					console.log(e);
				})
				.catch(e => {
					console.log(e);
				});
				
		},
		toLogout(){
			let obj = this;
			uni.showModal({
			    content:  this.$t('login.b7'),
			    success: (e)=>{
			    	if(e.confirm){
						logout({}).then((e) => {
							uni.navigateBack();
						}).catch((e) => {
							console.log(e);
						})
			    		obj.logout();
			    	}
			    }
			});
		},
		cancel(){
			// this.$refs.popup.open();
			let obj = this;
			uni.showModal({
				content:  this.$t('login.b7'),
				success: e => {
					if (e.confirm) {
						logout({}).then(e => {
								obj.logout();
								uni.switchTab({
									url: '/pages/index/index'
								})
							})
							.catch(e => {
								console.log(e);
							});
					}
				}
			});
		},
		qx() {
			this.password = '';
			this.$refs.popup.close();
		},
		pswQd() {
			if(this.password != this.userInfo.phone){
				this.$refs.popup.close();
				this.password = '';
				this.$api.msg(obj.$t("safe.f3"))
				return
			}
			this.$refs.popup.close();
			this.password = '';
			this.$api.msg(obj.$t("safe.f4"))
		}
	}
}
</script>

<style lang="scss">
	page{
		background-color: #051137;
	}
	.list-cell{
		background: linear-gradient(90deg, #0C5AFA, #1356FF);
		margin: 30rpx;
		color: #FFF;
		font-size: 30rpx;
		padding: 20rpx;
		text-align: center;
		border-radius: 10rpx;
		line-height: 1;
	}
	.row {
		padding: 20rpx;
		background: #fff;
		background-color:#1F2A4A ;
		border-radius: 10rpx;
		margin: 0 30rpx 30rpx 30rpx;
		.tit {
			flex-shrink: 0;
			font-size: $font-base;
			color:#FFF;
			
		}
		.input {
			flex: 1;
			text-align: right;
			font-size: $font-base;
			color: $color-gray;
		}
		.background-img {
			width: 80rpx;
			height: 80rpx;
			border-radius: 50%;
			background: #f2f2f2;
		}
	}
	.add-btn {
		display: flex;
		align-items: center;
		justify-content: center;
		margin: 158rpx auto 30rpx;
		width: 560rpx;
		height: 80rpx;
		background: #feca00;
		border-radius: 40px;
		color: #FFFFFF;
	}
	.out {
		display: flex;
		align-items: center;
		justify-content: center;
		margin: 0 auto 30rpx;
		width: 560rpx;
		height: 80rpx;
		border: 1px solid  #feca00;
		background: #FFFFFF;
		border-radius: 40px;
		color:  #feca00;
	}
	.psw-wrapper {
		width: 548rpx;
		height: 344rpx;
		background-color: #ffffff;
		.psw-title {
			width: 100%;
			font-size: 35rpx;
			padding: 43rpx 0 49rpx;
			text-align: center;
			font-weight: 800;
		}
		.psw-ipt {
			display: block;
			background-color: #dce3ed;
			height: 90rpx;
			width: 464rpx;
			padding-left: 30rpx;
			margin: 0 auto;
			font-size: 80rpx;
		}
		.psw-btn text {
			display: inline-block;
			text-align: center;
			width: 50%;
			padding-top: 29rpx;
			font-size: 35rpx;
		}
		.psw-qd {
			color: #32C6FF;
		}
	}
</style>
