<template>
	<view class="work-container">
		<!-- 轮播图 -->
		<uni-swiper-dot class="uni-swiper-dot-box" :info="swiperImgData" :current="current" field="content">
			<swiper class="swiper-box" :current="swiperDotIndex" @change="changeSwiper">
				<swiper-item v-for="(item, index) in swiperImgData" :key="index">
					<view class="swiper-item" @click="clickBannerItem(item)">
						<image :src="item.image" mode="aspectFill" :draggable="false" />
					</view>
				</swiper-item>
			</swiper>
		</uni-swiper-dot>

		<!-- 宫格组件 -->
		<view class="grid-body">
			<uni-grid :column="4" :showBorder="false" @change="changeGrid">
				<uni-grid-item v-for="(item, index) in uniGridList" v-if="item.ifData" :index="index+1" :key="index">
					<view class="grid-item-box">
						<uni-icons :type="item.type" :size="30" />
						<text class="text">{{item.text}}</text>
					</view>
				</uni-grid-item>
			</uni-grid>
		</view>
	</view>
</template>

<script>
	// 获取路由
	import {
		getRouters
	} from '@/api/login'
	import {
		checkPermi,
		checkRole
	} from "@/utils/permission"; // 权限判断函数
	export default {
		data() {
			return {
				current: 0,
				swiperDotIndex: 0,
				swiperImgData: [{
						image: '/static/images/banner/banner01.jpg'
					},
					{
						image: '/static/images/banner/banner02.jpg'
					},
					{
						image: '/static/images/banner/banner03.jpg'
					}
				],
				uniGridList: [{
						text: '打卡记录',
						type: "calendar-filled",
						ifData: false
					},
					{
						text: '异常巡检',
						type: "info-filled",
						ifData: "checkRole(['admin'])"
					},
					{
						text: '隐患申报',
						type: "navigate-filled",
						ifData: "checkRole(['admin',common])"
					},
					{
						text: '巡检记录',
						type: "list",
						ifData: "checkRole(['admin'])"
					},
					// {
					// 	text: '申报记录',
					// 	type: "list",
					// 	ifData: "checkRole(['admin'])"
					// },
				]
			}
		},
		created() {
			this.getUserRouters()
		},
		methods: {
			//获取路由
			getUserRouters() {
				let params = {
					menuUseful: 1
				}
				getRouters(params).then(res => {
					// this.iconBoxList=res.data[0].children;
					console.log(res.data[0]);
				});
			},
			checkPermi(res) {
				console.log(res);
			},
			checkRole(res) {
				console.log(res);
			},
			clickBannerItem(item) {
				console.info(item)
			},
			changeSwiper(e) {
				this.current = e.detail.current
			},
			changeGrid(e) {
				let {
					index
				} = e.detail
				if (index == 1) {
					this.$tab.navigateTo("/pages/work/inspection/checkInRecord/index");
				} else if (index == 2) {
					this.$tab.navigateTo("/pages/work/inspection/abnormalList/index");
                } else if (index == 3) {
                    this.$tab.navigateTo("/pages/work/sidebar/filingLog/index");
                } else if (index == 4) {
                    this.$tab.navigateTo("/pages/work/inspection/recordList/index");
                } else if (index == 5) {
                    this.$tab.navigateTo("/pages/work/sidebar/filingLog/index");
                }

			}
		}
	}
</script>

<style lang="scss">
	/* #ifndef APP-NVUE */
	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		background-color: #fff;
		min-height: 100%;
		height: auto;
	}

	view {
		font-size: 14px;
		line-height: inherit;
	}

	/* #endif */

	.text {
		text-align: center;
		font-size: 26rpx;
		margin-top: 10rpx;
	}

	.grid-item-box {
		flex: 1;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 15px 0;
	}

	.uni-margin-wrap {
		width: 690rpx;
		width: 100%;
		;
	}

	.swiper {
		height: 300rpx;
	}

	.swiper-box {
		height: 150px;
	}

	.swiper-item {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		justify-content: center;
		align-items: center;
		color: #fff;
		height: 300rpx;
		line-height: 300rpx;
	}

	@media screen and (min-width: 500px) {
		.uni-swiper-dot-box {
			width: 400px;
			/* #ifndef APP-NVUE */
			margin: 0 auto;
			/* #endif */
			margin-top: 8px;
		}

		.image {
			width: 100%;
		}
	}
</style>