<template>
	<view class="page">
		<uni-nav-bar  :fixed="true" background-color="#FFE05C" :border="false" :statusBar="true"  left-icon="left" title="个人信息" @clickLeft="back" />

		<view class="outView">
			<form @submit="inputValue">
				<view class="flex-row justify-between bordBot" >
					<view class="key flex-col justify-center ">
						<text>头像</text>
					</view>
					<view class="photoView" @click="updateAvatar">
						<image class="photoImage" :src="userInfo.img || '/static/ud4.png'"></image>
					</view>
				</view>

				<view class="flex-row justify-between bordBot" >
					<view class="key flex-col justify-center ">
						<text>姓名</text>
					</view>
					<view class="nikeName flex-col justify-center">
						<input  disabled name="name" v-model="userInfo.name"   placeholder="请输入昵称"/>
					</view>
				</view>

<!--				<view class="flex-row justify-between bordBot" >-->
<!--					<view class="key flex-col justify-center ">-->
<!--						<text>性别</text>-->
<!--					</view>-->
<!--					<view class="nikeName flex-row justify-center" @click="showSex = true">-->
<!--						<input  name="sex" disabled v-model="userInfo.sex"   placeholder="请选择性别"/>-->
<!--						<u-icon name="arrow-right" color="#666" size="18"></u-icon>-->
<!--					</view>-->
<!--				</view>-->

				<view class="flex-row justify-between bordBot" >
					<view class="key flex-col justify-center ">
						<text>手机号</text>
					</view>
					<view class="nikeName flex-row justify-center">
						<input   name="phone" disabled v-model="userInfo.phone"/>
					</view>
				</view>
				<view class="flex-row justify-between bordBot" >
					<view class="key flex-col justify-center ">
						<text>找回密码</text>
					</view>
					<view class="flex-row justify-end nikeName " @click="updatePassword">
						<text>点击修改</text>
						<u-icon name="arrow-right" color="#666" size="18"></u-icon>
					</view>
				</view>

<!--				<button class="updateButton"  formType="submit">-->
<!--					<text>保存</text>-->
<!--				</button>-->

			</form>
		</view>

		<view  class="logoutButton">
			<u-button type="error" text="退出登录" @click="logout"></u-button>
		</view>

		<u-action-sheet
				:show="showSex"
				:actions="actions"
				title="请选择性别"
				@close="showSex = false"
				@select="sexSelect">
		</u-action-sheet>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				showSex:false,
				photoUrl:'',
				userInfo: {},
				genderIndex:0,
				actions: [{
					name: '男',
					value:'1'
				},
					{
						name: '女',
						value:'0'
					},{
						name: '保密',
						value:'2'
					}
				],
			};
		},
		mounted() {
		},
		onShow() {
			// 用户信息
			this.userInfo = uni.getStorageSync('spreadUserInfo')
			console.log(this.userInfo)
		},
		methods: {

			inputValue(e){
				console.log('+++++++++++++inputValue+++++++++++',e)
				this.userInfo.name = e.detail.value.name




			},

			updateAvatar(){
				let that = this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: function (res) {
						let tempUrl = res.tempFiles[0].path
						uni.uploadFile({
							url: that.$baseUrl + '/resource/oss/upload', //仅为示例，非真实的接口地址
							filePath:tempUrl,
							name: 'file',
							header: {
								// "Content-Type": "multipart/form-data",
								// 'X-Access-Token': uni.getStorageSync('token'),
								'Authorization': 'Bearer ' + uni.getStorageSync('accessToken'),
							},
							success: (uploadFileRes) => {
								let res = JSON.parse(uploadFileRes.data)
								console.log('+++++++++++++++++chooseavatar+++++++++++++++++++++++',uploadFileRes.data)
								that.userInfo.img = res.data.url.replace(/^http:/, "https:")

								//todo  更新头像的接口

								uni.setStorageSync('spreadUserInfo', that.userInfo)

							}
						});

					}
				})

			},

			sexSelect(e) {
				this.userInfo.sex = e.name
				console.log(e)
			},
			back() {
				uni.navigateBack({
					delta: 1
				})
			},

			updatePassword(){

				uni.navigateTo({
					url:'/pages/forgetPassword/forgetPassword'
				})

			},
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			logout(){

				this.$api.login.logout().then(res=>{
					uni.removeStorageSync('accessToken');
					uni.removeStorageSync('userInfo');
					uni.navigateTo({
						url:'/pages/login/login'
					})
				})
			}

		}
	};
</script>

<style lang="scss" scoped>
	@import './index.rpx.css';
</style>
