<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" v-if="designState" :disabled="field.options.disabled">
      <el-button type="primary" class="button-sty" size="mini">
        <span>{{ getI18nLabel(field.options.label) }}</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"
          command="1"
        >导出</el-dropdown-item>
        <el-dropdown-item
          icon="el-icon-printer"
          :command="2"
        >打印</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
    <base-input-export
      v-else
      :option="exportOption"
      :parent-target="getFormRef()"
      :disabled="field.options.disabled"
    />
  </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: "print-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();
    this.init();
  },

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

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

  methods: {
    init() {
      if (this.designState) return;
      let prefix = "/" + this.getFormRef().reportTemplate.serviceName;
      // let printOption = this.handleCustomEvent(this.field.options.printOption);
      let codes = this.field.options.printItems
        .filter((item) => !!item.code)
        .map((item) => item.code);
      let label = null;
      /* if (this.field.options.customLabelEnabled && this.field.options.label) {
        label = this.$t1(this.field.options.label);
      } */
      if (this.field.options.label) {
        label = this.$t1(this.field.options.label);
      }
      let option = {
        prefix: prefix,
        tableTarget: () => {
          return this.getWidgetRef(this.field.options.printTableRef).getGridTable();
        },
        codes,
        label,
        // codes: ["USEREXCEL", "USERPDF", "USERPRINT", "USERHIPRINT", "USERJDPRINT", "USERPDDPRINT", "USERVIPPRINT"],
        // ...printOption
      };
      console.log("a:", option);
      this.exportOption = option;
    },
  },
};
</script>

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