<template>
	<view>
		
		<view class="profile_item profile_item1" @click="gotochange">
			<text>Photo</text>
			<view class="profile_item_right">
				<image src="../../static/img/logo.png" mode="" class="head_img" v-show="!user_info.isLogin"></image>
				<image :src="user_info.user_head" mode="" class="head_img" ></image>
				<image src="../../static/img/right1.png" alt="" class="right_img"></image>
			</view>
		</view>
		<view class="profile_item ">
		<!-- <view class="profile_item " @click="$refs.inputDialog.open()"> -->
			<text>Name</text>
			<view class="profile_item_right">
				<text>{{user_info.nickname}}</text>
				<image src="" alt="" class="right_img"></image>
				<!-- <image v-show="" src="../../static/img/right1.png" alt="" class="right_img"></image> -->
			</view>
		</view>
		<view class="profile_item ">
			<text>Email</text>
			<view class="profile_item_right">
				<image src="../../static/img/gantan.png" alt="" class="right_img1" v-if="user_info.is_validated==0"></image>
				<image src="../../static/img/qr.png" alt="" class="right_img1" v-if="user_info.is_validated!=0"></image>
				<text>{{user_info.is_validated==0?'Unverified':''+user_info.email}}</text>
				<image src="../../static/img/right1.png" alt="" class="right_img"></image>
			</view>
		</view>
		<navigator :url="'/pages/login/verifyEmail?type=0&email='+user_info.email" >
			<view class="profile_item ">
				<text>Change Password</text>
				<view class="profile_item_right">
					<image src="../../static/img/right1.png" alt="" class="right_img"></image>
				</view>
			</view>
		</navigator>
		<view class="profile_item"  @click="gotoaddress">
			<text>Ship to</text>
			<view class="profile_item_right">
				<!-- <text>{{addressDate.country_name || 'United States'}}</text> -->
				<text>{{ country }}</text>
				<image src="../../static/img/right1.png" alt="" class="right_img"></image>
			</view>
		</view>
		<navigator url="/pages/account/deleteCount" >
			<view class="profile_item ">
				<text>Delete account</text>
				<view class="profile_item_right">
					<image src="../../static/img/right1.png" alt="" class="right_img"></image>
				</view>
			</view>
		</navigator>
		<uni-popup ref="inputDialog" type="dialog">
			<uni-popup-dialog ref="inputClose"  mode="input" title="Edit Name"  cancelText="Cancel" confirmText="OK"
				placeholder="please enter your name" @confirm="dialogInputConfirm"></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	import {defaultRequest,defaultRequest2} from '../../api/index.js'
	export default {
		data() {
			return {
				user_info:{
					isLogin:false,
				},
				query:{
					_action:'updateinfo',
					nickname:'',
					user_head:''
				},
				addressDate:{},
				country:''
			}
		},
		methods:{
			//换头像
			gotochange(){
				uni.navigateTo({
				 url:'./changeImg'
				})
			},
			getaddress(){
				let data ={
					_action:'getregions',parent_region_id:0
				}
				defaultRequest(data).then( res  =>{
					console.log(JSON.parse(res),'p')
				})
			},
			// 获取默认地址
			getDefaultAddress(){
				let data={_action:'getdefaultconsignee'}
				defaultRequest2(data).then(res=>{
					console.info(res)
					if(res.error==0){
						this.addressDate=res.data
					}
				})
			},
			
			getUserInfo(){
				let data={_action:'getinfo'}
				defaultRequest2(data).then(res=>{
					console.info(res,'pph')
					if(res.error==0){
						  res.data.isLogin=true
						this.user_info=res.data
						uni.setStorageSync('user_info',this.user_info)
						// this.user_info=uni.getStorageSync('user_info')
					}
					else{
						this.user_info=uni.getStorageSync('user_info')
					}
				})
			},
			dialogInputConfirm(val){
				this.query.nickname=val
				this.query.user_head = this.user_info.user_head
				defaultRequest2(this.query).then(res=>{
					console.info(res,'///')
					if(res.error==0){
						uni.showToast({
							title:'OK',
							icon:'none'
						})
						this.getUserInfo()
					}
				})
			},
			gotoaddress(){
				uni.navigateTo({
					url:'../index/address'
				})
			},
		},
		
		onLoad(e) {
			console.log(e,'address')
             this.country=uni.getStorageSync('country')
			 console.log(this.country)
			
			
		},
		onShow() {
			
		   this.user_info=uni.getStorageSync('user_info')
		   console.log(this.user_info,'ppppp')
			this.getUserInfo()
			this.getDefaultAddress()
		}
	}
</script>

<style>
	page{
		border-top: 13.33rpx #F7F7F7 solid;
		padding-left: 26.67rpx;
	}
	
</style>
<style lang="scss" scoped>
	
	.profile_item{
		width: 97%;
		display: flex;
		margin-right: 3%;
		align-items: center;
		justify-content: space-between;
		font-size: 24rpx;
		font-weight: bold;
		 padding: 40rpx 0rpx;
		 padding-right: 30.33rpx;
		
		border-bottom: 1.33rpx #ECECEC solid;
		box-sizing: border-box;
		
		.profile_item_right{
			display: flex;
			align-items: center;
			.head_img{
				width: 112rpx;
				height: 112rpx;
				border-radius: 50%;
			}
			.right_img{
				width: 18.67rpx;
				height: 18.67rpx;
				margin-left: 20rpx;
			}
			.right_img1{
				width: 25.33rpx;
				height: 25.33rpx;
				margin-right: 9.33rpx;
			}
		}
		
	}
	.profile_item1{
		padding: 17.33rpx 0rpx;
		padding-right: 33.33rpx;
		
	}
</style>