<template>
  <vxe-modal
    v-model="visible"
    v-if="visible"
    v-bind="defaultModelConfig"
    size="small"
    @close="closeModal"
    @cancel="closeModal"
    @hide="closeModal"
    @open="openModal"
    @zoom="zoomModal"
    :width="modalWidth"
    :height="modalHeight"
    :destroy-on-close="destroyOnClose"
    :id="'md' + new Date().getTime()"
    :show-footer="showFooter">
    <template slot="header">
      <slot name="header"></slot>
    </template>
    <template #title>
      {{ modalTitle }}
    </template>
    <template #default>
      <slot></slot>
    </template>
    <template slot="footer">
      <slot name="footer">
        <cms-button size="small" @click="closeModal">{{ $t('common.button.close') }}</cms-button>
      </slot>
    </template>
  </vxe-modal>
</template>

<script>
import { CmsModalMix } from "./CmsModalMix";

export default {
  name: "CmsModal",
  mixins: [ CmsModalMix ],
  computed: {
    visible: {
      get() {
        return this.value;
      },
      set(val) {
        this.$emit("input", val); // 通过事件实现组件属性到父组件的传递
      },
    },
  },
  methods: {
    closeModal() {
      this.visible = false
      if (this.modalCallback) {
        this.modalCallback(false)
      }
      this.$emit('onCancel', false);
    },
    zoomModal(status) {
      this.$emit('zoom', status)
    },
    openModal() {
      this.$emit('open');
    }
  }
};
</script>
