card.vue 1.44 KB
<template>
  <div :style="{ 'margin-top': +marginTop + 'px' }" class="box">
    <div v-if="title" class="header" :style="{ cursor: openBtn ? 'pointer' : 'unset' }" @click.stop="showBody()">
      <i v-if="openBtn" class="el-icon-caret-right" :class="{ trans: open }"></i>
      {{ title }}
      <div style="float:right">
        <slot name="right"></slot>
      </div>
    </div>
    <div v-if="!openBtn || open" class="main-wrap">
      <slot></slot>
    </div>
  </div>
</template>
<script type="text/ecmascript-6">
export default {
  name: 'card',
  data() {
    return {
        open: false
    }
  },
  props: {
    title: {
      type: String,
      default: ''
    },
    openBtn: {
      type: Boolean,
      default: false
    },
    marginTop:{
        tyep: Number|String,
        default: 16
    }
  },
  mounted() {},
  methods:{
    showBody(){
        if(!this.openBtn) return
        this.open = !this.open
    }
  }
}
</script>
<style lang="scss" scoped>
.box {
  background-color: #fff;
  .header {
    height: 58px;
    background-color: #fff;
    line-height: 58px;
    padding: 0 20px;
    box-sizing: border-box;
    font-family: inherit;
    font-size: 16px;
    color: #333333;
    // font-weight: 600;
  }
  .main-wrap {
    border-top: 1px solid #e5e5e5;
    padding: 20px;
    height: 100%;
    position: relative;
  }
}

.header .trans {
  transform: rotate(90deg);
}
.header .el-icon-caret-right {
  transition: transform 0.3s ease 0s;
}
</style>