<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="go_link(item)">
					<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="go_link(items)">
					<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 {
		data() {
			return {
				// 当前煤矿编码
				mine_code: "",

				module: [],
				nav: [],
				header: "",
			};
		},
		onLoad() {
			// 初始化当前煤矿编码
			this.mine_code = uni.getStorageSync('mine_code')

			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

				})
			},

			go_link(item) {
				// console.log(item)
				
				let link = item.link
				
				// OA系统
				if(link.indexOf("oa_system.nxmy.com") != -1 ){
					uni.navigateTo({
						url:"../../origanization/OA/h5/h5",
						success: (res) =>{
							// 通过eventChannel向被打开页面传送数据
							res.eventChannel.emit('acceptDataFromOpenerPage', {
								url: link,
							})
						}
					})
					
					return
				}

				// 二维码
				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) {
					console.log("H5")
					// #ifdef APP
					if (plus.os.name == 'Android') {
					
						if (link.indexOf("cmb.pb") != -1) {
							plus.runtime.launchApplication({
								pname: 'cmb.pb'
							}, (e) => {
								console.log('Open system default browser failed: ' + e.message)
					
								uni.showToast({
									icon: "none",
									title: "未安装此应用"
								})
							})
						} else if (link.indexOf("com.icbc") != -1) {
							plus.runtime.launchApplication({
								pname: 'com.icbc'
							}, (e) => {
								console.log('Open system default browser failed: ' + e.message)
					
								uni.showToast({
									icon: "none",
									title: "未安装此应用"
								})
							})
						} else {
							uni.navigateTo({
								url: "../../workbench/h5/h5?url=" + link
							})
						}
					
					
					}
					
					// #endif
					
					// #ifdef H5
					uni.navigateTo({
						url: "../../workbench/h5/h5?url=" + link
					})
					// #endif
				}

				// 原生
				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("/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) {
						console.log("会议列表")
						uni.navigateTo({
							url: "../../workbench/meeting_arrangements/meeting_arrangements"
						})
					} else if (link.indexOf("/workBench/lifeCircleWin") != -1) {
						console.log("生活圈")

						uni.showToast({
							icon: "none",
							title: "暂未开通"
						})
					} else if (link.indexOf("/productionData/logging") != -1) {
						console.log("下井记录")
						// 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=640323B0011010019259"
							})
						} 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=640323B0011010019259"
							})
						}

					}else if(link.indexOf("/browseQrcode/gridSubmitItem_win") != -1){
						console.log("网格排查")
						uni.navigateTo({
							url:"../../workbench/gridding/gridding"
						})
					}else if(link.indexOf("/workBench/evaluate") != -1){
						console.log("干部评测")
						uni.navigateTo({
							url:"../../workbench/h5/h5?mine_code=zaoquan&workBench=pingce"
						})
					} else {
						uni.showToast({
							icon: "none",
							title: "暂未开通"
						})
					}
				}
			}

		},

	}
</script>

<style>
	page {
		background-color: #F5F5F5;
	}

	.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-between; */
		margin-top: 10rpx;
		overflow: hidden;
	}

	.headers_ul::after {
		content: '';
		width: 25%;
	}

	.headers_title {
		margin-left: 40rpx;
		padding-top: 30rpx;
		padding-bottom: 5rpx;
	}

	.headers_li {
		float: left;

		width: 25%;
		text-align: center;
		margin-bottom: 25rpx;
		margin-top: 25rpx;
	}

	.headers_li_img>image {
		width: 100rpx;
		height: 100rpx;
		margin-bottom: 10rpx;
	}

	.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>
