<!-- 教师首页 -->
<template>
	<view class="teacherHome">
		<dataBoard v-if="pageType == 1" style="display: flex;flex-direction:column;flex:1;"></dataBoard>
		<view class="home-page" v-if="pageType == 2">
			<nav-bar :title="title" :background="background"></nav-bar>
			<view class="top-back-img" :style="{top:navHeight+'rpx'}">
				<img class="position-data-button" @click="goPage('dataBoard')" v-if="dataPageType" :src="imagesUrl('home/icon_sy_sjmb@1x.png')">
				<img class="position-img" :src="rectangleLogo">
			</view>
			<view class="button-one-box">
				<view class="button-min" @click="goPage('securityExamination')" style="margin:23rpx 0 0 20rpx;">
					<img class="button-img" :src="imagesUrl('home/icon_sy_aqks@1x.png')">
					<view class="button-name">教育考试</view>
				</view>
				<view class="button-min" @click="goPage('securityAdmittance')" style="margin:23rpx 65rpx 0;">
					<img class="button-img" :src="imagesUrl('home/icon_sy_aqzr@1x.png')">
					<view class="button-name">安全准入</view>
				</view>
				<view class="button-min" @click="goPage('hierarchicalControl')" style="margin:23rpx 20rpx 0 0;">
					<img class="button-img" :src="imagesUrl('home/icon_sy_fjgk@1x.png')">
					<view class="button-name">分级管控</view>
				</view>
				<view class="button-min" @click="goPage('securityCheck')" style="margin:23rpx 0 0 20rpx;">
					<img class="button-img" :src="imagesUrl('home/icon_sy_aqjc@1x.png')">
					<view class="button-name">安全检查</view>
				</view>
				<!-- <view class="button-min" @click="goPage('securityResponsibility')">
					<img class="button-img" :src="imagesUrl('home/icon_sy_aqzrr@1x.png')">
					<view class="button-name">安全责任</view>
				</view> -->
				<view class="button-min" @click="goPage('deviceManagement')" style="margin:23rpx 65rpx 0;">
					<img class="button-img" :src="imagesUrl('home/icon_sy_sbgl@1x.png')">
					<view class="button-name">设备管理</view>
				</view>
				<view class="button-min" @click="goPage('emergencyDisposal')" style="margin:23rpx 20rpx 0 0;">
					<img class="button-img" :src="imagesUrl('home/icon_sy_yjcz@1x.png')">
					<view class="button-name">应急处置</view>
				</view>
				<view class="button-min" @click="goPage('hazardousWasteRecycling')" style="margin:23rpx 0 0 20rpx;">
					<img class="button-img" :src="imagesUrl('home/icon_sy_hxp@1x.png')">
					<view class="button-name">危废回收</view>
				</view>
				<!-- <view class="button-min" @click="goPage('cageSiteManagement')">
					<img class="button-img" :src="imagesUrl('home/icon_sy_lwgl@1x.png')">
					<view class="button-name">笼位管理</view>
				</view> -->
			</view>
			<topWarn></topWarn>
			<view class="button-two-box">
				<view class="button-big-box" @click="goPage('snapshot')"
					style="background-color: #DFF0FF;margin-right:20rpx;">
					<img :src="imagesUrl('home/icon_sy_ssp@1x.png')">
					<view class="button-min-box">
						<view>随手拍</view>
						<view>隐患上报</view>
					</view>
				</view>
				<view class="button-big-box" @click="goPage('remoteDoorOpening')" style="background-color: #D6EBDA;">
					<img :src="imagesUrl('home/img_sy_yckm@1x.png')">
					<view class="button-min-box">
						<view>远程开门</view>
						<view>打开门禁</view>
					</view>
				</view>
			</view>
			<view class="button-two-box">
				<view class="button-big-box" @click="goPage('leaveCheckPupilTeacher')"
					style="background-color: #FFF0DD;margin-right:20rpx;">
					<img :src="imagesUrl('home/home_button_04.png')">
					<view class="button-min-box">
						<view>离开检查</view>
						<view>拍照上传</view>
					</view>
				</view>
				<view class="button-big-box" @click="goPage('cageSiteManagement')" 
					style="background-color: rgba(201,159,255,0.2);">
					<img :src="imagesUrl('home/home_button_03.png')">
					<view class="button-min-box">
						<view>笼位管理</view>
						<view>实验动物中心</view>
					</view>
				</view>
			</view>
			<view class="button-three-box">
				<view class="button-big-box button-big-box-1" @click="goPage('facilityReservation')">
					<img :src="imagesUrl('home/img_ssyy@1x.png')">
					<view class="button-min-box">
						<view>设施预约</view>
						<view>预约审批 | 设施确认 | 费用结算</view>
					</view>
				</view>
			</view>
			<!-- <view class="button-three-box-1">
				<view class="button-big-box" @click="goPage('leaveCheckPupilTeacher')">
					<img :src="imagesUrl('home/img_lkjc@1x.png')">
					<view class="button-min-box">
						<view>离开检查</view>
						<view>拍照上传</view>
					</view>
				</view>
			</view>
			<view class="button-three-box">
				<view class="button-big-box" @click="goPage('cageSiteManagement')">
					<img :src="imagesUrl('home/img_lwgl@1x.png')">
					<view class="button-min-box">
						<view>笼位管理</view>
						<view>实验动物中心</view>
					</view>
				</view>
			</view> -->
			<!-- <view class="button-three-box">
				<view class="button-big-box" @click="goPage()">
					<img :src="imagesUrl('home/img_bg_hxpgk@1x.png')">
					<view class="button-min-box">
						<view>化学品智能管控</view>
						<view>申购审批丨使用台账丨实验室库存</view>
					</view>
				</view>
			</view> -->
			<img class="scan_btn" @click.stop="saoCode" :src="imagesUrl('commonality/icon_xyxc_sm.png')">
			<tab-bar></tab-bar>
		</view>

	</view>
