<template>
  <el-drawer
    @open="open"
    @close="close"
    class="custom-drawer-cls"
    :append-to-body="true"
    :close-on-press-escape="true"
    :destroy-on-close="true"
    :show-close="false"
    :modal-append-to-body="true"
    :modal="true"
    :size="size"
    :wrapperClosable="true"
    :visible.sync="inputValue"
    :direction="direction"
    :before-close="handleClose">
    <template slot="title">
      <i class="el-icon-info"></i>{{ title }}
    </template>
    <div class="el-drawer__main">
      <div class="el-drawer__content">
        <slot></slot>
      </div>
      <div class="el-drawer__footer">
        <div style="float: left;margin-left: 10px">
          <slot name="anchor"></slot>
        </div>
        <slot name="buttons">
          <cms-button v-if="showCloseBtn" @click="close">{{ $t('common.button.close') }}</cms-button>
        </slot>
      </div>
    </div>
  </el-drawer>
</template>

<script>
import { CmsEditFormViewMixin } from './_CmsEditFormView'

export default {
  name: "CmsDrawer",
  mixins: [ CmsEditFormViewMixin ],
  data() {
    return {
      list: []
    }
  },
  mounted() {
    this.initTestData();
  },
  methods: {
    initTestData() {
      for (let i = 0; i < 1; i++) {
        this.list.push(`${ i }-我来啦!`)
      }
    },
    open() {
      this.$emit('open');
    },
    close() {
      this.inputValue = false;
      this.$emit('close');
    },
    handleClose(done) {
      if (this.beforeClose && this.beforeClose(done)) {
        done();
      } else done();
    }
  },
  computed: {
    inputValue: {
      get() {
        return this.value;
      },
      set(value) {
        this.$emit('input', value);
      }
    }
  }
}
</script>

<style lang="scss">
.custom-drawer-cls {

  .el-drawer {
    min-width: 300px;
  }

  .el-drawer__header {
    padding: 8px 15px !important;
    background-color: #F5F7FA !important;

    i {
      flex: 0;
      margin-top: 5px;
      width: auto !important;
      padding: 0 10px 0 0;
    }
  }
}

.el-drawer__main {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 40px);

  .el-drawer__content {
    flex: 1;
    height: calc(100vh - 88px);
    overflow-y: auto;
    overflow-x: hidden;
  }

  .el-drawer__footer {
    width: 100%;
    border-top: 1px solid #eaf0f3;
    background-color: #e6e6e6;
    height: 50px;
    line-height: 50px;
    text-align: right;
    padding-right: 10px;
    margin-right: 10px;
  }
}
</style>