<template>
	<view>
		<view class="cu-custom" :style="[{height:CustomBar + 'px'}]">
			<view class="cu-bar fixed" :style="style" :class="[bgImage!=''?'none-bg text-white bg-img':'',bgColor]">
				<view class="flex justify-start">
					<view class="action" @tap="BackPage" v-if="isBack">
						<text class="cuIcon-back"></text>
						<slot name="backText"></slot>
					</view>
					<view class="action" @tap="BackHomePage" v-if="isBackHome">
						<text class="cuIcon-homefill"></text>
						<slot name="backHomeText"></slot>
					</view>
					<view></view>
				</view>
				<view class="content" :style="[{top:StatusBar + 'px'}]">
					<slot name="content"></slot>
				</view>
				<slot name="right"></slot>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				StatusBar: this.StatusBar,
				CustomBar: this.CustomBar
			};
		},
		name: 'cu-custom',
		computed: {
			style() {
				var StatusBar= this.StatusBar;
				var CustomBar= this.CustomBar;
				var bgImage = this.bgImage;
				var style = `height:${CustomBar}px;padding-top:${StatusBar}px;`;
				if (this.bgImage) {
					style = `${style}background-image:url(${bgImage});`;
				}
				return style
			}
		},
		props: {
			bgColor: {
				type: String,
				default: ''
			},
			isBack: {
				type: [Boolean, String],
				default: false
			},
			isBackHome: {
				type: [Boolean, String],
				default: false
			},
			homePageUrl: {
				type: [String],
				default: ''
			},
			bgImage: {
				type: String,
				default: ''
			},
		},
		methods: {
			BackPage() {
				uni.navigateBack({
					delta: 1
				});
			},
			BackHomePage() {
				uni.reLaunch({
					url: this.homePageUrl
				})
			}
		}
	}
</script>

<style scoped>
	.cu-bar .action:not(:first-child) {
		margin-left: 10rpx;
		font-size: 30rpx;
	}
	.cu-bar .action:not(:first-child)>text[class*="cuIcon-"] {
	    margin-right: 0.3em;
	}
</style>
