<template>
  <div class="com-panel" :class="{ 'no-title': !hasTitle }">
    <div v-if="hasTitle" class="panel-header">
      <div class="panel-title">
        <i v-if="hasIcon" class="panel-icon" :class="icon"></i>
        {{ title }}
      </div>
      <div class="panel-tools">{{ subTitle }}</div>
    </div>
    <div class="panel-body">
      <slot></slot>
    </div>
  </div>
</template>

<script>
export default {
  name: "com-panel",
  componentName: "com-panel",
  props: {
    // 标题
    title: String,
    // 图标
    icon: String,
    // 副标题
    subTitle: String,
  },
  computed: {
    // 是否存在标题
    // 标题为空时 不显示标题框
    hasTitle() {
      if (this.title) return true;
      return false;
    },
    // 是否存在图标
    hasIcon() {
      if (this.icon) return true;
      return false;
    },
  },
};
</script>
<style lang="less">
.com-panel {
  border-left: 2px solid rgba(255, 255, 255, 50%);

  &:before {
    content: " ";
    width: 4px;
    height: 4px;
    float: left;
    background: #fff;
    margin: 2px 6px 0px 2px;
  }

  &.no-title {
    border-left: 0px;
  }

  &.no-title::before {
    display: none;
  }

  .panel-header {
    display: flex;
    font-size: @fontsize;
    padding-left: 12px;
    background: rgba(255, 255, 255, 10%);
    line-height: 2.593vh;
    margin-bottom: 1.481vh;

    .panel-title {
      color: rgba(255, 255, 255, 0.8);
      flex: 1 1 auto;
      .panel-icon {
        margin-right: 8px;
      }
    }

    .panel-tools {
      flex: 0 0 auto;
      color: #ffffff4d;
      padding: 0 8px;
      font-size: @fontsize-s;
      letter-spacing: 1px;
    }
  }

  .panel-body {
    padding-left: 12px;
    color: rgba(255, 255, 255, 0.8);
  }

  &.no-title .panel-body {
    padding-left: 0px;
  }
}
</style>
