<template>
	<view class="topbar flex-between" :style="{'height':`${topbarOffsetHeight-statusBarHeight}px`,'padding-top':`${statusBarHeight}px`}">
		<view class="icon flex-center" @click="action">
			<image src="../../static/back.png" mode="aspectFill" class="icon-img" v-if="icon==='back'"></image>
		</view>
		<view class="text font32 fw600" :style="{'line-height':`${topbarOffsetHeight-statusBarHeight}px`}">
			{{title}}
		</view>
		<view class="null">
			
		</view>
	</view>
</template>

<script>
	export default {
		name:"TopBar",
		props:{
			icon:{
				type:String,
				default:''
			},
			title:{
				type:String,
				default:''
			}
		},
		data() {
			return {
				
			};
		},
		computed:{
			statusBarHeight(){
				return this.$store.state.statusBarHeight;
			},
			topbarOffsetHeight(){
				return this.$store.state.topbarOffsetHeight;
			}
		},
		methods:{
			action(){
				switch(this.icon){
					case 'back':
						uni.navigateBack({
							delta:1
						})
					break;
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "../../public.scss";
	.topbar{
		background-color: $bgcolor1;
	}
	.icon{
		width: 128rpx;
		height: 100%;
		.icon-img{
			width: 40rpx;
			height: 40rpx;
		}
	}
	.text{
		height: 100%;
		flex: 1;
		color: $fontcolor5;
		text-align: center;
	}
	.null{
		width: 128rpx;
		height: 100%;
	}
</style>