<template>
	<view>
		<view class="ui-fixed" :class="{'fixed-top':position=='top','fixed-bottom':position=='bottom'}">
			<slot></slot>
		</view>
		<view :style="{height:height+'px'}"></view>
	</view>
</template>

<script>
	export default {
		name: 'fixed',
		props: {
			position: {
				type: [String],
				default () {
					return 'top'
				}
			}
		},
		data() {
			return {
				height: uni.getSystemInfoSync().windowWidth * 100 / 750
			}
		},
		mounted() {
			this.setHeight();
		},
		created() {
			this.setHeight();
		},
		onReady() {
			this.setHeight();
		},
		methods: {
			setHeight() {
				var _this = this;
				var query = uni.createSelectorQuery().in(this);
				query.select('.ui-fixed').boundingClientRect(function(res) {
					_this.height = res.height;
				}).exec();
			}
		},
	}
</script>


<style>
	.ui-fixed {
		position: fixed;
		left: 0;
		width: 100%;
		z-index: 999;
	}

	.fixed-top {
		top: 0;
	}

	.fixed-bottom {
		bottom: 0;
	}
</style>
