<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="action" @tap="BackPage" v-if="isBack">
					<image style="width: 32rpx;height: 32rpx;margin-right: 16rpx;" src="/static/user/bask.png"></image>
					<slot  name="backText"> </slot>
				</view>
				<view class="action" v-else>
					<slot name="backText"></slot> 
				</view>
				<!-- 居中标题 -->
				<view class="action" :style="[{top:StatusBar + 'px'}]">
					<slot name="content"></slot>
				</view>
				<!-- 最右端内容 -->
				<view class="action" :style="[{top:StatusBar + 'px'}]" >
					<slot name="right"></slot>
				</view>
				
			</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
			},
			isBackIndex: {
				type: [Boolean, String],
				default: true
			},
			backNum:{
				type:Number,
				default:0
			},
			bgImage: {
				type: String,
				default: ''
			},
		},
		methods: {
			BackPage() {
				if(this.isBackIndex){
					if(this.backNum){
						uni.navigateBack({
							delta: this.backNum
						});
					}
					uni.navigateBack({
						delta: 1
					});
				}else{
					uni.navigateTo({
						url:"/pages/index/index"
					})
				}
				
			}
		}
	}
</script>

<style>
	.cu-bar .action:last-child {
	    margin-right: 5px;
	}
</style>