</template>

<script>
	import {
		pageRestrictVerify
	} from '@/utils/index'
	import {
		chemicalAppletSelectStockInfo,
		laboratorySubPassOutIsotopeSubSign,
		systemUserProfile,
		systemUserGetPost,
		hwmsAppRegisterApprovalIsPermit,
	} from '@/pages/api/index.js'
	import {
		tabBar
	} from '@/pages/component/tabBar.vue'
	import {
		navBar
	} from '@/pages/component/navbar.vue'
	import {
		topWarn
	} from '@/pages/component/topWarn.vue'
	import {
		dataBoard
	} from '@/pages/views/dataBoard/dataBoard.vue'
	export default {
		name: "teacherHome",
		components: {
			tabBar,
			navBar,
			topWarn,
			dataBoard,
		},
		data() {
			return {
				pageType: 2,
				navHeight: uni.getStorageSync('navHeight'),
				dataPageType: false,
				title: '实验室安全智慧化管控系统',
				background: '#0183FA',
				rectangleLogo: uni.getStorageSync('rectangleLogo'),
				identityData:uni.getStorageSync('identityData'),
			}
		},
		created() {
			if (pageRestrictVerify('dataBoard')) {
				this.dataPageType = true;
				if (!uni.getStorageSync('dataBoardType')) {
					this.pageType = 1;
					uni.setStorageSync('dataBoardType', true);
				}
			}
		},
		mounted() {
			this.systemUserProfile();
		},
		methods: {
			//获取个人信息
			async systemUserProfile() {
				const {
					data
				} = await systemUserProfile();
				if (data.code == 200) {
					this.$set(this, 'userData', data.data)
					uni.setStorageSync('userDeptId', data.data.deptId);
					uni.setStorageSync('userDeptName', data.data.deptName);
				}
			},
			goHome() {
				this.pageType = 2;
			},
			goPage(type) {
				if (!type) {
					uni.showToast({
						title: '暂未开放',
						icon: "none",
						mask: true,
						duration: 2000
					});
					return
				}
				if (!pageRestrictVerify(type)) {
					uni.showToast({
						title: '没有相关权限,请联系管理员',
						icon: "none",
						mask: true,
						duration: 2000
					});
					return
				}
				if (type == 'dataBoard') {
					//数据看板
					this.pageType = 1;

				} else if (type == 'securityCheck') {
					//安全检查
					uni.navigateTo({
						url: "/pages_safetyCheck/views/safetyCheck",
					});
					/* if(this.identityData){
						uni.navigateTo({
							url: "/pages_safetyCheck/views/safetyCheck",
						});
					}else{
						uni.showToast({
							mask: true,
							icon: "none",
							position: "center",
							title: '您不是校/院级管理员或督导组成员,无法使用该功能.',
							duration: 2000
						});
					} */
				} else if (type == 'securityExamination') {
					//安全考试
					uni.navigateTo({
						url: "/pages_basics/views/deviceCageSitePage?pageType=3",
					});	
				} else if (type == 'securityAdmittance') {
					//安全准入
					uni.navigateTo({
						url: "/pages_manage/views/accessQualification/accessQualification",
					});
				} else if (type == 'hierarchicalControl') {
					//分级管控
					uni.navigateTo({
						url: "/pages_basics/views/gradingControl/gradingControl",
					});
				} else if (type == 'securityResponsibility') {
					//安全责任
					uni.navigateTo({
						url: "/pages_basics/views/deviceCageSitePage?pageType=4",
					});
				} else if (type == 'deviceManagement') {
					//设备管理
					uni.navigateTo({
						url: "/pages_basics/views/deviceCageSitePage?pageType=1",
					});
				} else if (type == 'emergencyDisposal') {
					//应急处置
					// uni.navigateTo({
					// 	url: "/pages_manage/views/emergencyEvacuationBig",
					// });
					uni.navigateTo({
						url: "/pages_manage/views/emergencyEvacuationSubList",
					});
				} else if (type == 'cageSiteManagement') {
					//笼位管理
					uni.navigateTo({
						url: "/pages_basics/views/deviceCageSitePage?pageType=2",
					});
				} else if (type == 'snapshot') {
					//随手拍
					uni.navigateTo({
						url: "/pages_safetyCheck/views/snapshotManage/snapshotList",
					});
					/* uni.navigateTo({
						url: "/pages_safetyExamine/views/snapshotManage/snapshotAdd",
					}); */
				} else if (type == 'remoteDoorOpening') {
					//远程开门
					uni.navigateTo({
						url: "/pages_manage/views/accessControl/remoteOpen",
					});
				} else if (type == 'leaveCheckPupilTeacher') {
					//离开检查
					uni.navigateTo({
						url: "/pages_basics/views/photoInspection",
					});
				} else if (type == 'chemicalsManagement') {
					//化学品管控

				} else if (type == 'facilityReservation'){
					//设施预约
					uni.navigateTo({
						url: "/pages_basics/views/deviceCageSitePage?pageType=5",
					});
				}else if(type == 'hazardousWasteRecycling'){
					//危废回收
					this.systemUserGetPost();
				}
			}, 
			async systemUserGetPost(){
				const {
					data
				} = await systemUserGetPost();
				if (data.code == 200) {
					let num = 0;
					for(let i=0;i<data.data.length;i++){
						if(data.data[i].postCode == 'safe_fzr'){
							
						}else{
							if(data.data[i].isPost){
								num++
							}
						}
					}
					if(num>0){
						// 拥有身份
						uni.setStorageSync('hazardousWasteUserType',1)
						uni.navigateTo({
							url: "/pages_hazardousWasteRecycling/views/home/home",
						});
					}else{
						// 没有身份
						uni.setStorageSync('hazardousWasteUserType',0)
						this.hwmsAppRegisterApprovalIsPermit();
					}
				}
			},
			async hwmsAppRegisterApprovalIsPermit(){
				const {
					data
				} = await hwmsAppRegisterApprovalIsPermit();
				if (data.code == 200) {
					if(data.data == '0'){
						//没有权限-跳转权限申请
						uni.navigateTo({
							url: "/pages_hazardousWasteRecycling/views/permissionApply/index",
						});
					}else if(data.data == '1'){
						//有权限-正常进入
						uni.navigateTo({
							url: "/pages_hazardousWasteRecycling/views/home/home",
						});
					}else if(data.data == '2'){
						//没有权限-有申请-跳转申请列表
						uni.navigateTo({
							url: "/pages_hazardousWasteRecycling/views/permissionApply/listPage",
						});
					}
				}
			},
			/* 扫一扫*/
			saoCode() {
				let self = this;
				uni.scanCode({
					onlyFromCamera: true,
					success: function(res) {
						if(res.result.indexOf('type') != -1){
							//项目二维码
							let list = res.result.split("?")[1].split("&");
							let codeData = {};
							list.forEach((item) => {
								codeData[item.split("=")[0]] = item.split("=")[1];
							})
							if (codeData.type == 1 || codeData.type == 2 || codeData.type == 3 || codeData.type == 7 ||
								codeData.type == 8 || codeData.type == 10 ||
								codeData.type == 11 || codeData.type == 12 || codeData.type == 13 || codeData.type == 14) {
								uni.reLaunch({
									url: '/pages/views/saoCode/saoCode?q=' + encodeURIComponent(res.result)
								});
							}else if(codeData.type == 5){
								self.laboratorySubPassOutIsotopeSubSign(codeData.subId,res.result);
							}else if(codeData.type == 9){
								self.chemicalAppletSelectStockInfo(codeData.code);
							}
						}else{
							self.chemicalAppletSelectStockInfo(res.result);
						}
					}
				});
			},
			//扫码查询-化学品基本信息
			async chemicalAppletSelectStockInfo(code) {
				const {
					data
				} = await chemicalAppletSelectStockInfo({tagCode:code});
				if (data.code == 200) {
					if(data.data){
						data.data.code = code;
						//化学品信息
						uni.navigateTo({
							url: "/pages_basics/views/chemicalsInfo/chemicalsInfo?item=" + encodeURIComponent(JSON.stringify(data.data)),
						});
					}else{
						uni.showToast({
							mask: true,
							icon: "none",
							position: "center",
							title: '未找到相关信息,请扫描正确的二维码',
							duration: 2000
						});
					}
				}
			},
			//查询是否是同位素实验并且有签退
			async laboratorySubPassOutIsotopeSubSign(subId,result) {
				const {
					data
				} = await laboratorySubPassOutIsotopeSubSign({subId:subId});
				if (data.code == 200) {
					if(data.data.isotope){
						let obj = {
							subId:subId,
							subName:data.data.subName,
							passOutId:data.data.passOutId,
						}
						uni.navigateTo({
							url: "/pages_basics/views/photoInspection?item=" + encodeURIComponent(JSON.stringify(obj)),
						});
					}else{
						uni.reLaunch({
							url: '/pages/views/saoCode/saoCode?q=' + encodeURIComponent(result)
						});
					}
				}
			},
		}
	}
