<template>
	<view>
		<!-- 工作台头图 -->
		<view class="top">
			<image :src="header"></image>
		</view>
		
		<!-- nav -->
		<view class="section">
			<view class="title"></view>
			<view class="list">
				<view class="item" v-for="(item,index) in nav" :key="index"  @click="go_link(item)">
					<view class="icon">
						<view class="num" v-if="item.link.indexOf('http://oa_system.nxmy.com:8011/?m=ying&d=we&num=daiban&hideheader=true') != -1 && num_1 > 0">{{num_1}}</view>
						<view class="num" v-if="item.link.indexOf('http://oa_system.nxmy.com:8011/?m=ying&d=we&num=todo&hideheader=true') != -1 && num_2 > 0">{{num_2}}</view>
						<image :src="item.icon" mode=""></image>
					</view>
					<view class="name">{{item.title}}</view>
				</view>
			</view>
		</view>
		
		<view class="section" v-for="(item,index) in module" :key="index">
			<view class="title">{{item.title}}</view>
			<view class="list">
				<view class="item" v-for="(item_2,index_2) in item.children" :key="index_2"  @click="go_link(item_2)">
					<view class="icon">
						<image :src="item_2.icon" mode=""></image>
					</view>
					<view class="name">{{item_2.title}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 当前煤矿编码
				mine_code: "",
				
				// 头部图片
				header:"",
				nav: [],
				module: [],
				
				num_1:0,
				num_2:0
			};
		},
		onLoad() {
			// 初始化当前煤矿编码
			this.mine_code = uni.getStorageSync('mine_code')

			this.get_workbench_index()
			
			this.get_workflow_todo_query_1()
			this.get_workflow_todo_query_2()
		},
		methods: {
			// 获取基础数据
			get_workbench_index(){
				this.$api.workbench_index({
				
				}).then((res) => {
					// console.log(res.data.data)
					
					this.header = res.data.data.header
					this.nav = res.data.data.nav
					this.module = res.data.data.module
				})
			},
			
			// 获取消息提醒数量
			get_workflow_todo_query_1(){
				this.$api.workflow_todo_query({
					staff_num: uni.getStorageSync('user').staff_num,
					query_type: 2
				}).then((res)=>{
					console.log(res.data.content.data)
					
					this.num_1 = res.data.content.data
				})
			},
			get_workflow_todo_query_2(){
				this.$api.workflow_todo_query({
					staff_num: uni.getStorageSync('user').staff_num,
					query_type: 1
				}).then((res)=>{
					console.log(res.data.content.data)
					
					this.num_2 = res.data.content.data
				})
			},

			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 lang="scss">
	page{
		background-color: #F2FAF7;
	}
	.top{
		image{
			width: 750rpx;
			height: 270rpx;
			display: block;
		}
	}
	
	.section{
		margin-top: 20rpx;
		background-color: #FFFFFF;
		
		box-sizing: border-box;
		padding: 25rpx;
		.title{
			font-weight: 700;
			font-size: 34rpx;
		}
		
		.list{
			margin-top: 30rpx;
			width: 700rpx;
			overflow: hidden;
			.item{
				float: left;
				margin-right: 20rpx;
				margin-bottom: 30rpx;
				
				width: 160rpx;
				text-align: center;
				.icon{
					position: relative;
					margin-bottom: 10rpx;
					image{
						width: 100rpx;
						height: 100rpx;
					}
					
					.num{
						z-index: 999;
						position: absolute;
						top: 0;
						right: 10rpx;
						
						width: 40rpx;
						line-height: 40rpx;
						background-color: #F56C6C;
						border-radius: 50%;
						color: #FFF;
						font-size: 26rpx;
					}
				}
				.name{
					font-size: 30rpx;
				}
			}
			.item:nth-child(4n){
				margin-right: 0;
			}
		}
	}
</style>