<template>
  <div class="aos-widget-box">
    <div class="aos-widget-title-container" :class="{ headerBorder: showHeaderBorder}" v-if="!onlyBody">
      <div class="header">
        <i v-if="iconType === 'iconfont' && icon" class="iconfont header-icon" :class="'icon-'+icon"></i>
        <i v-else-if="icon" class="header-icon" :class="'el-icon-' + icon"></i>
        <span>{{name}}</span>
      </div>
      <div class="header-right">
        <div class="header-right-left">
          <slot name="right"></slot>
          <i v-if="showDelete" class="el-icon-delete delete" @click="handleDelete"></i>
        </div>
        <div class="operation" v-if="showOperation" @click="handleOperationClick">
          {{operation}}
          <i class="el-icon-arrow-right"></i>
        </div>
      </div>
    </div>
    <div class="aos-widget-body" :class="{'aos-widget-body-only-body':onlyBody}">
      <slot></slot>
    </div>
  </div> 
</template>
<script>
export default {
  name: 'AosWidgetBox',
  props: {
    name: {
      type: String
    },
    operation: {
      type: String,
      default: '详情'
    },
    showOperation: {
      type: Boolean,
      default: false
    },
    minHeight: {
      type: Number,
      default: 400
    },
    onlyBody: {
      type: Boolean,
      default: false
    },
    showDelete: {
      type: Boolean,
      default: false
    },
    showHeaderBorder: {
      type: Boolean,
      default: true
    },
    refreshTime: {
      type: Number
    },
    icon: {
      type: String
    },
    iconType: {
      type: String
    }
  },
  data () {
    return {
      timer: null
    }
  },
  methods: {
    handleOperationClick(){
      this.$emit('operation-click');
    },
    handleDelete () {
      this.$emit('delete')
    },
    handleRefreshEmit () {
      const self = this
      if (this.refreshTime) {
        this.timer = setInterval(() => {
          self.$emit('refresh')
        }, self.refreshTime)
      }
    }
  },
  created () {
    this.handleRefreshEmit()
  },
  beforeDestory() {
    if (this.timer) {
      clearInterval(this.timer)
    }
  }
}
</script>