</script>

<style lang="stylus" scoped>
	@import '@/api/request/imagesUrl.styl';
	.teacherHome {
		flex: 1;
		display: flex;
		flex-direction: column;
		overflow: hidden;

		.data-board {
			flex: 1;
			display: flex;
			flex-direction: column;
			overflow: hidden;
		}

		.home-page {
			flex: 1;
			display: flex;
			flex-direction: column;
			overflow-y: scroll;
			overflow-x: hidden;
			padding-bottom:120rpx;

			.top-page-title {
				text-align: center;
				font-size: 28rpx;
				background-color: #0183FA;
				color: #fff;
			}

			.top-back-img {
				position: absolute;
				top: 0;
				left: 0;
				width: 750rpx;
				height: 539rpx;
				background: url($imagesUrl+'home/img_sy_bg@1x.png') no-repeat;
				background-size:100%;
				background-repeat: no-repeat;

				.position-img {
					z-index: 5;
					position: absolute;
					left: 0;
					top: 10rpx;
					width: 400rpx;
					height: 88rpx;
				}

				.position-data-button {
					z-index: 5;
					position: fixed;
					right: 0;
					top: 180rpx;
					width: 130rpx;
					height: 109rpx;
					/* line-height: 50rpx;
					background-color: #0183fa;
					color: #fff;
					font-size: 28rpx;
					text-align: center;
					border-top-left-radius: 30rpx;
					border-bottom-left-radius: 30rpx; */
				}
			}

			.button-one-box {
				z-index: 5;
				background: #fff;
				width: 690rpx;
				border-radius: 20rpx;
				padding: 13px 0 20px;
				overflow: hidden;
				margin: 490rpx 30rpx 0;

				.button-min {
					display: inline-block;
					overflow: hidden;
					width: 172rpx;
					height: 123rpx;
					margin-top: 23rpx;

					.button-img {
						display: block;
						width: 80rpx;
						height: 80rpx;
						margin: 0 auto;
					}

					.button-name {
						margin-top: 15rpx;
						height: 28rpx;
						line-height: 28rpx;
						font-size: 28rpx;
						text-align: center;
						color: #333;
					}
				}
			}

			.button-two-box {
				z-index: 5;
				width: 690rpx;
				height: 120rpx;
				display: flex;
				margin: 20rpx 30rpx 0;

				.button-big-box {
					width: 335rpx;
					display: flex;
					border-radius: 20rpx;

					img {
						display: block;
						margin: 20rpx 25rpx 0 25rpx;
						height: 80rpx;
						width: 80rpx;
					}

					.button-min-box {
						view:nth-child(1) {
							line-height: 32rpx;
							height: 32rpx;
							font-size: 30rpx;
							color: #333;
							margin: 20rpx 0 18rpx;
						}

						view:nth-child(2) {
							line-height: 28rpx;
							height: 28rpx;
							font-size: 26rpx;
							color: #999;
						}
					}
				}
			}

			.button-three-box-1 {
				z-index: 5;
				width: 690rpx;
				height: 130rpx;
				margin: 20rpx 30rpx 0;

				.button-big-box {
					border-radius: 20rpx;
					background-color: #CDE7FF;
					display: flex;

					img {
						display: block;
						width: 134rpx;
						height: 104rpx;
						margin: 23rpx 34rpx 0 30rpx;
					}

					.button-min-box {
						view:nth-child(1) {
							line-height: 30rpx;
							height: 30rpx;
							font-size: 30rpx;
							color: #0183FA;
							margin: 27rpx 0 15rpx;
						}

						view:nth-child(2) {
							line-height: 26rpx;
							height: 26rpx;
							font-size: 26rpx;
							color: #666666;
						}
					}
				}
			}

			.button-three-box {
				z-index: 5;
				width: 690rpx;
				height: 130rpx;
				margin: 20rpx 30rpx 0;
				.button-big-box-1{
					background: #CDE7FF;
					.button-min-box{
						view:nth-child(1){
							color: #0183FA;
						}
						view:nth-child(2){
							color: #666666;
						}
					}
				}
				.button-big-box {
					height:130rpx;
					border-radius: 20rpx;
					display: flex;

					img {
						display: block;
						width: 134rpx;
						height: 104rpx;
						margin: 23rpx 34rpx 0 30rpx;
					}

					.button-min-box {
						view:nth-child(1) {
							line-height: 30rpx;
							height: 30rpx;
							font-size: 30rpx;
							margin: 30rpx 0 15rpx;
						}

						view:nth-child(2) {
							line-height: 26rpx;
							height: 26rpx;
							font-size: 26rpx;
						}
					}
				}
			}

			.scan_btn {
				z-index: 10;
				position: fixed;
				bottom: 210rpx;
				right: 0rpx;
				width: 140rpx;
				height: 140rpx;
			}
		}
	}
</style>