<template>
  <el-dropdown trigger="hover">
    <el-button type="primary" class="button-sty" size="mini">
      <span>{{ $t2("列表导出", "components.excelExport.listExport") }}</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()"
        v-if="option.conditionExport !== false"
      >
        {{ $t2("条件导出", "components.excelExport.conditionExport") }}
      </el-dropdown-item>
      <el-dropdown-item
        icon="el-icon-upload2"
        @click.native="toDo('selected')"
        v-if="option.selectExport !== false"
      >
        {{ $t2("选择导出", "components.excelExport.selectExport") }}
      </el-dropdown-item>
      <el-dropdown-item
        icon="el-icon-upload2"
        @click.native="toDo('current')"
        v-if="option.currentExport === true"
      >
        {{ $t2("当前页导出", "components.excelExport.currentExport") }}
      </el-dropdown-item>
    </el-dropdown-menu>

    <indexViewDialog
      ref="indexViewDialogRef"
      v-if="showIndexViewDialog"
      :visiabled.sync="showIndexViewDialog"
      :param="indexViewOption"
    ></indexViewDialog>
  </el-dropdown>
</template>

<script>
import indexViewDialog from "./index.vue";

export default {
  name: "base-table-export",
  props: {
    option: Object,
  },
  components: {
    indexViewDialog,
  },
  data() {
    return {
      showExportFieldOptions: null,
      showExportFieldDialog: false,
      indexViewOption: null,
      showIndexViewDialog: false,
    };
  },
  methods: {
    toDo(type) {
      let that = this.$attrs["parent-target"];
      let option = {
        ...this.option,
        type: type,
        vue: that,
        destroyComponent: (loadingObj) => {
          this.showIndexViewDialog = false;
          if (loadingObj) {
            setTimeout(function () {
              loadingObj.close();
            }, 200);
          }
        },
      };

      /*
        // this.option = this.param;
        let $grid = getGrid(option.vue, option.targetRef);
        let datas = [];
        if (type == "selected") {
          datas = $grid.getCheckboxRecords(true);
          if (!datas.length) {
            this.$baseAlert(this.$t2('请选择导出的数据', 'components.excelExport.warmMsg1'));
            return;
          }
        } else if (type == "current") {
          datas = $grid.getTableData().fullData;
          if (!datas.length) {
            this.$baseAlert(this.$t2('不存在可导出的数据', 'components.excelExport.warmMsg2'));
            return;
          }
        }
        */

      this.indexViewOption = option;
      this.showIndexViewDialog = true;
      this.$nextTick(() => {
        this.$refs.indexViewDialogRef.exc();
      });
      // that.$excelExport(option);
    },
    openIndexViewDialog(option) {},
  },
};
</script>

<style scoped></style>
