<template>
  <static-content-wrapper
    :designer="designer" :field="field" :design-state="designState"
    :display-style="field.options.displayStyle"
    :parent-widget="parentWidget" :parent-list="parentList"
    :index-of-parent-list="indexOfParentList">
    <el-button :type="field.options.type" class="button-sty" size="mini" icon="el-icon-download" @click="importHandle"
               :disabled="field.options.disabled">{{ getI18nLabel(field.options.label)}}
    </el-button>
  </static-content-wrapper>

</template>
<script>
import emitter from '../../../../../components/xform/utils/emitter'
import i18n from "../../../../../components/xform/utils/i18n";
import fieldMixin from "../../../../../components/xform/form-designer/form-widget/field-widget/fieldMixin";
import StaticContentWrapper
  from "../../../../../components/xform/form-designer/form-widget/field-widget/static-content-wrapper.vue";

export default {
  name: "import2-button-widget",
  components: {StaticContentWrapper},
  componentName: 'FieldWidget',  //必须固定为FieldWidget，用于接收父级组件的broadcast事件
  mixins: [emitter, fieldMixin, i18n],
  props: {
    field: Object,
    parentWidget: Object,
    parentList: Array,
    indexOfParentList: Number,
    designer: Object,
    designState: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      exportOption: {}
    }
  },
  beforeCreate() {
    /* 这里不能访问方法和属性！！ */
  },
  created() {

    /* 注意：子组件mounted在父组件created之后、父组件mounted之前触发，故子组件mounted需要用到的prop
       需要在父组件created中初始化！！ */
    this.registerToRefList()
    this.initEventHandler()

    this.handleOnCreated()
  },

  mounted() {
    this.handleOnMounted()
  },

  beforeDestroy() {
    this.unregisterFromRefList()
  },

  methods: {
    importHandle() {
      const done = () => {
        this.getFormRef().openImportDialog({
          target: this,
          importOption: this.field.options,
          importFrontOnly: true,
          callback: (resultData, file, done) => {

          }
        });
      }
      if (this.field.options.onBeforeClickButton) {
        if (this.handleCustomEvent(this.field.options.onBeforeClickButton, ["done"], [done]) !== false) {
          done();
        }
      } else {
        done();
      }
    }
  }

}
</script>

<style lang="scss" scoped>
@import "~@/styles/global.scss"; //* static-content-wrapper已引入，还需要重复引入吗？ *//

</style>
