<template>
	<view class="container">
		<uNavBar dark :fixed="true" backgroundColor="#3F9EFF" statusBar="false" left-icon="left" left-text="返回"
			:title="title" rightText="完成" @clickLeft="toBack" @clickRight="submit">
		</uNavBar>
		<view class="content">
			<view class="avatar">
				<image :src="userInfo.avatar" class="avatar-image" mode=""></image>
				<view class="a" @click="handleChooseImg">更换头像</view>
			</view>
			<view class="form">
				<view class="cell">
					<view class="name">姓名</view>
					<input type="text" placeholder="请输入姓名" v-model="userInfo.nick_name" class="ipt"
						placeholder-class="hold" />
				</view>
				<view class="cell">
					<view class="name">角色</view>
					<input type="text" placeholder="" disabled="true" v-model="deptName" class="ipt"
						placeholder-class="hold" style="color: #82848A;" />
				</view>
				<view class="cell">
					<view class="name">单位</view>
					<input type="text" placeholder="" disabled="true" v-model="roleName" class="ipt"
						placeholder-class="hold" style="color: #82848A;" />
				</view>
				<view class="cell">
					<view class="name">手机号</view>
					<input type="number" placeholder="请填写手机号" v-model="detail.phone" class="ipt"
						placeholder-class="hold" />
				</view>
				<view class="cell">
					<view class="name">邮箱</view>
					<input v-model="detail.email" class="ipt" placeholder-class="hold" />
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import http from '@/http/api.js'
	import uNavBar from '@/uni_modules/uni-nav-bar/components/uni-nav-bar/uni-nav-bar.vue'
	export default {
		components: {
			uNavBar
		},
		data() {
			return {
				sexPicker: [{
						name: '男'
					},
					{
						name: '女'
					}
				],
				detail: {},
				deptName: '',
				roleName: '',
				title: '个人资料'
			};
		},
		onLoad() {

				
			const that = this;
			this.$u.api.userInfo().then(data => {
				console.log(data);
				if (data.success) {
					this.detail = data.data;
					http.request({
						url: '/galaxy-system/dept/detail?id=' + this.userInfo.dept_id,
						method: 'GET'
					}).then(res => {
						console.log(JSON.stringify(res.data))
						that.deptName = res.data.deptName;
					}).catch(err => {
						console.log(err)
					})

					http.request({
						url: '/galaxy-system/role/select?roleId=' + this.userInfo.role_id,
						method: 'GET'
					}).then(res => {
						console.log(JSON.stringify(res.data))
						var name = "";
						res.data.forEach(info => {
							name += name.length > 0 ? ":" : "";
							name += info.roleName;
						})
						that.roleName = name;
					}).catch(err => {
						console.log(err)
					})


				}
			}).catch(err => {
				console.log(err)
				this.$u.func.showToast({
					title: err,
				})
			})




		},
		methods: {
			toBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			logout() {
				this.$u.func.logout();
			},
			submit() {
				// let detail = this.detail
				// if (!detail.phone && !/^1\d{10}$/.test(detail.phone)) {
				// 	return uni.showToast({
				// 		title: '请输入正确的手机号',
				// 		duration: 2000,
				// 		icon: 'none'
				// 	});
				// }
				// console.log(JSON.stringify(detail));
			},
			changeDefaultPicker(name, e) {
				this.detail[name] = e.detail.value;
			},
			changePicker(name, e) {
				this.detail[name] = this[`${name}Picker`][e.detail.value].name;
			},
			handleChooseImg() {
				let that = this;
				uni.chooseImage({
					count: 1,
					success(e) {
						that.detail.avatar = e.tempFilePaths[0];
					}
				});
			}
		}
	};
</script>

<style lang="scss">
	.container {
		background-color: #f7f7f7;
		min-height: 100vh;
		padding: 0 0 200rpx;
		overflow: hidden;
	}

	.complie {
		vertical-align: middle;
		padding: 10rpx 20rpx;
		font-size: 32rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #14b9c8;
	}

	.content {
		background-color: #ffffff;
		overflow: hidden;
	}

	.avatar {
		margin-top: 30rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;

		font-size: 30rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #14b9c8;

		.avatar-image {
			width: 162rpx;
			height: 162rpx;
			background: #ffffff;
			border-radius: 50%;
			background-color: #82848a;
			margin-bottom: 15rpx;
		}
	}

	.form {
		padding: 0 36rpx;

		.cell {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 40rpx 0;

			font-size: 30rpx;
			font-family: Source Han Sans CN;
			font-weight: bold;
			color: #666666;

			&:not(:last-of-type) {
				border-bottom: 2rpx solid #efefef;
			}

			.ipt {
				flex: 1;
				margin-left: 40rpx;
				text-align: right;
				font-size: 23rpx;
				font-family: Source Han Sans CN;
				font-weight: bold;
				color: #333333;
			}

			.hold {
				font-size: 27rpx;
				font-family: Source Han Sans CN;
				font-weight: bold;
				color: #c8c8ce;
			}
		}
	}

	.back {
		margin-top: 40rpx;
		text-align: center;
		height: 109rpx;
		background: #ffffff;

		font-size: 34rpx;
		font-family: Source Han Sans CN;
		font-weight: bold;
		color: #141414;
		line-height: 109rpx;
	}
</style>
