<template>
	<view>
		<view class="top">
			<view class="avatar">
				<image v-if="info.avatar" :src="info.avatar" mode="aspectFill"></image>
				<view class="avatar" v-if="!info.avatar && !info" :style="{backgroundColor:bgColor[1]}">
					{{info.name.split('').pop()}}
				</view>
			</view>
			<view class="info">
				<view class="name">{{info.name}}</view>
				<view class="box">
					<view class="item">
						<view class="label">部门</view>
						<view class="text">{{info.section_fullname}}</view>
					</view>
					<view class="item">
						<view class="label">职务</view>
						<view class="text">{{info.duty_num}}</view>
					</view>
					<view class="item">
						<view class="label">员工编号</view>
						<view class="text">{{info.staff_num}}</view>
					</view>
				</view>
			</view>
		</view>

		<view class="content">
			<view class="box">
				<view class="item" @click="change_active(1)">
					<view class="text" :style="{color:active == 1?'#333':'#8e8e8e'}">个人信息</view>
					<view class="line" v-if="active == 1"></view>
				</view>
				<view class="item" @click="change_active(2)">
					<view class="text" :style="{color:active == 2?'#333':'#8e8e8e'}">工作经历</view>
					<view class="line" v-if="active == 2"></view>
				</view>
				<view class="item" @click="change_active(3)">
					<view class="text" :style="{color:active == 3?'#333':'#8e8e8e'}">荣誉及证书</view>
					<view class="line" v-if="active == 3"></view>
				</view>
			</view>


			<!-- 个人信息 -->
			<view class="list_1" v-if="active == 1">
				<view class="item" @click="binding_phone()">
					<view class="label">手机号</view>
					<view class="text">12345678</view>
					<view class="right">
						<uni-icons type="arrowright" size="20" color="#999"></uni-icons>
					</view>
				</view>
				<view class="item" @click="go_signature()">
					<view class="label">手写签名</view>
					<view class="text"> </view>
					<view class="right">
						<uni-icons type="arrowright" size="20" color="#999"></uni-icons>
					</view>
				</view>
				<view class="item">
					<view class="label">岗位分类</view>
					<view class="text">{{info.job_classify}}</view>
					<view class="right"></view>
				</view>
				<!-- <view class="item">
					<view class="label">岗位</view>
					<view class="text">{{info.position.title}}</view>
					<view class="right"></view>
				</view> -->
				<view class="item">
					<view class="label">民族</view>
					<view class="text">{{info.nation}}</view>
					<view class="right"></view>
				</view>
				<view class="item">
					<view class="label">出生日期</view>
					<view class="text">{{info.birthday}}</view>
					<view class="right"></view>
				</view>
			</view>

			<!-- 工作经历 -->
			<view class="list_2" v-if="active == 2">
				<view class="item">
					<view class="text_1">任职时间</view>
					<view class="text_2">工作单位</view>
					<view class="text_3">职务</view>
				</view>
				<view class="item" v-for="item in 3">
					<view class="text_1">2008-06-23至1010-05-14</view>
					<view class="text_2">公司名称公司名称公司名称</view>
					<view class="text_3">工程师</view>
				</view>
			</view>
			<!-- 荣誉及证书 -->
			<view class="list_3" v-if="active == 3">
				<view class="item" v-for="item in 4">
					<view class="img">
						<image
							src="https://cdn.colorhub.me/7X-46x4lrKMmT8Tyo5qNMRFN0p1R-nMEzlYx-XvdZiw/rs:auto:280:0:0/g:ce/bG9jYWw6Ly8vMTgv/NzUvOGFkNWU4NmZj/Mzc2NWJjYTBiYzAw/YTY1N2JiNWE5ZmMz/MjAyMTg3NS5qcGc.jpg"
							mode="aspectFill"></image>
					</view>
					<view class="text">奖项名称奖项名称奖项名称</view>
				</view>
				<view class="item">
					<view class="img">
						<view class="add" @click="add()">+</view>
					</view>
					<view class="text"></view>
				</view>
			</view>
		</view>


	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 当前煤矿编码
				mine_code: "",
				// 基础请求路径
				base_url: " ",
				
				active: 1,
				info: {},
				// 头像随机色
				bgColor: [],
			};
		},
		onLoad() {
			// 设置头像
			for (let i = 0; i < 2; i++) {
				// 获取随机色
				let r = parseInt(Math.random() * 256)
				let g = parseInt(Math.random() * 256)
				let b = parseInt(Math.random() * 256)

				// ES6 字符串拼接
				// this.bgColor = `rgba(${r},${g},${b},0.3)`
				let color = "rgba(" + r + "," + g + "," + b + "," + 0.3 + ")"
				// console.log(color)
				this.bgColor.push(color)
			}
			
			// 初始化当前煤矿编码
			this.mine_code = uni.getStorageSync('mine_code')
			
			// 根据矿编码切换首页接口不同的请求基础路径
			switch (this.mine_code) {
				case 'ningdongyunying':
					this.base_url = "http://ningdongyunying.nxjiewei.com:8011/api"
					break;
				case 'meihuajing':
					this.base_url = "http://meihuajing.nxjiewei.com:8011/api"
					break;
				case 'zaoquan':
					this.base_url = "http://zaoquan.nxjiewei.com:8011/api"
					break;
				default:
					this.base_url = ""
			}

			this.get_info()
		},
		methods: {
			change_active(index) {
				this.active = index
			},
			// 绑定手机
			binding_phone() {
				uni.navigateTo({
					url: "../../my/setPhone/setPhone"
				})
			},
			// 手写签名
			go_signature() {
				uni.navigateTo({
					url: "../../my/signature/signature"
				})
			},
			get_info() {
				this.$api.user_getUinfo({
					staff_num: uni.getStorageSync('user').staff_num
				}).then((res) => {
					console.log(res.data.data)
					this.info = res.data.data
				})
			},
			
			add(){
				uni.chooseImage({
					count: 1,
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						console.log(chooseImageRes.tempFiles[0]);
				
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F5F8F8;
	}

	.top {
		background-color: #FFFFFF;
		width: 750rpx;
		height: 440rpx;

		background-image: url(./icon/top.png);
		background-size: 100% 100%;
		background-position: 0 -110rpx;
		background-repeat: no-repeat;

		.avatar {
			padding-top: 34rpx;
			text-align: center;

			image {
				width: 200rpx;
				height: 200rpx;

				border-radius: 50%;
			}
		}

		.info {
			margin-top: 20rpx;

			.name {
				text-align: center;
				font-size: 40rpx;
				font-weight: 700;
			}

			.box {
				margin-top: 30rpx;
				display: flex;
				justify-content: space-around;

				.item {
					width: 250rpx;
					text-align: center;

					.label {
						font-size: 30rpx;
						color: #009FE8;
						margin-bottom: 10rpx;
					}

					.text {
						font-size: 32rpx;
					}
				}
			}
		}

		margin-bottom: 20rpx;
	}

	.content {
		background-color: #FFFFFF;

		.box {
			display: flex;
			justify-content: space-around;
			align-items: center;

			border-bottom: 2rpx solid #F5F8F8;

			.item {
				height: 95rpx;
				width: 230rpx;
				text-align: center;

				position: relative;

				.text {
					font-size: 34rpx;
					line-height: 95rpx;
				}

				.line {
					margin: -6rpx auto 0;
					width: 80rpx;
					height: 6rpx;
					background-color: #009FE8;
				}
			}
		}

		.list_1 {
			box-sizing: border-box;
			padding: 0 50rpx;

			.item {
				border-bottom: 2rpx solid #F5F8F8;
				height: 95rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				font-size: 32rpx;

				.label {
					width: 200rpx;
					text-align: left;
				}

				.text {
					width: 350rpx;
					text-align: left;
					color: #8e8e8e;

				}

				.right {
					width: 100rpx;
					text-align: right;
				}
			}

		}

		.list_2 {
			box-sizing: border-box;
			padding: 0 50rpx;

			.item {
				border-bottom: 2rpx solid #F5F8F8;
				height: 95rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				font-size: 30rpx;
				text-align: center;
				color: #8e8e8e;

				.text_1 {
					width: 190rpx;
				}

				.text_2 {
					width: 240rpx;

				}

				.text_3 {
					width: 160rpx;
				}
			}

			.item:first-child {
				font-size: 32rpx;
				color: #333;
			}

		}

		.list_3 {
			box-sizing: border-box;
			padding: 50rpx;
			
			overflow: hidden;
			
			.item {
				float: left;
				margin-right: 25rpx;
				margin-bottom: 30rpx;
				
				width: 200rpx;
				text-align: center;
				.img{
					image{
						width: 200rpx;
						height: 140rpx;
					}
					
					.add{
						font-size: 110rpx;
						color: #DCDCDC;
						text-align: center;
						height: 140rpx;
						line-height: 140rpx;
						background-color: #EEEEEE;
					}
				}
				.text{
					width: 180rpx;
					font-size: 24rpx;
					color: #8e8e8e;
				}
			}
			.item:nth-child(3n){
				margin-right: 0;
			}
		}
	}
</style>
