<template>
  <div :class="`header ${needBottomBorder ? ' bottom-border' : ' '}`">
    <div class="header-left">
      <div class="icon" @click="onBack" v-show="showBack">
        <WlPic :src="require('@packages/assets/images/back.png')" />
      </div>
      <slot name="header_part_left"></slot>
    </div>
    <div class="header-title">
      <slot>{{ title }}</slot>
    </div>
    <div class="header-right">
      <div class="icon" @click="onClose" v-show="showClose">
        <WlPic :src="require('@packages/assets/images/close.png')" />
      </div>
      <slot name="header_part_right"></slot>
    </div>
  </div>
</template>

<script>
/*
 * @Author: Liao.xiuli
 * @Date: 2021-09-18 11:18:59
 * @Last Modified by: Liao.xiuli
 * @Last Modified time: 2022-06-06 14:11:55
 */
import WlPic from "@packages/components/Common/WlPic/src/index.vue";
export default {
  name: "WlHeader",
  components: { WlPic },
  props: {
    title: {
      type: String,
      default: "",
    },
    showClose: {
      type: Boolean,
      default: false,
    },
    showBack: {
      type: Boolean,
      default: false,
    },
    needAutoBack: {
      type: Boolean,
      default: true,
    },
    needBottomBorder: {
      type: Boolean,
      default: false,
    },
  },
  methods: {
    onBack() {
      if (this.needAutoBack) {
        this.$router.back();
      } else {
        this.$emit("onBack");
      }
    },

    onClose() {
      this.$emit("onClose");
    },
  },
};
</script>

<style lang="scss" scoped>
.header {
  width: 100%;
  height: j(55);
  color: #0e0e0e;
  font-size: j(18);
  font-weight: 500;
  line-height: j(55);
  background-color: #fff;
  position: relative;
  text-align: center;
  @extend %flex-middle;
  &.bottom-border {
    @include halfBorder("bottom", #eee);
  }
  &-title {
    flex: 1;
    @include textEllipsis(1);
  }
  .icon {
    width: j(18);
    height: j(18);
    padding: 0 j(15);
    cursor: pointer;
    box-sizing: content-box;
  }
  &-left {
    min-width: j(48);
  }
  &-right {
    min-width: j(48);
  }
}
</style>
