<template>
  <vxe-modal v-model="show" v-bind="modalConfig" @close="onClose">
    <template #default>
      <slot></slot>
    </template>
    <template #footer>
      <slot name="footer"></slot>
    </template>
  </vxe-modal>
</template>
<script>
import { modalConfigMap, combineConfig } from '@/config/vxeModal';
export default {
  name: 'CommonModal',
  props: {
    type: {
      type: String,
      default: 'default'
    },
    visible: {
      type: Boolean,
      default: false
    },
    closeCb: {
      type: Function
    }
  },
  data() {
    return {
      modalConfig: {}
    }
  },
  methods: {
    async onClose() {
      console.log('关闭')
      if (this.closeCb) {
        await this.closeCb();
      }
      this.show = false;
    }
  },
  computed: {
    show: {
      get: function() {
        return this.visible
      },
      set: function (value) {
        this.$emit('update:visible', value)
      }
    }
  },
  created() {
    // 合并配置
    this.modalConfig = combineConfig(modalConfigMap.get(this.type),this.$attrs)
  },
  mounted() {
  }
}
</script>
