<!--设备管理和笼位管理页面-->
<template>
	<view id="deviceCageSitePage">
		<!-- 设备管理 -->
		<web-view v-if="pageType==1&&openType" :src="'https://labcontrol.nwafu.edu.cn/ysms/h5/#/?userId='+userId"></web-view>
		<!-- 笼位管理 -->
		<web-view v-if="pageType==2&&openType" :src="'https://labcontrol.nwafu.edu.cn/cage/app/#/?ticket='+ticket"></web-view>
		<!-- 安全教育与考试 -->
		<web-view v-if="pageType==3&&openType" :src="'https://labcontrol.nwafu.edu.cn/studay/wx/#/zjznaiLogin?access_token='+access_token"></web-view>
		<!-- 安全责任 -->
		<web-view v-if="pageType==4&&openType" :src="'https://labcontrol.nwafu.edu.cn/duty/app/#/?userId='+userId"></web-view>
		<!-- 设施预约 -->
		<web-view v-if="pageType==5&&openType" :src="'https://labcontrol.nwafu.edu.cn/reserve/app/#/pages/login?token='+token"></web-view>
		</view>
</template>

<script>
	import {
		config
	} from '@/api/request/config.js'
	import {
		systemMineLinkGetEquipmentDetail,
		systemMineLinkGetCagePositionDetail,
		systemMineLinkGetEducationExamDetail,
		systemMineLinkGetExamH5,
		systemMineLinkGetSafetyDetail,
		menuLinkPost,
	} from '@/pages_basics/api/index.js'
	export default {
		name: "deviceCageSitePage",
		data() {
			return {
				baseUrl: config.base_url,
				pageType: 0, //1设备 2笼位
				userId: '',
				ticket: '',
				access_token:'',
				token:'',
				openType:false,
			}
		},
		onLoad(option) {
			let self = this;
			this.pageType = option.pageType;
		},
		mounted() {
			if(this.pageType==1){
				//设备管理
				this.userId=uni.getStorageSync('userId');
				this.$set(this,'openType',true);
			}else if(this.pageType==2){
				//笼位管理
				this.systemMineLinkGetCagePositionDetail()
			}else if(this.pageType==3){
				//安全教育与考试
				this.systemMineLinkGetEducationExamDetail();
			}else if(this.pageType==4){
				//安全责任
				this.userId=uni.getStorageSync('userId');
				this.$set(this,'openType',true);
				// this.systemMineLinkGetSafetyDetail();
			}else if(this.pageType==5){
				//设施预约
				// let item = {
				// 	reqApi:'labcontrol.nwafu.edu.cn/reserve/api/user/labLogin',
				// };
				// let obj = {
				// 	appId:'1962714012644597761',
				// 	secret:'c2789f8a360a4709a054a2e9f102d1b4',
				// 	timeStamp:Date.parse(new Date()),
				// 	userId:uni.getStorageSync('userId'),
				// };
				// this.menuLinkPost(item,obj);
				this.systemMineLinkGetExamH5();
			}
		},

		methods: {
			//设备资产管理
			async systemMineLinkGetEquipmentDetail() {
				const {
					data
				} = await systemMineLinkGetEquipmentDetail();
				if (data.code == 200) {
					this.getParams(data.data)
				}
			},
			//笼位管理
			async systemMineLinkGetCagePositionDetail() {
				const {
					data
				} = await systemMineLinkGetCagePositionDetail();
				if (data.code == 200) {
					this.getParams(data.data)
				}
			},
			//安全教育与考试
			async systemMineLinkGetEducationExamDetail() {
				const {
					data
				} = await systemMineLinkGetEducationExamDetail();
				if (data.code == 200) {
					this.getParams(data.data)
				}
			},
			//设施预约
			async systemMineLinkGetExamH5() {
				const {
					data
				} = await systemMineLinkGetExamH5();
				if (data.code == 200) {
					this.getParams(data.data)
				}
			},
			getParams(item) {
				let params = JSON.parse(item.params)
				let obj = {};
				params.requestArgument.forEach((item) => {
					if (item.type == 1) {
						//数据-键值对
						obj[item.key] = item.value;
					} else if (item.type == 2) {
						//读取cookie
						obj[item.value] = Cookies.get(item.key);
					} else if (item.type == 3) {
						//读取localStorage
						obj[item.value] = uni.getStorageSync('userId');
					}  else if (item.type == 5) {
						//生成时间戳-区分13位或者10位
						if (item.num == '10') {
							obj[item.key] = Date.parse(new Date()) / 1000;
							formData.append(item.key, );
						} else if (item.num == '13') {
							obj[item.key] = Date.parse(new Date());
						}
				 }
				})
				this.menuLinkPost(item,obj)
			},
			async menuLinkPost(item,obj){
				let self = this;
				menuLinkPost('https://'+item.reqApi,obj).then(response => {
					if(self.pageType==2||self.pageType==4){
						if(response.data.code==200){
							self.$set(self,'ticket',response.data.data.ticket);
						}
					}else if(self.pageType==3){
						self.$set(self,'access_token',response.data.data.access_token);
					}else if(self.pageType==5){
						self.$set(self,'token',response.data.data.access_token);
					}
					self.$set(self,'openType',true);
				})
			},

		},
	}
</script>

<style lang="stylus" scoped>
	#deviceCageSitePage {
		overflow scroll
	}
</style>
