<template>
	<view class="headers">
		<view class="headers_img">
			<image :src="header" mode="aspectFill"></image>
		</view>
		<view class="headers_nav">
			<view class="headers_ul">
				<view class="headers_li" v-for="(item,index) in nav" :key="index" @click="getnav(item.link)">
					<view class="headers_li_img">
						<image :src="item.icon" mode=""></image>
					</view>
					<view class="headers_li_text">  
						{{item.title}}
					</view>
			   </view>
			</view>  
		</view>
		
		
		<view class="headers_list" v-for="(item,index) in module" :key="index">
			<view class="headers_title">
				<text class="headers_title_h1">
					{{item.title}}				
				</text>	
			</view>
			<view class="headers_ul" >
				<view class="headers_li" v-for="(items,index) in item.children" :key="index" @click="getmodule(items.link)">
					<view class="headers_li_img">
						<image :src="items.icon" mode=""></image>
					</view>
					<view class="headers_li_text">  
						{{items.title}}
					</view>
					
				</view>
			</view>
		</view>	
	</view>
</template>

<script>
	export default {
		props: [
			"mine_code"
		],
		data() {
			return {
				module:[],
				nav:[],
				header:"",
			};
		},
		created() {
			this.getworkbench()
		},
		methods:{
			getworkbench(){
				this.$api.workbench_index({
		
				}).then((res)=>{
					// console.log(res)
					this.header=res.data.data.header
					this.nav=res.data.data.nav
					this.module=res.data.data.module
					
				})
			},
			getnav(link){
				console.log(link)
				// 二维码
				if(link.indexOf("pageId") != -1 && link.indexOf("app:") == -1){
					let pageId = ""
					function GetQueryString(name) {
						var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
						var r = link.match(reg);
						if (r != null) return unescape(r[2]);
						return null;
					}
					console.log(GetQueryString("pageId"))
					if (GetQueryString("pageId")) {
						pageId = GetQueryString("pageId")
					} else {
						pageId = link.split('=')[1]
					}
					
					uni.navigateTo({
						url:"../../index/record/record?pageId=" + pageId + "&mine_code=" + this.mine_code,
					})
				}
				// h5
				if(link.indexOf("pageId") == -1 && link.indexOf("app:") == -1){
					uni.navigateTo({
						url:"../../workbench/h5/h5?url=" + link
					})
				}
				// 原生
				if(link.indexOf("pageId") == -1 && link.indexOf("app:") != -1){
					console.log("原生")
					
					console.log(link)
					
					if(link.indexOf("/news/news_win") != -1){
						console.log("通知公告")
						
						uni.navigateTo({
							url:"../../my/message-reminder/message-reminder"
						})
					}else if(link.indexOf("/workBench/getDuty") != -1){
						console.log("值班信息")
						
						uni.navigateTo({
							url:"../../workbench/duty_information/duty_information"
						})
					}else if(link.indexOf("/workBench/huiyiList") != -1){
						uni.showToast({
							icon:"none",
							title:"暂时没有会议"
						})
					}else{
						uni.showToast({
							icon:"none",
							title:"暂未开通"
						})
					}
					
				}
			},
			getmodule(link){
				console.log(link)
				console.log(this.mine_code)
				
				// 二维码
				if(link.indexOf("pageId") != -1 && link.indexOf("app:") == -1){
					let pageId = ""
					function GetQueryString(name) {
						var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
						var r = link.match(reg);
						if (r != null) return unescape(r[2]);
						return null;
					}
					console.log(GetQueryString("pageId"))
					if (GetQueryString("pageId")) {
						pageId = GetQueryString("pageId")
					} else {
						pageId = link.split('=')[1]
					}
					
					uni.navigateTo({
						url:"../../index/record/record?pageId=" + pageId + "&mine_code=" + this.mine_code,
					})
				}
				// h5
				if(link.indexOf("pageId") == -1 && link.indexOf("app:") == -1){
					uni.navigateTo({
						url:"../../workbench/h5/h5?url=" + link
					})
				}
				// 原生
				if(link.indexOf("pageId") == -1 && link.indexOf("app:") != -1){
					console.log("原生")
					
					console.log(link)
					// 发票助手
					if(link.indexOf("/workBench/invoice") != -1){
						console.log("发票助手")
						uni.navigateTo({
							url:"../../workbench/invoice_assistant/invoice_assistant"
						})
					}else if(link.indexOf("/productionData/logging") != -1){
						console.log("下井记录")
						// uni.navigateTo({
						// 	url:"../../production/personnel_orientation/downhole_statistics/downhole_statistics?people_num="+people_num+"&depart_name="+depart_name+"&name="+name+"&mine="+this.mine
						// })
						
						// people_num 特殊值
						if(!uni.getStorageSync('people_code')){
							uni.navigateTo({
								url:"../../production/personnel_orientation/downhole_statistics/downhole_statistics?people_num=null&depart_name="+uni.getStorageSync('user').section+"&name="+uni.getStorageSync('user').name+"&mine=640181B0011010037723"
							})
						}else{
							uni.navigateTo({
								url:"../../production/personnel_orientation/downhole_statistics/downhole_statistics?people_num="+uni.getStorageSync('user').people_code+"&depart_name="+uni.getStorageSync('user').section+"&name="+uni.getStorageSync('user').name+"&mine=640181B0011010037723"
							})
						}
						
					}else if(link.indexOf("/browseQrcode/gridSubmitItem_win") != -1){
						console.log("网格排查")
						uni.navigateTo({
							url:"../../workbench/gridding/gridding"
						})
					}
				}
				
			}
		},
		
	}
</script>

<style>
	.headers{
		width: 100%;
		background-color: #F5F5F5;
	}
	.headers_img>image{
		width: 100%;
		height: 360rpx;
	}
	.headers_nav{
		width: 100%;
		background-color: #FFFFFF;
		margin-bottom: 25rpx;
	}
	.headers_ul{
		width: 100%;
		display: flex;
		 flex-wrap:wrap;
		justify-content: space-around;
		margin-top: 10rpx;
	}
	.headers_ul::after{
		content: '';
		width: 25%;
	}
	.headers_title{
		margin-left: 40rpx;
		padding-top: 30rpx;
		padding-bottom: 5rpx;
	}
	.headers_li{
		width: 25%;
		text-align: center;
		margin-bottom: 25rpx;
		margin-top: 25rpx;
	}
	.headers_li_img>image{
		width: 100rpx;
		height: 100rpx;
		margin-bottom: 20rpx;
	}
	.headers_li_text{
		font-size: 14px;
	}
	.headers_title_h1{
		font-weight: 800;
	}
	.headers_list{
		width: 100%;
		background-color: #fff;
	}
	.ly-tree-node__label{
		color: #000000;
	}
</style>
