import { ref as _, defineComponent as w, reactive as b, onMounted as W, resolveComponent as f, openBlock as h, createBlock as D, mergeProps as B, withCtx as n, createVNode as s, createTextVNode as C, nextTick as M, createElementBlock as I, createElementVNode as O, unref as y } from "vue";
import { message as P, Card as R, Button as T } from "ant-design-vue";
import { C as L } from "./index.18983179.js";
import { d as m, _ as k, W as A, e as x, k as S, h as V } from "./index.14fbe0a4.js";
import { useRouter as U } from "vue-router";
import "axios";
const v = _([]);
async function F(o) {
  try {
    const e = await m("apis").getWorkflowCategoryTree({ ...o, parentId: 0 });
    return v.value = e.data, e || [];
  } catch (e) {
    throw new Error(e);
  }
}
async function Y(o) {
  try {
    const e = await m("apis").addOrUpdateWorkflowCategory({ body: o });
    return P.success("\u64CD\u4F5C\u6210\u529F"), e || [];
  } catch (e) {
    throw new Error(e);
  }
}
function $() {
  return {
    layout: "vertical",
    rowAttr: {
      gutter: { xs: 8, sm: 16, md: 24 }
    },
    baseColAttr: {
      span: 12
    },
    columns: [{
      label: "\u5206\u7C7B\u540D\u79F0",
      field: "name",
      component: "a-input"
    }, {
      label: "\u7C7B\u578B",
      field: "type",
      defaultValue: "WORKFLOW",
      component: "dict-select",
      componentProps: {
        dict: "CATEGORY_TYPE",
        selectProps: {
          onChange(e) {
            F({ type: e });
          }
        }
      }
    }, {
      label: "\u4E0A\u7EA7",
      field: "parentId",
      component: "a-cascader",
      componentProps: {
        options: v,
        "change-on-select": !0,
        fieldNames: {
          label: "name",
          value: "id"
        }
      }
    }, {
      label: "\u6392\u5E8F",
      field: "sort",
      component: "a-input-number"
    }]
  };
}
F({ type: "WORKFLOW" });
const K = w({
  components: { WorkflowStatus: A, ConfigForm: x },
  props: {
    hideActions: {
      type: [Boolean],
      default: !1
    }
  },
  emits: ["register", "success"],
  setup(o, { emit: e }) {
    U();
    const a = b({
      formData: {},
      formProps: {},
      actionLoading: !1
    });
    a.formProps = $();
    const t = _(!1), l = _({}), d = {};
    function p(i) {
      Object.assign(d, i);
    }
    async function u(i = {}) {
      t.value = !0;
      const { data: c = {}, isUpdate: E } = i;
      l.value = c, await M(), await d.resetFormData(), E && (a.formData = c);
    }
    function r() {
      t.value = !1;
    }
    async function g() {
      const { parentId: i = [] } = a.formData;
      try {
        a.actionLoading = !0, await Y({ ...a.formData, parentId: i.pop ? i.pop() : i });
      } catch (c) {
        console.log(c);
        return;
      } finally {
        a.actionLoading = !1;
      }
      e("success"), r();
    }
    return W(() => {
      e("register", { openModal: u, closeModal: r });
    }), {
      visible: t,
      modalData: l,
      state: a,
      closeModal: r,
      handleSave: g,
      registerForm: p
    };
  }
});
function N(o, e, a, t, l, d) {
  const p = f("ConfigForm"), u = f("a-button"), r = f("a-col"), g = f("a-row"), i = f("a-drawer");
  return h(), D(i, B({
    title: "\u7F16\u8F91\u6D41\u7A0B\u5206\u7C7B",
    visible: o.visible,
    "onUpdate:visible": e[1] || (e[1] = (c) => o.visible = c),
    width: "800px"
  }, o.$attrs), {
    footer: n(() => [
      s(g, {
        gutter: 15,
        justify: "end"
      }, {
        default: n(() => [
          s(r, null, {
            default: n(() => [
              s(u, {
                type: "primary",
                onClick: o.handleSave,
                loading: o.state.actionLoading
              }, {
                default: n(() => [
                  C("\u4FDD\u5B58")
                ]),
                _: 1
              }, 8, ["onClick", "loading"])
            ]),
            _: 1
          }),
          s(r, null, {
            default: n(() => [
              s(u, {
                onClick: o.closeModal,
                loading: o.state.actionLoading
              }, {
                default: n(() => [
                  C("\u53D6\u6D88")
                ]),
                _: 1
              }, 8, ["onClick", "loading"])
            ]),
            _: 1
          })
        ]),
        _: 1
      })
    ]),
    default: n(() => [
      s(p, {
        modelValue: o.state.formData,
        "onUpdate:modelValue": e[0] || (e[0] = (c) => o.state.formData = c),
        formProps: o.state.formProps,
        onRegister: o.registerForm
      }, null, 8, ["modelValue", "formProps", "onRegister"])
    ]),
    _: 1
  }, 16, ["visible"]);
}
const Q = /* @__PURE__ */ k(K, [["render", N], ["__scopeId", "data-v-7b8e34b7"]]);
async function G(o) {
  try {
    const e = await m("apis").deleteWorkflowCategoryById(o);
    return P.success("\u5220\u9664\u6210\u529F"), e;
  } catch (e) {
    throw new Error(e);
  }
}
function Z(o = {}) {
  return {
    rowKey: "id",
    columns: [
      {
        title: "\u5206\u7C7B\u540D\u79F0",
        dataIndex: "name"
      },
      {
        title: "\u7C7B\u578B",
        dataIndex: "type",
        customRender: function({ record: t }) {
          return m("showDictionary")("CATEGORY_TYPE", t.type);
        }
      },
      {
        title: "\u6392\u5E8F",
        dataIndex: "sort"
      },
      {
        title: "\u521B\u5EFA\u65E5\u671F",
        dataIndex: "createTime"
      },
      {
        title: "\u64CD\u4F5C",
        dataIndex: "actions",
        width: 90,
        fixed: "right",
        buttons: [
          {
            title: "\u7F16\u8F91",
            icon: "edit-outlined",
            props: {
              type: "primary"
            },
            key: "record",
            onClick: function(t) {
              o.categoryModal.openModal({ data: t, isUpdate: !0 });
            }
          },
          {
            title: "\u5220\u9664",
            icon: "delete-outlined",
            props: {
              danger: !0
            },
            key: "delete",
            onClick: async function(t) {
              try {
                await S({});
              } catch {
                return;
              }
              G({ id: t.id });
            }
          }
        ]
      }
    ]
  };
}
function j() {
  return {
    formProps: {
      columns: [{
        field: "keywords",
        label: "\u5173\u952E\u5B57"
      }, {
        label: "\u7C7B\u578B",
        field: "type",
        defaultValue: "WORKFLOW",
        component: "dict-select",
        componentProps: {
          dict: "CATEGORY_TYPE",
          selectProps: {
            allowClear: !0
          }
        }
      }]
    }
  };
}
const z = { class: "workflow-category" }, q = { class: "right" }, H = /* @__PURE__ */ w({
  __name: "SanZhiWorkflowCategory",
  setup(o) {
    const e = {};
    function a(r) {
      e.table = r;
    }
    function t(r) {
      e.categoryModal = r;
    }
    const l = b({
      locationQuery: V(),
      formProps: j(),
      tableProps: Z(e),
      tabsList: [],
      tableQuery: {
        type: "WORKFLOW"
      },
      tableData: {},
      loading: !1,
      openEditModal: !1,
      isEdit: !1,
      flowId: ""
    });
    function d() {
      return m("apis").getWorkflowCategoryPageList;
    }
    function p() {
      e.categoryModal.openModal();
    }
    function u() {
      e.table.reload();
    }
    return (r, g) => (h(), I("div", z, [
      O("div", q, [
        s(y(R), { size: "small" }, {
          default: n(() => [
            s(y(L), {
              api: d(),
              extraParams: l.tableQuery,
              tableProps: l.tableProps,
              formProps: l.formProps,
              onRegister: a
            }, {
              formRight: n(() => [
                s(y(T), {
                  type: "primary",
                  onClick: p,
                  loading: l.loading
                }, {
                  default: n(() => [
                    C(" \u65B0\u589E ")
                  ]),
                  _: 1
                }, 8, ["loading"])
              ]),
              _: 1
            }, 8, ["api", "extraParams", "tableProps", "formProps"])
          ]),
          _: 1
        })
      ]),
      s(Q, {
        onRegister: t,
        onSuccess: u
      })
    ]));
  }
});
const re = /* @__PURE__ */ k(H, [["__scopeId", "data-v-d0dc616f"]]);
export {
  re as default
};
