<template>

  <vxe-modal class="vxe-table--ignore-clear" id="myModal" @close="modalClose" v-model="visible" :width="width" :height="height"

  :show-footer="showFooter"
      @confirm="confirmEvent"
    min-width="600" min-height="400" show-zoom resize  transfer>
    <template #title>
      <span>{{ title }}</span>
    </template>
    <template #default>
      <component :is="app" ref="appPage" :dataId="dataId" :pageOptions="pageOptions" :pageMode="pageMode" @callback="handleCallback"></component>
    </template>
  </vxe-modal>

</template>
<script>

export default {
  name: "myDialog",
  data() {
    return {
      width:800,
      height:800,
      visible: false,
      title: "提示",
      callback: null,
      showFooter:false,
      dataId: "",
      pageMode: "", //add edit select
      pageOptions:{},
      app: null
    };
  },
  methods: {


    open(options) {
      const { page, title, callback, pageMode, dataId,width = 800,height = 600 , pageOptions = {} ,showFooter } = options || {}; 
      
      this.width = width;
      this.height = height;
      this.dataId = dataId;
      this.pageMode = pageMode;
      this.title = title;
      this.pageOptions = pageOptions;
      this.app = page;
      this.callback = callback;
      this.showFooter = showFooter;

      setTimeout(() => {
        this.visible = true;
      }, 10);
    },
    handleCallback(e) {
      const { callback } = this;
      if (callback) {
        callback(e);
        this.$destroy();
      }
    },
    modalClose() {
      this.$destroy();
    },
    confirmEvent(){
      const { callback } = this;
      let data = this.$refs.appPage.getConfirmData();
      if (callback) {
        callback({data});
        this.$destroy();
      }
    }
  },
};
</script>
  