<template>
  <el-card class="ed-card" :shadow="shadow" :bodyStyle="bodyStyle">
    <div v-if="showHeader && isTitle" slot="header" class="ed-card--header">
      <slot name="header">
        <div>{{ title }}</div>
        <div><slot name="operate"></slot></div>
      </slot>
    </div>

    <slot></slot>
  </el-card>
</template>

<script>
export default {
  name: "EdCard",
  props: {
    title: String,

    // 是否显示title
    isTitle: {
      type: Boolean,
      default: true
    },

    bodyStyle: {
      type: Object,
      default: () => {
        return {
          padding: '15px'
        }
      }
    },
    // 	设置阴影显示时机 always / hover / never
    shadow: {
      type: String,
      default: "always"
    }
  },
  computed:{
    showHeader(){
      let slots = Object.keys(this.$slots)
      return this.title !== undefined || slots.includes('header') || slots.includes('operate')
    }
  }
}
</script>

<style lang="scss" scoped>
@import "../../../style/index.scss";
.ed-card {
  .ed-card--header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 40px;

    div:last-child, .es-card-header-operate {
      display: flex;
      justify-content: flex-end;
      align-items: center;
    }
  }
  .view-list-card.active {
    background-color: rgb(225, 243, 216);
  }
}
// el-card 默认样式修改
::v-deep {
  .el-card__header {
    font-size: 18px;
    padding: 10px;
  }

  .el-card.is-never-shadow {
    .el-card__header {
      opacity: 0.5;
    }
  }

  .el-card__body {
    height: calc(100% - 90px);
    overflow-y: auto;
  }
}

</style>
