<template>
	<view class="back" :style="{height: capsuleHeight+ 'px',top:capsuleTop+'px'}">
		<u-icon name="arrow-left" v-if="show === 'back'" :color="color" size="24" @click="backIconHandler"></u-icon>
		<u-icon name="home-fill" v-if="show === 'home'" :color="color" size="24" @click="backHomeHandler"></u-icon>
		<view class="back-text" :style="{color: color}">{{ text }}</view>
	</view>
</template>

<script>
	export default {
		name: "top-return",
		props: {
			text: {
				type: String,
				default: ''
			},
			color: {
				type: String,
				default: '#303133'
			},
			show: {
				type: String,
				default: 'back'
			}
		},
		data() {
			return {
				//胶囊
				capsuleHeight: 0,
				capsuleTop: 0,
			};
		},
		created() {
			this.getCapsuleSite()
		},
		methods: {
			backIconHandler() {
				uni.navigateBack()
			},
			backHomeHandler() {
				uni.switchTab({
					url: '/pages/tab_home/tab_home'
				})
			},
			//获取胶囊位置信息
			getCapsuleSite() {
				let res = uni.getMenuButtonBoundingClientRect()
				this.capsuleHeight = res.height
				this.capsuleTop = res.top
			}
		}
	}
</script>

<style lang="scss">
	.back {
		position: relative;
		padding: 0 0 0 20rpx;
		display: flex;
		align-items: center;
		z-index: 999;

		.back-text {
			margin:0 0 5rpx 20rpx;
			font-size: 40rpx;
			font-weight: bold;
			z-index: 999;
		}
	}
</style>
