<template>
	<view class="hzIndex">
		<hzHeader title="全部菜单"></hzHeader>
		<view class="hzContent">
			<view class="box-wrap">
				<view @click="navTo(item.pageUrl,item.code,item.children)" class="box-column"
					v-for="(item, index) in permissions" :key="index" v-if="item.isOpen == 0">
					<image class="box-image" :src="item.iconUrl"></image>
					<view class="box-name">{{item.name}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getUserPermission3,
		travelPolicyList
	} from '@/common/api.js';
	import {
		callbackRequest,
		formatDate,
		getStorage,
		callbackRequestNoLoading,
		alertTip
	} from '@/common/util.js';
	export default {
		data() {
			return {
				formatDate: formatDate,
				permissions: [],
				travelPolicy: []

			}
		},
		onLoad(option) {
			this.permissions = JSON.parse(option.permissions) || [];
		},
		methods: {
			getUserPermissions(code) {
				let that = this;
				let userId = getStorage('userInfo').userId;
				callbackRequestNoLoading({
					method: getUserPermission3,
					data: {
						userId: userId,
						parentCode: code
					}
				}).then(res => {
					if (res.data.returnCode == 1) {
						that.permissions = res.data.returnData;
					} else {
						console.log('获取权限失败');
					}
				});
			},
			navTo(url, code, child) {
				let where = "";
				for (let i = 0; i < child.length; i++) {
					if (child[i].type == 1) {
						if (url.indexOf('?') != -1) {
							url = url + '&' + child[i].pageUrl;
						} else {
							url = url + '?' + child[i].pageUrl;
						}
					}
				}
				if (!url) {
					alertTip('敬请期待');
				}
				if (url && url.startsWith('/')) {
					if (url.indexOf('?') != -1) {
						url = url + '&code=' + code;
					} else {
						url = url + '?code=' + code;
					}
					if (child.length > 0) {
						url = url + '&permissions=' + JSON.stringify(child);
					}
					// console.log(url);
					uni.navigateTo({
						url
					});
				} else if (url) {

					window.location.href = url;
				}

			},
		}
	}
</script>

<style lang="scss">
	.hzContent {
		padding: 20upx;


		.box-wrap {
			display: flex;
			flex-wrap: wrap;
			background-color: #fff;
			border-radius: 20upx;
			padding-bottom: 30upx;

			.box-column {
				width: 25%;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				margin-top: 30upx;

				.box-name {
					font-weight: 400;
					font-size: 26upx;
					color: #333333;
					margin-top: 20upx;
				}

				image {
					width: 54upx;
					height: 54upx;
				}
			}
		}
	}
</style>