<template>
	<view>
		<u-navbar class="u-navbar-box" title="我的" placeholder bgColor="transparent" left-icon-size="0" />
		<view class="top-box">
			<u-image class="bg-box" width="690rpx" height="270rpx" src="/static/mine/user-center-bg.png" />
			<div class="avatar-name" style="z-index: 9;">
				<up-avatar size="116rpx" :src="computeAvatarUrl" defaultUrl="/static/mine/avatar-def.png"
					bgColor="#305BFF" />
				<!-- <u-image class="avatar" width="116rpx" bgColor="transparent" height="116rpx"
					src="/static/mine/avatar-def.png" /> -->
				<view style="margin-left: 30rpx;">
					<view class="name">{{user.nickName}}</view>
					<view class="roles">{{handleRolesText()}}</view>
				</view>

			</div>
			<div class="abs-right">
				<u-image bgColor="transparent" width="220rpx" height="258rpx" src="/static/mine/user-center-img.png" />
			</div>
		</view>
		<u-cell-group :border="false" :customStyle="{background: '#fff', margin: '30rpx', borderRadius: '20rpx'}">
			<!-- 街道 -->
			<u-cell v-if="vuex_user.roles.includes('village')" title="护理初审" isLink url="/pages/subpack/pages/application/list">
				<template #icon>
					<u-image src="/static/mine/task.png" bgColor="transparent" width="36rpx" height="36rpx" />
				</template>
			</u-cell>
			<!-- 区民政 -->
			<u-cell v-if="vuex_user.roles.includes('area')" title="护理审核" isLink url="/pages/subpack/pages/application/list">
				<template #icon>
					<u-image src="/static/mine/task.png" bgColor="transparent" width="36rpx" height="36rpx" />
				</template>
			</u-cell>
			<!-- 护理人员 -->
			<u-cell v-if="vuex_user.roles.includes('nurse')" title="护理打卡" isLink url="/pages/subpack/pages/application/list">
				<template #icon>
					<u-image src="/static/mine/task.png" bgColor="transparent" width="36rpx" height="36rpx" />
				</template>
			</u-cell>
			<!-- 护理公司 -->
			<u-cell v-if="vuex_user.roles.includes('company')" title="我的申请" isLink url="/pages/subpack/pages/application/list?flag=0">
				<template #icon>
					<u-image src="/static/mine/task.png" bgColor="transparent" width="36rpx" height="36rpx" />
				</template>
			</u-cell>
			<u-cell v-if="vuex_user.roles.includes('company')" title="护理指派" isLink url="/pages/subpack/pages/application/list?flag=1">
				<template #icon>
					<u-image src="/static/mine/task.png" bgColor="transparent" width="36rpx" height="36rpx" />
				</template>
			</u-cell>
			
			<u-cell icon="integral-fill" title="个人信息" isLink :border="false" url="/pages/subpack/pages/myInfo/info">
				<template #icon>
					<u-image src="/static/mine/myself.png" bgColor="transparent" width="36rpx" height="36rpx" />
				</template>
			</u-cell>
			<u-cell icon="integral-fill" title="用户协议" isLink :border="false" url="/pages/subpack/pages/protocol/list">
				<template #icon>
					<u-image src="/static/mine/myself.png" bgColor="transparent" width="36rpx" height="36rpx" />
				</template>
			</u-cell>
		</u-cell-group>
	</view>
</template>

<script setup>
	import {
		onMounted,
		ref,
		computed,
		getCurrentInstance
	} from 'vue';
	import {
		useStore
	} from 'vuex';
	import {
		onLoad,
		onShow
	} from '@dcloudio/uni-app'

	const {
		proxy
	} = getCurrentInstance();
	// 获取 Vuex store 实例
	const store = useStore();
	const user = ref({
		nickName: ' ',
		roles: []
	})

	const roleKV = {
		common: '普通角色',
		admin: '超级管理员',
		village: '乡镇民政所',
		area: '区民政局',
		company: '护理公司',
		nurse: '护理员'
	}

	const computeAvatarUrl = computed(() => {
		// console.log('proxy.vuex_user.avatar', proxy.vuex_user.avatar);
		// console.log('proxy.vuex_user.avatar', uni.$u.http.config.baseURL);
		return uni.$u.http.config.baseURL + proxy.vuex_user.avatar
	})

	function handleRolesText() {
		let roles = user.value.roles;
		let roleText = [];
		roles.map(item => {
			if (roleKV.hasOwnProperty(item)) {
				roleText.push(roleKV[item]);
			}
		})
		return roleText.join(',');
	}
	onShow(() => {
		// console.log('store=>', store.state);
		user.value = store.state.vuex_user;
	})
</script>
<style>
	page {
		background-color: #F6F8FD;
	}
</style>
<style lang="scss" scoped>
	:deep(.u-image) {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	:deep(.u-navbar__content__title) {
		font-weight: bold;
		font-size: 36rpx;
		color: #222222;
	}

	.u-navbar-box {
		background: radial-gradient(circle at left, #FFE5E4 0%, #EEF2F5 40%, #DBEEFB 100%);
	}

	.top-box {
		position: relative;
		margin: 30rpx;

		.avatar-name {
			position: absolute;
			top: 77rpx;
			left: 40rpx;
			display: flex;
			align-items: center;

			.name {
				font-weight: bold;
				font-size: 40rpx;
				color: #000000;
			}

			.roles {
				font-size: 28rpx;
				margin-top: 10rpx;
				color: #000000;
			}
		}

		.abs-right {
			position: absolute;
			bottom: 20rpx;
			right: 40rpx;
		}

	}
</style>