<template>
	<view class="wrap">
		<u-row gutter="16" justify="space-between">
			<u-col span="12">
				<view class="demo-layout bg-blue" style="text-align: left;padding-left: 20rpx;">当前登录人：{{userInfo.name}}
				</view>
			</u-col>
		</u-row>
		<u-row gutter="16">

			<u-col span="6" v-if="isshowxc">
				<view class="demo-layout bg-purple-light" @click="toviewplan(1)">
					<text class="iconfont icon-zuzhijiagouguanli"></text>
					<text class="navtxt">巡查计划</text>
				</view>
			</u-col>
			<u-col span="6" v-if="isshowxc">
				<view class="demo-layout bg-purple-light" @click="toview(5)">
					<text class="iconfont icon-guanxianxuncha"></text>
					<text class="navtxt">雨管巡查</text>
				</view>
			</u-col>
		</u-row>
		<u-row gutter="16">
			<u-col span="6" v-if="isshowyh">
				<view class="demo-layout bg-purple" @click="toviewplan(2)">
					<text class="iconfont icon-zuzhijiagouguanli"></text>
					<text class="navtxt">养护计划</text>
				</view>
			</u-col>
			<u-col span="6" v-if="isshowyh">
				<view class="demo-layout bg-purple" @click="toview(4)">
					<text class="iconfont icon-guanxianyanghu"></text>
					<text class="navtxt">雨管养护</text>
				</view>
			</u-col>
		</u-row>
		<!-- <u-row gutter="16">
		
		
			<u-col span="12">
				<view class="demo-layout bg-purple-light" @click="toview(6)">
					<text class="iconfont icon-gongnengxingquexianshuju"></text>
					<text class="navtxt">工单执行</text>
				</view>
			</u-col>
		</u-row> -->
		<u-row gutter="16" v-if="isshowrc">


			<u-col span="12">
				<view class="demo-layout bg-purple-light" @click="toview(3)">
					<text class="iconfont icon-zaixianjiance"></text>
					<text class="navtxt">日常监管巡查</text>
				</view>
			</u-col>
		</u-row>
		<u-row gutter="16" justify="space-between">
			<u-col span="8" v-if="isshowty">
				<view class="demo-layout bg-purple" @click="toview(1)">
					<text class="iconfont icon-caidanguanli"></text>
					<text class="navtxt">通用巡查</text>
				</view>
			</u-col>
			<u-col span="4">
				<view class="demo-layout bg-purple-light" @click="toview(2)">
					<text class="iconfont icon-yonghugerenzhongxin"></text>
					<text class="navtxt">我的</text>
				</view>
			</u-col>
		</u-row>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				title: '',
				userInfo: {
					allow_menu_list: -1
				},
				isshowty: false,
				isshowxc: false,
				isshowyh: false,
				isshowrc: false
			}
		},
		onLoad() {
			this.loadInfo();
		},
		mounted() {
			var a = document.getElementsByClassName('uni-page-head-btn')[0]
			a.style.display = 'none';
		},
		watch: {
			userInfo: {
				// 每个属性值发生变化就会调用这个函数
				handler(newVal, oldVal) {
					this.isshowty = this.hasMenu(4);
					this.isshowxc = this.hasMenu(1);
					this.isshowyh = this.hasMenu(2);
					this.isshowrc = this.hasMenu(3);
				},
				// 立即处理 进入页面就触发
				immediate: true,
				// 深度监听 属性的变化
				deep: true
			}
		},
		onNavigationBarButtonTap(val) {
			window.android.finish();
		},
		methods: {
			hasMenu(menu_id) {
				if (this.userInfo.allow_menu_list == -1) return false;
				if (this.userInfo.allow_menu_list.length == 0) {
					return true;
				} else {
					let list = this.userInfo.allow_menu_list.filter((item) => {
						return item == menu_id;
					});

					return list > 0;

				}
			},
			loadInfo() {
				let that = this;
				this.util.request({
					api: '/api/mobile/auth/me',
					method: 'POST',
					utilSuccess: function(res) {
						that.userInfo = res;
					},
					utilFail: function(res) {
						that.util.alert(res);
					}
				});
			},

			toviewplan(type) {
				var url = '/raininspection/plan/plan';
				if (type == 2) {
					url = "/rainmaintain/plan/plan"
				}
				uni.navigateTo({
					url: url
				})


			},
			toview(type) {
				let url = "/packageA/pages/generalPatrol/generalPatrol";
				// let url = "/road/road/road?type=general"
				if (type == 2) {
					url = "/pages/mine/mine"
				}
				if (type == 3) {
					// url = "/road/road/road?type=daily"
					url = "/packageB/pages/dailyInspection/dailyInspection"
				}
				if (type == 4) {
					url = "/road/road/road?type=rainmaintain"
					// url = "/rainmaintain/rainmaintain/rainmaintain"
				}
				if (type == 5) {
					url = "/road/road/road?type=raininspection"
					// url = "/raininspection/raininspection/raininspection"
				}
				// if (type == 6) {
				// 	url = "/order/order/order/order"
				// }
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.wrap {
		padding: 24rpx;
	}

	.u-row {
		margin: 40rpx 0;
	}

	.demo-layout {
		border-radius: 8rpx;
		text-align: center;
		display: flex;
		flex-direction: column;
		padding: 20rpx 0rpx;
	}

	.navtxt {
		margin-top: 20rpx;
		color: #000000;
	}

	.iconfont {
		color: #338de3;
		font-size: 64rpx;

	}

	.bg-purple {
		background: #d3dce6;
	}

	.bg-blue {
		background: #338de3;
		color: #fff;
	}

	.bg-purple-light {
		background: #e5e9f2;
	}

	.bg-purple-dark {
		background: #99a9bf;
	}
</style>
