<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-dropdown trigger="hover" :disabled="field.options.disabled">
      <el-button type="primary" class="button-sty" size="mini">
        <span>{{ getI18nLabel("列表导出") }}</span
        ><span class="line"></span> <i class="el-icon-arrow-down el-icon--right"></i>
      </el-button>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item icon="el-icon-upload2" @click.native="toDo()">
          {{ getI18nLabel("条件导出") }}
        </el-dropdown-item>
        <el-dropdown-item icon="el-icon-upload2" @click.native="toDo('selected')">
          {{ getI18nLabel("选择导出") }}
        </el-dropdown-item>
        <!-- <el-dropdown-item icon="el-icon-upload2" @click.native="toDo('exportItem')">
          {{ getI18nLabel("选择导出明细") }}
        </el-dropdown-item> -->
      </el-dropdown-menu>
    </el-dropdown>
  </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: "table-export-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 {};
  },
  beforeCreate() {
    /* 这里不能访问方法和属性！！ */
  },

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

    this.handleOnCreated();
  },

  mounted() {
    this.handleOnMounted();
  },

  beforeDestroy() {
    this.unregisterFromRefList();
  },

  methods: {
    toDo(type = null) {
      if (this.designState) {
        return;
      }
      let opt = {
        title: this.field.options.exportFileName || null,
        targetRef: this.field.options.tableRef || null,
        pageSize: this.field.options.exportPageSize || null,
        showImageAtTable: this.field.options.showImageAtTable || null,
      };
      let tableExportParam = this.handleCustomEvent(this.field.options.tableExportParam);
      let options = { ...opt, ...tableExportParam, type: type };
      let tableRef = options?.targetRef;
      delete options.targetRef;
      let tableWidget = this.getWidgetRef(tableRef);
      tableWidget.exportData(options);
    },
  },
};
</script>

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