<template>
	<view class="internal-management">
		<VNavigationBar style="position: relative;z-index: 99;" homeHeaderPaddingTop="0" backgroundColor="#fff"
			title-color="#000" title="内部管理"></VNavigationBar>
		<!-- 内容区域 -->
		<view class="content">
			<view class="menu-box" v-for="(item, index) in filteredList" :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 {
		getToken,
		getUserInfo,
		getJSONData,
	} from '@/utils/auth'
	import tabBarVue from "@/components/tabBar/tabBar.vue";
	import {
		checkPermi,
		checkRole
	} from "@/utils/permission"; // 权限判断函数
	import VNavigationBar from "@/components/VNavigationBar.vue";


	export default {
		components: {
			tabBarVue,
			VNavigationBar
		},
		data() {
			return {
				menuList: [{
						id: 1,
						name: '员工管理',
						icon: '/static/icons/internal/staff.png'
					},
					{
						id: 2,
						name: '资料管理',
						icon: '/static/icons/internal/database.png'
					},
					{
						id: 3,
						name: '工作汇报',
						icon: '/static/icons/internal/workReport.png'
					},
					{
						id: 4,
						name: '设备管理',
						icon: '/static/icons/internal/device.png',
						requiredPermission: true
					}
				],
				customInfo: null,
				coachInfo: null,
				staff: null,
				filteredList: []
			}
		},
		created() {
			if (!getToken()) {
				uni.reLaunch({
					url: '/pages/login/loginSms'
				});
				return;
			}
			if (this.checkRole(['tenant_admin', 'weixiu'])) {
				this.filteredList = this.menuList;

			} else {
				this.filteredList = this.menuList.filter(item => [2, 3].includes(item.id));
			}
		},
		methods: {
			checkPermi,
			checkRole,
			goManage(id) {
				const routes = {
					1: '/pages-internal/staffManagement/NewstaffManagement',
					2: '/pages-internal/dataManagement/deviceManage',
					3: '/pages-internal/workReport/reportList',
					4: '/pages-internal/deviceManagement/deviceManage',
				}
				if (routes[id]) {
					uni.navigateTo({
						url: routes[id]
					});
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.internal-management {
		display: flex;
		flex-direction: column;
		min-height: 100vh;
		background: #F1F3F6;
	}

	.content {
		flex: 1;
		padding: 30rpx;
	}

	.menu-box {
		width: 100%;
		height: 128rpx;
		background-image: url('/static/icons/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;
		border: 2rpx solid #0174F6;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #0174F6;
		font-size: 28rpx;
		border-radius: 30rpx 30rpx 30rpx 30rpx;
	}
</style>