<template>
  <div>
    <el-card v-if="labDesign.switch">设计模式不展示</el-card>
    <el-dialog :visible.sync="visible" center
               :title="element.props.title"
               :width="element.props.width"
               :full-screen="element.props.fullscreen"
               append-to-body destroy-on-close :close-on-click-modal="false" :close-on-press-escape="false"
      >
      <lab-view key="windowRef" :element="windowForm" :model-data="windowData" />
    </el-dialog>
  </div>
</template>

<script>
import LabBase from "../../mixins/LabBase";
import LabEvent from "../../mixins/LabEvent";

export default {
  name: "LabWindow",
  mixins: [LabBase,LabEvent],
  inject: {
    /**
     * 加载组件对象,注入异步方法
     */
    loadView: {
      from: 'loadView',
      default: function () {
        return function (ele){
          return new Promise(resolve => { return resolve(ele)})
        }
      }
    }
  },
  data() {
    return {
      visible: false,
      windowData: {},
      windowForm: { props: {}}
    }
  },
  methods: {
    open(args) {
      const { appCmd, callCmd, versionId } = this.element.props
      this.windowForm.props = { appCmd, callCmd, versionId }
      this.loadView(this.windowForm, args)
      .then(res => {
        if (res.code === 200) {
          this.windowData = this.$Util.copy(args)
          this.dispatchEvent('open', { modelData: this.windowData })
          .then(() => {
            this.visible = true
          })
        }
      })
    },
    close(){
      this.visible = false
      this.$Util.cleanObj(this, this.windowData)
      this.$Util.cleanObj(this, this.windowForm)
      this.dispatchEvent('close', { modelData: this.windowData })
    }
  }
}
</script>

<style scoped>

</style>
