<!--设备管理和笼位管理页面-->
<template>
	<view id="deviceCageSitePage">
		<!-- 设备管理 -->
		<web-view v-if="pageType==1" :src="'https://lab.xf100.net/ysms-h5/#/?userId='+userId"></web-view>
		<!-- 笼位管理 -->
		<web-view v-if="pageType==2" :src="'http://175.27.136.248:9033/#/?ticket='+ticket"></web-view>
	</view>
</template>

<script>
	import {
		config
	} from '@/api/request/config.js'
	import {
		systemMineLinkGetEquipmentDetail,
		systemMineLinkGetCagePositionDetail,
		menuLinkPost
	} from '@/pages_basics/api/index.js'
	export default {
		name: "deviceCageSitePage",
		data() {
			return {
				baseUrl: config.base_url,
				pageType: 0, //1设备 2笼位
				userId: '',
				ticket: '',
			}
		},
		onLoad(option) {
			let self = this;
			this.pageType = option.pageType;
			console.log(this.pageType)
		},
		mounted() {
			if(this.pageType==1){
				this.userId=uni.getStorageSync('userId');
				//this.systemMineLinkGetEquipmentDetail()
			}else if(this.pageType==2){
				this.systemMineLinkGetCagePositionDetail()
			}


		},

		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)
				}

			},

			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){
				menuLinkPost('http://'+item.reqApi,obj).then(response => {
					if(response.data.code==200){
						this.ticket=response.data.data.ticket
					}

				})
			},

		},
	}
</script>

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