<template>
	<view class="internal-management">
		<view class="top-rail"></view>
		<view class="page-top" :style='{ justifyContent: "center" }'>

			<!-- 返回上一级页面信息 -->
			<view class='go-back-page' @click='pageBack'>返回</view>

			<!-- 人员/车辆/我的组件显示的表头信息 -->
			<view class="other-title-class">
				内部管理
			</view>
		</view>


		<!-- 内容区域 -->
		<view class="content">
			<view class="menu-box" v-for="(item, index) in filteredMenuList" :key="index" @click="goManage(item.id)">
				<view class="menu-content">
					<image :src="item.icon" mode="aspectFit" style="width: 60rpx; height: 60rpx;"></image>
					<text>{{item.name}}</text>
				</view>
				<view class="action-button">
					去查看
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		ifHasRoleByDictType
	} from "@/utils/utils";
	export default {
		data() {
			return {
				hasStaffPermission: false,
				menuList: [{
						id: 1,
						name: '员工管理',
						icon: '/static/internal/staff.png',
						requiredPermission: true
					},
					{
						id: 2,
						name: '资料管理',
						icon: '/static/internal/database.png',
						requiredPermission: false
					},
					{
						id: 3,
						name: '工作汇报',
						icon: '/static/internal/workReport.png',
						requiredPermission: false
					},
					{
						id: 4,
						name: '设备管理',
						icon: '/static/internal/device.png',
						requiredPermission: true
					}
				]
			}
		},
		computed: {
			filteredMenuList() {
				return this.menuList.filter(item => {
					// 如果菜单不需要权限，或者需要权限但用户有权限，则显示
					return !item.requiredPermission || (item.requiredPermission && this.hasStaffPermission);
				});
			}
		},
		async created() {
			try {
				// 获取权限状态，使用await等待异步结果
				this.hasStaffPermission = await ifHasRoleByDictType('rescue_menu_permissions');
				console.log('this.hasStaffPermission', this.hasStaffPermission);
			} catch (error) {
				console.error('获取权限失败:', error);
				// 默认无权限
				this.hasStaffPermission = false;
			}
		},
		methods: {
			goManage(id) {
				const routes = {
					1: '/pages/internal/NewstaffManagement',
					2: '/pages/internal/rescueManage',
					3: '/pages/internal/reportList',
					4: '/pages/internal/deviceManage'
				}
				if (routes[id]) {
					uni.navigateTo({
						url: routes[id]
					})
				}
			},
			pageBack() {
				uni.navigateBack({
					delta: 1 // delta值为1时表示返回的页面层数
				});
			},
		}
	}
</script>

<style lang="scss">
	.internal-management {
		height: 100%;
		background-color: #f1f3f6;

		.top-rail {
			height: 60rpx;
			width: 100%;
			background-color: #054DF3;
		}

		.custom-navbar {
			height: 88rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			background-color: #ffffff;
			position: fixed;
			top: 0;
			left: 0;
			right: 0;
			z-index: 10;
			box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);

			.title {
				font-size: 36rpx;
				font-weight: bold;
				color: #333333;
			}
		}

		.content {
			padding: 30rpx;
		}

		.menu-box {
			width: 100%;
			height: 128rpx;
			background-image: url('/static/internal/box_.png');
			background-size: 100% 100%;
			box-sizing: border-box;
			padding: 0 24rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			font-size: 32rpx;
			color: #000000;
			margin-bottom: 30rpx;
			border-radius: 12rpx;

			.menu-content {
				display: flex;
				align-items: center;

				image {
					width: 80rpx;
					height: 80rpx;
					margin-right: 20rpx;
				}

				text {
					font-weight: 500;
				}
			}
		}

		.action-button {
			width: 144rpx;
			height: 66rpx;
			background: #327DFB;
			display: flex;
			align-items: center;
			justify-content: center;
			color: #fff;
			font-size: 28rpx;
			border-radius: 50px;
		}
	}

	.page-top {
		flex-shrink: 0;
		width: 100%;
		height: 160rpx;
		display: flex;
		align-items: center;
		color: white;
		flex-shrink: 0;
		background: linear-gradient(180deg, #054DF3 0%, #55A3FF 100%);
		// margin-top: 50rpx;

		.go-back-page {
			position: absolute;
			left: 20rpx;
		}
	}
</style>