<script>
export default {
  name: "ExportDialog",
  props: {
    data: {
      type: [Object],
      require: true,
    },
    page: {
      type: [Object],
      require: true,
    },
  },
  data() {
    return {
      title: "导 出",
    };
  },
  computed: {},
  watch: {},
  methods: {
    //
    open() {
      this.$confirm("是否确认导出所有数据项?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "info",
        beforeClose: async (action, instance, done) => {
          if (action === "confirm") {
            instance.confirmButtonLoading = true;
            instance.confirmButtonText = "下载中...";
            try {
              // try
              const {
                data,
                page: { pageNum, pageSize },
              } = this.$props;
              await this.download(
                "pu/order/generate/export",
                { ...data, pageNum, pageSize },
                `task_${new Date().getTime()}.xlsx`
              );
              await done();
            } catch (err) {
              // catch
              console.error(err);
              instance.confirmButtonText = "确认";
            } finally {
              // finally
              instance.confirmButtonLoading = false;
            }
          } else {
            done();
          }
        },
      })
        .then(() => {})
        .catch(() => {});
    },
  },
  created() {},
  mounted() {},
  destroyed() {},
};
</script>
<template>
  <el-button v-bind="$attrs" v-on="$listeners" @click="open">
    {{ title }}
  </el-button>
</template>
