<template>
	<page-meta root-font-size="system" />
	<view class="content">
		<!-- 用户信息部分 -->
		<uni-card margin="0" spacing="0">
			<view class="headImg">
				<image :src="config.baseUrlPre + ((userStore.user.photo ?? '') || config.defaultAvatarPath)" class="avatar" @click="toEditAvatar"></image>
			</view>
			<view class="user-info" @click="lookMsg()">
				<view class="info-detail">
					<view class="name">
						<text>姓名: {{ userStore.user.name}}</text>
					</view>
					<!-- <view class="desc">
						<text>ID: {{ userStore.user.useId }}</text>
					</view> -->
					<!-- 部门切换框 -->
					<view class="uni-list-cell">
						<view class="uni-list-cell-left">
							部门:
						</view>
						<view class="uni-list-cell-db" @click.stop="">
							<picker @change.stop="bindPickerChange" :value="index" :range="deptNameArray">
								<view class="uni-input">
								{{ deptNameArray[index] }}
								</view>
							</picker>
						</view>
					</view>
					<view class="desc">
						<text> 职务: {{ userStore.user.groupXUsers[index].posName ||'暂无'}}</text>
					</view>

				</view>
				<uni-icons type="forward" size="16" margin-left="10px"></uni-icons>
			</view>
		</uni-card>

		<uni-card margin="0" spacing="0" is-shadow="false">
			<!-- 功能按钮区 -->
			<view class="function-list">
				<view class="function-item" @click="editData">
					<text class="ygoa_icon icon-edit"></text>
					<text class="title">编辑资料</text>
					<text class="desc"></text>
				</view>

				<view class="function-item" @click="checkIn">
					<text class="ygoa_icon icon-checkIn"></text>
					<text class="title">我的考勤</text>
					<text class="desc"></text>
				</view>

				<view v-if="config.companyCode !== 'yz'" class="function-item" @click="clockIn">
					<text class="ygoa_icon icon-clockIn"></text>
					<text class="title">我的打卡</text>
					<text class="desc"></text>
				</view>
				
				<!-- 根据companyCode显示我的工资 -->
				<view v-if="config.companyCode === 'yz'" class="function-item" @click="mySalary">
					<text class="ygoa_icon icon-calculator"></text>
					<text class="title">我的工资</text>
					<text class="desc"></text>
				</view>
							
				<view class="function-item" @click="myTrain">
					<text class="ygoa_icon icon-diary"></text>
					<text class="title">我的培训</text>
					<text class="desc"></text>
				</view>
				
				<view class="function-item" @click="setting">
					<text class="ygoa_icon icon-setting"></text>
					<text class="title">应用设置</text>
					<text class="desc"></text>
				</view>
			</view>
		</uni-card>


	</view>
</template>

<script setup lang="ts">
	import { onMounted, ref } from 'vue';
	import $tab from "@/plugins/tab.js"
	import { useUserStore } from '@/store/user.js'
	import config from '@/config';
	import { onShow } from '@dcloudio/uni-app'
	const userStore = useUserStore()

	onShow(() => {
		uni.$emit('showTabBarBadge')
	})

	// 部门数组
	const deptNameArray = ref(['研发部', '业务部', '法务部']);
	const index = ref(0);
	onMounted(() => {
		initDeptArray();
	})

	//部门初始化
	function initDeptArray() {
		const groupXUsers = userStore.user.groupXUsers;
		// 使用map方法提取groupName
		deptNameArray.value = groupXUsers.map(groupXUser => groupXUser.groupName) || ['无数据'];
	}

	// 部门切换事件
	function bindPickerChange(e) {
		index.value = e.detail.value; // 更新选择的部门索引
	};

	// 查看个人信息的函数
	function lookMsg() {
		$tab.navigateTo('/pages/mine/personal_message/personal_message?id=' + userStore.user.useId + '&name=' + userStore.user.name);
	};

	// 编辑资料的函数
	function editData() {
		$tab.navigateTo('/pages/mine/edit/edit')
	};

	// 我的考勤的函数
	function checkIn() {
		$tab.navigateTo('/pages/mine/checkIn/checkIn')
	}

	// 应用设置的函数
	function setting() {
		$tab.navigateTo('/pages/mine/setting/setting')
	};

	// 打卡的函数
	function clockIn() {
		$tab.navigateTo('/pages/mine/clockIn/clockIn')
	};
	
	// 我的工资的函数
	function mySalary() {
		$tab.navigateTo('/pages/mine/salary/salaryList')
	}
	
	// 我的培训的函数
	function myTrain() {
		$tab.navigateTo('/pages/mine/train/trainList')
	}
	
	//头像修改页
	function toEditAvatar() {
		// $tab.navigateTo('/pages/mine/avatar/avatarTest/avatarTest')
		$tab.navigateTo('/pages/mine/avatar/avatar')
	}
</script>

<style lang="scss" scoped>
	// @import "@/static/font/ygoa/iconfont.css";

	.ygoa_icon {
		margin-right: calc(10px + .5*(1rem - 16px)) !important;
		font-size: calc(1.6rem + 0px) !important;
	}

	.content {
		display: flex;
		flex-direction: column;
	}


	.user-info {
		display: flex;
		align-items: center;
		padding: 16px 48px;
		border-bottom: 1rpx solid #666;
		color: #777;
		::v-deep .uni-icons {
			font-size: calc(1rem + 0px) !important;
		}
	}


	.avatar {
		width: calc(6.25rem + 0px) !important;
		height: calc(6.25rem + 0px) !important;
		border-radius: 50%;
	}

	.info-detail {
		flex-grow: 1;
		// text-align: center;
		.name {
			padding: 0.5rem 0;
			color: #333;
			font-size: calc(1.1rem + 0px) !important;
		}
		.desc {
			font-size: calc(0.875rem + 0px) !important;
		}
	}




	.function-list {
		margin-bottom: calc(16px + .5*(1rem - 16px)) !important;
	}

	.function-item {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: calc(12px + .5*(1rem - 16px)) !important;
		background-color: #ffffff;
		border-radius: 10rpx;
		margin-bottom: 0.75rem;
		border-bottom: 1px solid gainsboro;
	}


	.title {
		flex-grow: 1;
		font-size: calc(1rem + 0px) !important;
	}

	.desc {
		color: #777;
		margin-right: 0.5rem;
	}

	.desc::after {
		content: ">";
	}

	.select1 {
		display: inline-block;
		width: 50%;
		margin-top: 0.3rem;
	}

	.headImg {
		text-align: center;
	}


	//样式穿透
	::v-deep .uni-list-cell {
		justify-content: left;
	}

	::v-deep .uni-list-cell-left {
		padding: 0 0;
		font-size: calc(1.1rem + 0px) !important;
		color: #333;
		flex: none;
	}

	::v-deep .uni-list-cell::after {
		background-color: #f5f5f5;
	}

	::v-deep .uni-input {
		padding: 0.5rem 0.25rem;
		text-decoration: underline;
		/* 给文字添加下划线 */
		color: blue;
		font-size: calc(1.1rem + 0px) !important;
		background-color: #f5f5f5;
		overflow: hidden;
		/* 隐藏超出部分 */
		white-space: nowrap;
		/* 不换行 */
		text-overflow: ellipsis;
		/* 省略号 */
		max-width: 30vh;
	}


	::v-deep .uni-list-cell-db,
	.uni-list-cell-right {
		flex: none;
	}

	::v-deep .uni-card {
		background-color: #f5f5f5 !important;
	}

	::v-deep .uni-card--shadow {
		box-shadow: none !important;
	}

	::v-deep .uni-card--border {
		border: none !important;
	}
</style>