<template>
	<view class="content">
		<view class="setupItem">
			<view class="label" @click="albumClick">
				<view class="label-name">
					<image class="label-name-img" src="/static/imgs/zK_01.png" mode="aspectFill"></image>
					<view class="label-name-text">修改头像</view>
				</view>
				<view class="label-tips">
					<image class="label-name-head" :src="avatar ? avatar : '/static/imgs/default_myHead.png'" mode="aspectFill"></image>
					<image class="label-name-arrow" src="/static/imgs/zK_arrow.png" mode="widthFix"></image>
				</view>
			</view>
			<view class="label" @click="$Router.push({name: 'Modify'})">
				<view class="label-name">
					<image class="label-name-img" src="/static/imgs/zK_02.png" mode="aspectFill"></image>
					<view class="label-name-text">修改密码</view>
				</view>
				<view class="label-tips">
					<image class="label-name-arrow" src="/static/imgs/zK_arrow.png" mode="widthFix"></image>
				</view>
			</view>
			<view class="label" @click="$Router.push({name: 'Authsuccess'})" v-if="certification">
				<view class="label-name">
					<image class="label-name-img" src="/static/imgs/zK_03.png" mode="aspectFill"></image>
					<view class="label-name-text">实名认证</view>
				</view>
				<view class="label-tips">
					<image class="label-name-arrow" src="/static/imgs/zK_arrow.png" mode="widthFix"></image>
				</view>
			</view>
			<view class="label" @click="$Router.push({name: 'sheetIdcard'})" v-else>
				<view class="label-name">
					<image class="label-name-img" src="/static/imgs/zK_03.png" mode="aspectFill"></image>
					<view class="label-name-text">实名认证</view>
				</view>
				<view class="label-tips">
					<image class="label-name-arrow" src="/static/imgs/zK_arrow.png" mode="widthFix"></image>
				</view>
			</view>
			<!-- <view class="label" @click="$Router.push({name: 'Invite'})">
				<view class="label-name">
					<image class="label-name-img" src="/static/imgs/zK_03.png" mode="aspectFill"></image>
					<view class="label-name-text">邀请码</view>
				</view>
				<view class="label-tips">
					<image class="label-name-arrow" src="/static/imgs/zK_arrow.png" mode="widthFix"></image>
				</view>
			</view> -->
		</view>
		<view class="setupItem">
			<!-- <view class="label" @click="$Router.push({name: 'Referee'})">
				<view class="label-name">
					<image class="label-name-img" src="/static/imgs/zK_04.png" mode="aspectFill"></image>
					<view class="label-name-text">我的伙伴</view>
				</view>
				<view class="label-tips">
					<view class="label-name-number" v-if="childrenCount">{{childrenCount}}</view>
					<image class="label-name-arrow" src="/static/imgs/zK_arrow.png" mode="widthFix"></image>
				</view>
			</view> -->
			<view class="label" @click="$Router.push({name: 'Parent'})">
				<view class="label-name">
					<image class="label-name-img" src="/static/imgs/zK_05.png" mode="aspectFill"></image>
					<view class="label-name-text">业务联系人</view>
				</view>
				<view class="label-tips">
					<image class="label-name-arrow" src="/static/imgs/zK_arrow.png" mode="widthFix"></image>
				</view>
			</view>
		</view>
		<!-- <view class="setupItem">
			<view class="label" @click="$Router.push({name: 'AppDown'})">
				<view class="label-name">
					<image class="label-name-img" src="/static/imgs/zK_06.png" mode="aspectFill"></image>
					<view class="label-name-text">APP下载</view>
				</view>
				<view class="label-tips">
					<image class="label-name-arrow" src="/static/imgs/zK_arrow.png" mode="widthFix"></image>
				</view>
			</view>
		</view> -->
		<view class="setupItem">
			<view class="signOut" @click="outLogin">
				退出登录
			</view>
		</view>
	</view>
</template>

<script>
	import { userIndex, setting } from '@/apis/interfaces/user'
	import { uploads } from '@/apis/interfaces/uploading'
	export default {
		data() {
			return {
				avatar		 : '',  //用户头像
				childrenCount: '', // 下级人数
				certification: '' // 是否认证
			};
		},
		
		onShow() {
		    // 获取用户信息
		    this.userInfo();
		},
		
		methods:{
			// 用户信息
			userInfo() {
			    userIndex().then(res => {
					this.avatar        = res.avatar
					this.childrenCount = res.children_count.one
					this.certification = res.certification
			    }).catch(err => {
					uni.showToast({
						title: err.message,
						icon: "none"
					})
				})
			},
			
			// 相册选择图片
			albumClick() {
				var _this = this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album','camera'],  // way是点击时传入的打开方式相机或相册
					success: path=> {
						uploads([{
							uri : path.tempFilePaths[0]
						}]).then(res => {
						    this.avatar = res.url[0]
						    // 上传头像
						    this.settingInfo('avatar', res.path[0])
						}).catch(err => {
							uni.showToast({
								title: err.message,
								icon : 'none'
							})
						})
					},
				});
			},
			
			// 上传用户信息
			settingInfo(key, value) {
			    setting(key, {
			        value: value
			    }).then(res => {
			    }).catch(err => {
			    	uni.showToast({
			    		title: err.message,
			    		icon : 'none'
			    	})
			    })
			},
			
			// 退出登录
			outLogin(){
				this.$store.commit('setToken', '')
				this.$Router.replaceAll({name: 'Index'})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		background-color: #f7f9fa;
		height: 100vh;
		overflow-y: scroll;
	}
	
	.setupItem {
		margin-bottom: $margin;
		background-color: #ffffff;
		.label {
			line-height: 60rpx;
			display: flex;
			padding: $padding;
			box-sizing: border-box;
			border-bottom: 2rpx solid #f7f9fa;
			&:last-child {
				border: none;
			}
			.label-name {
				display: flex;
				flex: 1;
				.label-name-img {
					width: 34rpx;
					height: 34rpx;
					margin-top: 12rpx;
					margin-right: 20rpx;
				}
			}
			.label-tips {
				display: flex;
				.label-name-head {
					width: 54rpx;
					height: 54rpx;
					border-radius: 50%;
					margin-right: 20rpx;
				}
				.label-name-arrow {
					width: 24rpx;
					height: 24rpx;
					margin-top: 18rpx;
				}
				.label-name-number {
					display: inline-block;
					background-color: $mian-color;
					color: #ffffff;
					border-radius: $radius * 3;
					height: 36rpx;
					line-height: 36rpx;
					padding: 0 $padding - 10;
					font-size: $title-size-sm;
					margin: 12rpx 20rpx 0 0;
				}
			}
		}
		.signOut {
			text-align: center;
			line-height: 60rpx;
			padding: $padding - 5 0;
			color: $mian-color;
		}
	}
</style>