<template>
<!-- 	<view class="container">
		<uni-list>
		    <uni-list-item title="个人资料" @click="navTo('/pages/set/userinfo')" ></uni-list-item>
			<uni-list-item title="修改密码" @click="navTo('/pages/set/password')" ></uni-list-item>
		    <uni-list-item title="实名认证" @click="navTo('/pages/set/phone')" ></uni-list-item>
		    <uni-list-item title="收货地址" @click="navTo('/pages/set/address')" ></uni-list-item>
		</uni-list>
		<uni-list class="margin-t-20">
		    <uni-list-item title="消息推送" :switch-checked='true' :show-switch="true" :show-arrow="false" switch-color='#5dbc7c'  @switchChange='switchChange'> 
			</uni-list-item>
		</uni-list>
		
		<uni-list class="margin-t-20">
		    <uni-list-item title="清除缓存" ></uni-list-item>
		    <uni-list-item title="检查更新" >
				<template slot="right">
					当前版本 1.0.3
				</template>
			</uni-list-item>
		</uni-list>
		<view class="list-cell log-out-btn" @click="toLogout">
			<text class="cell-tit">退出登录</text>
		</view>
	</view> -->
  <view class="container">
  	<view class="row b-b flex jg">
  		<text class="tit">头像</text>
  		<image :src="userInfo.avatar" @click.stop="imgsub"></image>
  	</view>
  	<view class="row b-b flex">
  		<text class="tit">昵称</text>
  		<input class="input" v-model="userInfo.nickname" type="text" placeholder-class="placeholder" />
  	</view>
  	<view class="row b-b flex">
  		<text class="tit">ID</text>
  		<input class="input" v-model="userInfo.uid" type="text" disabled="true" placeholder-class="placeholder" />
  	</view>
  	<view class="row b-b flex">
  		<text class="tit">用户账号</text>
  		<input class="input" v-model="userInfo.account || userInfo.phone" type="number" disabled="true" placeholder-class="placeholder" />
  	</view>
  	<view class="submit-box flex" >
  		<view class="submit" @click="edit">确认修改</view>
  		<!-- <view class="submit" @click="toLogout">退出登录</view> -->
  	</view>
  	
  </view>
</template>

<script>
	// import uniList from "@/components/uni-list/uni-list.vue"
	// import uniListItem from "@/components/uni-list-item/uni-list-item.vue"
	// import { logout } from '@/api/set.js';
	// import {  
	//     mapMutations  
	// } from 'vuex';
	// export default {
	// 	components: {
	// 		uniList,uniListItem
	// 	},
	// 	data() {
	// 		return {
				
	// 		};
	// 	},
	// 	methods:{
	// 		...mapMutations('user',['logout']),
	// 		navTo(url){
	// 			uni.navigateTo({
	// 				url:url
	// 			})
	// 		},
	// 		//退出登录
	// 		toLogout(){
	// 			let obj = this;
	// 			uni.showModal({
	// 			    content: '确定要退出登录么',
	// 			    success: (e)=>{
	// 			    	if(e.confirm){
	// 						logout({}).then((e) => {
	// 							uni.navigateBack();
	// 						}).catch((e) => {
	// 							console.log(e);
	// 						})
	// 			    		obj.logout();
	// 			    	}
	// 			    }
	// 			});
	// 		},
	// 		//switch切换触发方法
	// 		switchChange(e){
	// 			console.log(e);
	// 			let statusTip = e.value ? '打开': '关闭';
	// 			this.$api.msg(`${statusTip}消息推送`);
	// 		},

	// 	}
	// }
  import uniList from '@/components/uni-list/uni-list.vue';
  import uniListItem from '@/components/uni-list-item/uni-list-item.vue';
  import { mapState, mapMutations } from 'vuex';
  import { logout } from '@/api/set.js';
  import {
  		uploads,edit
  	} from '@/api/user.js';
  export default {
  	components: {
  		uniList,
  		uniListItem
  	},
  	data() {
  		return {
  			// nickName:'李淡淡',
  			// id:'HFBNXISN',
  			// account:'13745262356',
  			userInfo:'',
  		};
  	},
  	onLoad() {
  		this.userInfo = uni.getStorageSync('userInfo') || '';
      console.log(this.userInfo)
  	},
  	methods: {
  		...mapMutations('user',['logout']),
  		//退出登录
  		toLogout() {
  			let obj = this;
  			uni.showModal({
  				content: '确定要退出登录么',
  				success: e => {
  					if (e.confirm) {
  						logout({}).then(e => {
  							obj.logout();
  							uni.navigateTo({
  								url:'/pages/public/login'
  							})
  						})
  						.catch(e => {
  							console.log(e);
  						});
  					}
  				}
  			});
  		},
  		imgsub() {
  			console.log('上传头像')
			this.$util.uploadImageOne('upload/image', function(res) {
				console.log('------',res);
				this.pics.push(res.data.path);
				this.$set(this, 'pics', this.pics);
				this.$set(this, 'extract_pic', this.pics[0])
			});
  			// uploads({
  			// 	filename: ''
  			// }).then(data => {
  			// 	console.log("data",data);
  			// 	this.userInfo.avatar = data[0].url;
  			// })
  		},
  		edit() {
  			const that = this;
  			edit({
  				avatar: this.userInfo.avatar,
  				nickname: this.userInfo.nickname
  			}).then( e =>{
  				that.$api.msg('修改成功');
  				setTimeout(()=> {
  					uni.switchTab({
  						url:'/pages/user/user'
  					});
  				}, 1000);
  			}).catch(e =>{
  				console.log(e);
  				that.$api.msg('修改失败');
  			})
  		}
  	}
  };
</script>

<style lang='scss'>
	/* page{
		background: $page-color-base;
	}
	.list-cell{
		display:flex;
		align-items:baseline;
		padding: 20rpx $page-row-spacing;
		line-height:60rpx;
		position:relative;
		background: #fff;
		justify-content: center;
		&.log-out-btn{
			margin-top: 40rpx;
			.cell-tit{
				color: $uni-color-primary;
				text-align: center;
				margin-right: 0;
			}
		}
		.cell-tit{
			flex: 1;
			font-size: $font-base + 2rpx;
			color: $font-color-dark;
			margin-right:10rpx;
		}
		.cell-tip{
			font-size: $font-base;
			color: $font-color-light;
		}
		switch{
			transform: translateX(16rpx) scale(.84);
		}
	} */
  page {
    background-color: #f3f3f3;
  	min-height: 100%;
  	.container{
  		height: 100%;
  		
  	}
  }
  .row {
    background-color: #fff;
  	padding: 42rpx 25rpx;
  	font-size: 30rpx;
  	color: #333333;
  	image{
  		width: 80rpx;
  		height: 80rpx;
  		border-radius: 50%;
  	}
  	.input {
  		text-align: right;
  		color: #333333;
  	}
  }
  .submit-box{
  		 padding-top: 157rpx;
  		.submit{
  			margin: 40rpx auto;
  			width: 560rpx;
  			background-color: #901b21;
  			color: #FFFFFF;
  			text-align: center;
  			padding:26rpx 0rpx;
  			border-radius: 50rpx;
  		}
  	}
    .jg {
      margin-bottom: 20rpx;
    }
</style>
