<template>
	<div class="eno-header">
	    <div class="eno-header-left">
			<slot name="left">
				<i class="el-icon-arrow-left" @click="back()"></i>
				<span>{{backText}}</span>
			</slot>	
		</div>
		<div class="eno-header-center">
			<slot name="center"></slot>
		</div>
	    <div class="eno-header-right">
            <slot name="right">
				<template v-if="!readOnly">
					<div v-if="!isEdit">
						<el-button type="primary" @click="editFunction">编辑</el-button>
						<el-button type="primary" @click="newFunction" v-if="newBtn">新建</el-button>
					</div>	
					<div v-else>
						<el-button @click="giveUp">放弃</el-button>
						<el-button type="primary" @click="save">保存</el-button>
					</div>
				</template>
			</slot>
	    </div>
	</div>
</template>

<script>
	export default {
	    name: "enoFormHeader",
	    props: {
	        backText:{
	            type:String,
	            default:'上一级'
	        },
	        isEdit:{
	            type:Boolean,
	            default: false
	        },
			newBtn:{
	            type:Boolean,
	            default: false
	        },
			infoHasChange:{
			    type:Boolean,
			    default: false
			},
			customBack: {
				type: Function,
				default: null
			},
			readOnly:{
			    type:Boolean,
			    default: false
			},
	    },
	    methods: {
	        back: function() {
				if(typeof customBack == 'function'){
					this.customBack()
				}
				else{
					this.$router.go(-1)
				}
	        },
			editFunction: function() {
	            this.$emit('edit')
	        },
	        newFunction: function() {
	            this.$emit('new')
	        },
			save: function() {
	            this.$emit('save')
	        },
			giveUp: function() {
	            this.$emit('giveUp')
	        }
	    }
	}
</script>

<style lang="less" scoped>
	.eno-header{
	    width: 100%;
		padding: 0 40px;
		height: 54px;
		line-height: 54px;
		position: fixed;
		top: 64px;
		left: 0;
		background-color: #f5f8ff;
		z-index: 5;
		display: flex;
		justify-content: space-between;
		align-items: center;
		flex-wrap: wrap;
		
		.eno-header-left {
		  font-size: 16px;
		  line-height: 22px;
		  font-weight: bold;
		
		  .el-icon-arrow-left {
		    font-weight: bold;
		    padding: 4px;
		    cursor: pointer;
		  }
		}

	
	}
</style>
