'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
var elementPlus = require('element-plus');
var exports$1 = require('../../../../utils/src/elementPlus/exports.js');
var index = require('../../plugins/message/index.js');
var iconsVue = require('@element-plus/icons-vue');
var importDialog = require('./importDialog.js');

const _hoisted_1 = { class: "" };
const _hoisted_2 = { class: "gm-mb-2 gm-bg-[#f5f5f5] gm-p-4" };
const _hoisted_3 = /* @__PURE__ */ vue.createElementVNode(
  "p",
  { class: "gm-mb-3 gm-text-[13px]" },
  "\u4E0B\u8F7D\u5BFC\u5165\u6A21\u677F\uFF0C\u6839\u636E\u6A21\u677F\u63D0\u793A\u5B8C\u5584\u5185\u5BB9",
  -1
  /* HOISTED */
);
const _hoisted_4 = /* @__PURE__ */ vue.createElementVNode(
  "div",
  { class: "el-upload__text" },
  [
    /* @__PURE__ */ vue.createTextVNode("\u5C06\u6587\u4EF6\u62D6\u5230\u6B64\u5904\uFF0C\u6216 "),
    /* @__PURE__ */ vue.createElementVNode("em", null, "\u70B9\u51FB\u4E0A\u4F20")
  ],
  -1
  /* HOISTED */
);
const _hoisted_5 = /* @__PURE__ */ vue.createElementVNode(
  "div",
  { class: "gm-text-[#999]" },
  "\u9650\u52361\u4E2A\u6587\u4EF6\uFF0C\u65B0\u6587\u4EF6\u5C06\u8986\u76D6\u65E7\u6587\u4EF6",
  -1
  /* HOISTED */
);
const _hoisted_6 = { class: "dialog-footer" };
var _sfc_main = /* @__PURE__ */ vue.defineComponent({
  ...{
    name: "GmImportDialog"
  },
  __name: "ImportDialog",
  props: /* @__PURE__ */ vue.mergeModels(importDialog.importDialogProps, {
    "fileList": { default: () => [] },
    "fileListModifiers": {}
  }),
  emits: /* @__PURE__ */ vue.mergeModels(importDialog.importDialogEmits, ["update:fileList"]),
  setup(__props, { expose: __expose, emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const fileList = vue.useModel(__props, "fileList");
    const uploadRef = vue.ref();
    const handleExceed = (files, uploadFiles) => {
      uploadRef.value.clearFiles();
      const file = files[0];
      file.uid = elementPlus.genFileId();
      uploadRef.value.handleStart(file);
      props.onExceed?.(files, uploadFiles);
    };
    const submitUpload = () => {
      if (fileList.value.length === 0) {
        return index.GmMessage.error("\u8BF7\u9009\u62E9\u6587\u4EF6");
      }
      uploadRef.value.submit();
      emit("importClick");
    };
    const dialogVisible = vue.ref(false);
    const openDialog = () => {
      dialogVisible.value = true;
    };
    function closeDialog() {
      dialogVisible.value = false;
      reset();
    }
    function reset() {
      fileList.value = [];
      uploadRef.value?.clearFiles();
    }
    const uploadLoading = vue.ref(false);
    const httpRequest = (options) => {
      uploadLoading.value = true;
      return props.httpRequest(options);
    };
    function handleSuccess(response, uploadFile, uploadFiles) {
      uploadLoading.value = false;
      return props.onSuccess(response, uploadFile, uploadFiles);
    }
    const handleError = (error, uploadFile, uploadFiles) => {
      const file = uploadFile.raw;
      if (props.errorReselect && file) {
        file.uid = elementPlus.genFileId();
        uploadRef.value?.handleStart(file);
      }
      uploadLoading.value = false;
      return props.onError(error, uploadFile, uploadFiles);
    };
    const exposeNames = ["abort", "submit", "clearFiles", "handleStart", "handleRemove"];
    const { exposeFns } = exports$1.getGmExports(uploadRef, exposeNames);
    __expose({
      openDialog,
      closeDialog,
      reset,
      ...exposeFns
    });
    return (_ctx, _cache) => {
      const _component_gm_button = vue.resolveComponent("gm-button");
      const _component_el_icon = vue.resolveComponent("el-icon");
      const _component_gm_upload = vue.resolveComponent("gm-upload");
      const _component_gm_dialog = vue.resolveComponent("gm-dialog");
      return vue.openBlock(), vue.createElementBlock(
        vue.Fragment,
        null,
        [
          vue.createCommentVNode(" \u5BFC\u5165\u5BF9\u8BDD\u6846 "),
          vue.createVNode(_component_gm_dialog, vue.mergeProps(_ctx.dialogProps, {
            modelValue: dialogVisible.value,
            "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => dialogVisible.value = $event)
          }), {
            footer: vue.withCtx(() => [
              vue.createElementVNode("div", _hoisted_6, [
                vue.createVNode(_component_gm_button, {
                  type: "primary",
                  loading: uploadLoading.value,
                  onClick: submitUpload
                }, {
                  default: vue.withCtx(() => [
                    vue.createTextVNode("\u5BFC \u5165")
                  ]),
                  _: 1
                  /* STABLE */
                }, 8, ["loading"]),
                vue.createVNode(_component_gm_button, { onClick: closeDialog }, {
                  default: vue.withCtx(() => [
                    vue.createTextVNode("\u53D6 \u6D88")
                  ]),
                  _: 1
                  /* STABLE */
                })
              ])
            ]),
            default: vue.withCtx(() => [
              vue.createElementVNode("div", _hoisted_1, [
                vue.createElementVNode("div", _hoisted_2, [
                  _hoisted_3,
                  vue.createVNode(_component_gm_button, {
                    icon: vue.unref(iconsVue.Download),
                    onClick: _cache[0] || (_cache[0] = vue.withModifiers(($event) => emit("downloadTemplate"), ["stop"]))
                  }, {
                    default: vue.withCtx(() => [
                      vue.createTextVNode(" \u4E0B\u8F7D\u6A21\u677F ")
                    ]),
                    _: 1
                    /* STABLE */
                  }, 8, ["icon"])
                ]),
                vue.renderSlot(_ctx.$slots, "default"),
                vue.createVNode(_component_gm_upload, {
                  ref_key: "uploadRef",
                  ref: uploadRef,
                  "file-list": fileList.value,
                  "onUpdate:fileList": _cache[1] || (_cache[1] = ($event) => fileList.value = $event),
                  action: "",
                  limit: 1,
                  drag: "",
                  accept: _ctx.accept,
                  "http-request": httpRequest,
                  "on-exceed": handleExceed,
                  "on-success": handleSuccess,
                  "on-error": handleError,
                  "on-remove": _ctx.onRemove,
                  "before-upload": _ctx.beforeUpload,
                  "auto-upload": false,
                  class: "gmUploadEl gm-mb-5"
                }, {
                  default: vue.withCtx(() => [
                    vue.createVNode(_component_el_icon, { class: "el-icon--upload" }, {
                      default: vue.withCtx(() => [
                        vue.createVNode(vue.unref(iconsVue.UploadFilled))
                      ]),
                      _: 1
                      /* STABLE */
                    }),
                    _hoisted_4,
                    _hoisted_5
                  ]),
                  _: 1
                  /* STABLE */
                }, 8, ["file-list", "accept", "on-remove", "before-upload"])
              ])
            ]),
            _: 3
            /* FORWARDED */
          }, 16, ["modelValue"])
        ],
        2112
        /* STABLE_FRAGMENT, DEV_ROOT_FRAGMENT */
      );
    };
  }
});

exports.default = _sfc_main;
//# sourceMappingURL=ImportDialog.vue2.js.map
