import { ref as v, computed as I, h as T, defineComponent as j, reactive as z, watch as C, onMounted as $, resolveComponent as B, openBlock as F, createElementBlock as D, createVNode as o, unref as m, withCtx as s, createElementVNode as A, createCommentVNode as G, Fragment as q, renderList as H, createBlock as J, createTextVNode as y, toDisplayString as X } from "vue";
import { message as d, Card as N, InputSearch as ee, Tree as te, Button as M } from "ant-design-vue";
import { useRouter as ue } from "vue-router";
import { C as ae } from "./index.18983179.js";
import { d as i, n as ne, W as oe, k as E, h as re, D as le, p as se, _ as ie } from "./index.14fbe0a4.js";
import { W as ce } from "./WorkflowBackModal.d7a7566a.js";
import { W as de } from "./WorkflowFormRenderDrawer.92087c3d.js";
import { W as pe } from "./WorkflowTaskModal.f996c726.js";
import "axios";
import "./SanZhiFormRenderOA.6d13345d.js";
const x = v([]), R = v([]), b = v([]), h = I(() => b.value.map((r) => r.instanceId)), fe = I(() => b.value.map((r) => r.id));
function me() {
  return new Promise((n, r) => {
    i("apis").getWorkflowCategoryTree({ type: "WORKFLOW", parentId: 0 }).then((a) => {
      const { data: c } = a;
      x.value = c, c.length && R.value.push(c[0].id), n(a);
    }).catch((a) => {
      r(a);
    });
  });
}
function Ee() {
  return new Promise((n, r) => {
    n([{
      tabName: "\u5168\u90E8",
      tabParam: "",
      tabTitle: "\u5168\u90E8"
    }, {
      tabName: "\u5DF2\u5B8C\u7ED3",
      tabParam: "1",
      tabTitle: "\u5DF2\u5B8C\u7ED3"
    }, {
      tabName: "\u672A\u5B8C\u7ED3",
      tabParam: "0",
      tabTitle: "\u672A\u5B8C\u7ED3"
    }, {
      tabName: "\u5DF2\u7EC8\u6B62",
      tabParam: "2",
      tabTitle: "\u5168\u90E8\u72B6\u6001"
    }, {
      tabName: "\u5DF2\u5F52\u6863",
      tabParam: "3",
      tabTitle: "\u5DF2\u5F52\u6863"
    }]);
  });
}
function ye(n) {
  const { archiveStatus: r, instanceRunStatus: a, instanceStatus: c } = n;
  return r ? { color: "success", text: "\u5DF2\u5F52\u6863" } : a === "END" ? { color: "default", text: "\u5DF2\u7EC8\u6B62" } : c ? { color: "processing", text: "\u5DF2\u5B8C\u7ED3" } : { color: "warning", text: "\u672A\u5B8C\u7ED3" };
}
function ge(n = {}, r) {
  return {
    rowKey: "id",
    columns: [
      {
        title: "\u6807\u9898",
        dataIndex: "title",
        customRender: function({ record: u }) {
          const { flowId: l, instanceId: g, id: k, title: e } = u, w = { flowId: l, instanceId: g, taskId: k };
          return T("span", {
            class: "ant-btn-link pointer",
            onClick: function() {
              ne({ params: w, router: r });
            }
          }, e);
        },
        width: 350
      },
      {
        title: "\u6D41\u7A0B",
        dataIndex: "flowName",
        width: 150,
        ellipsis: !0
      },
      {
        title: "\u5F53\u524D\u6B65\u9AA4",
        dataIndex: "stepName",
        width: 100,
        ellipsis: !0
      },
      {
        title: "\u53D1\u8D77\u4EBA",
        dataIndex: "senderName",
        width: 100,
        ellipsis: !0
      },
      {
        title: "\u5904\u7406\u4EBA",
        dataIndex: "receiverName",
        width: 100,
        ellipsis: !0
      },
      {
        title: "\u53D1\u8D77\u65E5\u671F",
        dataIndex: "receiveTime",
        width: 190
      },
      {
        title: "\u6D41\u7A0B\u72B6\u6001",
        dataIndex: "instanceStatus",
        customRender: function({ record: u }) {
          const l = ye(u);
          return T(oe, {
            color: l.color,
            value: l.text
          });
        },
        width: 100
      },
      {
        title: "\u64CD\u4F5C",
        dataIndex: "actions",
        fixed: "right",
        width: 175,
        buttons: [
          {
            title: "\u6D41\u7A0B\u8F68\u8FF9",
            icon: "fund-outlined",
            props: {
              type: "primary"
            },
            key: "record",
            onClick: function(u) {
              n.modal.openModal({ data: u });
            }
          },
          {
            title: "\u5DE5\u4F5C\u4EFB\u52A1",
            icon: "control-outlined",
            props: {
              type: "primary"
            },
            key: "task",
            onClick: function(u) {
              n.taskModal.openModal({ data: u });
            }
          },
          {
            title: "\u7EC8\u6B62\u5B9E\u4F8B",
            icon: "poweroff-outlined",
            props: {
              type: "danger"
            },
            key: "end",
            hide: function(u) {
              const { instanceRunStatus: l, instanceStatus: g } = u;
              return !(!l && !g);
            },
            onClick: async function(u) {
              try {
                await E({
                  content: "\u786E\u8BA4\u7EC8\u6B62\u5F53\u524D\u5B9E\u4F8B\u4E48\uFF1F"
                });
              } catch {
                return;
              }
              i("apis").endFlowByInstanceId({ id: u.instanceId }).then(() => {
                d.success("\u7EC8\u6B62\u6210\u529F"), n.table.reload();
              });
            }
          },
          {
            title: "\u5220\u9664\u5B9E\u4F8B",
            icon: "delete-outlined",
            props: {
              type: "danger"
            },
            key: "del",
            hide: function(u) {
              const { instanceRunStatus: l } = u;
              return l !== "END";
            },
            onClick: async function(u) {
              try {
                await E({
                  content: "\u786E\u8BA4\u5220\u9664\u5F53\u524D\u5B9E\u4F8B\u4E48\uFF1F"
                });
              } catch {
                return;
              }
              i("apis").deleteEndWorkflowTaskById({ id: u.id }).then(() => {
                d.success("\u5220\u9664\u6210\u529F"), n.table.reload();
              });
            }
          },
          {
            title: "\u64A4\u56DE",
            icon: "rollback-outlined",
            props: {
              type: "warning"
            },
            key: "return",
            hide: function(u) {
              const { recall: l } = u;
              return !l;
            },
            onClick: async function(u) {
              try {
                await E({
                  content: "\u786E\u8BA4\u64A4\u56DE\u5F53\u524D\u5B9E\u4F8B\u4E48\uFF1F"
                });
              } catch {
                return;
              }
              i("apis").recall({ id: u.id }).then(() => {
                d.success("\u64A4\u56DE\u6210\u529F"), n.table.reload();
              });
            }
          }
        ]
      }
    ],
    rowSelection: {
      onChange: (u, l) => {
        b.value = l;
      },
      selectedRowKeys: fe
    }
  };
}
function W(n = {}) {
  const r = n.tableQuery && n.tableQuery.categoryId, a = n.locationQuery || {};
  return {
    formProps: {
      layout: "inline",
      columns: [{
        field: "title",
        label: "\u6807\u9898"
      }, {
        field: "sender",
        label: "\u53D1\u8D77\u4EBA"
      }, {
        field: "timeRange",
        label: "\u65F6\u95F4",
        colAttr: {
          span: 6
        },
        timeRangeFieldNames: {
          startTime: "completedStartTime",
          endTime: "completedEndTime"
        },
        component: "a-range-picker",
        componentProps: {
          style: {
            width: "100%"
          },
          valueFormat: "YYYY-MM-DD"
        }
      }, {
        field: "categoryId",
        label: "\u5DE5\u4F5C\u6D41\u7A0B",
        hide: !a.noTree,
        defaultValue: r || "",
        component: "a-tree-select",
        componentProps: {
          "tree-data": x,
          "field-names": {
            children: "children",
            value: "id",
            label: "name"
          },
          treeDefaultExpandAll: !0
        }
      }]
    }
  };
}
const Be = { class: "workflow-manage" }, be = {
  key: 0,
  class: "left"
}, Fe = { class: "input-box" }, he = { class: "tree-box" }, ke = { class: "right" }, we = /* @__PURE__ */ j({
  __name: "SanZhiWorkflowInstance",
  setup(n) {
    const r = ue(), a = {};
    function c(t) {
      a.table = t;
    }
    function u(t) {
      a.modal = t;
    }
    function l(t) {
      a.workflowForm = t;
    }
    function g(t) {
      a.backModal = t;
    }
    function k(t) {
      a.taskModal = t;
    }
    const e = z({
      locationQuery: re(),
      keyword: "",
      treeData: x,
      fieldNames: {
        children: "children",
        title: "name",
        key: "id"
      },
      selectedKeys: R,
      formProps: W(),
      tableProps: ge(a, r),
      tabsList: [],
      tableQuery: {
        status: ""
      },
      tableData: {},
      loading: !1,
      currentEdit: {},
      openNoticeModal: !1,
      notice: {},
      openEditModal: !1,
      isEdit: !1,
      flowId: ""
    }), w = I(() => !e.locationQuery.noTree);
    C(
      () => e.selectedKeys,
      (t, p) => {
        const _ = t[0] || "";
        e.tableQuery.categoryId = _, a.table.reload();
      },
      { deep: !0 }
    ), C(
      () => e.tableQuery.categoryId,
      () => {
        b.value = [];
      }
    ), C(
      () => e.tableQuery.status,
      () => {
        b.value = [];
      }
    );
    function S() {
      return i("apis").getWorkflowTaskInstanceLaunchPageList;
    }
    function L() {
      const t = a.table.getParams();
      e.loading = !0, i("apis.export").getWorkflowTaskInstanceExportExcel({ ...t }).then((p) => {
      }).finally(() => {
        e.loading = !1;
      });
    }
    async function Q() {
      const t = h.value.length;
      if (!t) {
        d.info("\u8BF7\u9009\u62E9\u81F3\u5C11\u4E00\u6761\u6570\u636E");
        return;
      }
      try {
        await E({
          content: `\u786E\u8BA4\u50AC\u529E\u9009\u4E2D\u7684\u6D41\u7A0B\u4E48\uFF0C\u5171\u9009\u4E2D${t}\u6761`
        });
      } catch {
        return;
      }
      i("apis").remindMyLaunchByInstanceList({ body: h.value }).then(() => {
        d.success("\u50AC\u529E\u6210\u529F");
      });
    }
    async function K({ key: t }) {
      if (t === "1") {
        try {
          await E({
            content: "\u786E\u8BA4\u4E00\u952E\u50AC\u529E\u4E48"
          });
        } catch {
          return;
        }
        i("apis").remindMyLaunchByInstanceList({ body: null }).then(() => {
          d.success("\u4E00\u952E\u50AC\u529E\u6210\u529F");
        });
        return;
      }
      try {
        await E({
          content: "\u786E\u8BA4\u4E00\u952E\u50AC\u529E\u4E0B\u4E00\u6B65\u4E48"
        });
      } catch {
        return;
      }
      i("apis").remindMyLaunchWaitByInstanceList({ body: null }).then(() => {
        d.success("\u4E00\u952E\u50AC\u529E\u4E0B\u4E00\u6B65\u6210\u529F");
      });
    }
    async function U() {
      const t = h.value.length;
      if (!t) {
        d.info("\u8BF7\u9009\u62E9\u81F3\u5C11\u4E00\u6761\u6570\u636E");
        return;
      }
      try {
        await E({
          content: `\u786E\u8BA4\u7EC8\u6B62\u9009\u4E2D\u7684\u6D41\u7A0B\u4E48\uFF0C\u5171\u9009\u4E2D${t}\u6761`
        });
      } catch {
        return;
      }
      i("apis").endBatchFlowByInstanceId({ body: h.value }).then(() => {
        d.success("\u7EC8\u6B62\u6D41\u7A0B\u6210\u529F"), a.table.reload();
      });
    }
    return $(() => {
      Ee().then((t) => {
        e.tabsList = t;
      }), me().then(() => {
        e.formProps = W(e);
      });
    }), (t, p) => {
      const _ = B("a-radio-button"), V = B("a-radio-group"), P = B("a-menu-item"), Y = B("a-menu"), O = B("a-dropdown-button");
      return F(), D("div", Be, [
        w.value ? (F(), D("div", be, [
          o(m(N), { size: "small" }, {
            default: s(() => [
              A("div", Fe, [
                o(m(ee), {
                  value: e.keyword,
                  "onUpdate:value": p[0] || (p[0] = (f) => e.keyword = f),
                  placeholder: "\u8BF7\u8F93\u5165\u641C\u7D22\u5185\u5BB9"
                }, null, 8, ["value"])
              ]),
              A("div", he, [
                o(m(te), {
                  "tree-data": e.treeData,
                  selectedKeys: e.selectedKeys,
                  "onUpdate:selectedKeys": p[1] || (p[1] = (f) => e.selectedKeys = f),
                  fieldNames: e.fieldNames
                }, null, 8, ["tree-data", "selectedKeys", "fieldNames"])
              ])
            ]),
            _: 1
          })
        ])) : G("", !0),
        A("div", ke, [
          o(m(N), { size: "small" }, {
            default: s(() => [
              o(m(ae), {
                api: S(),
                autoGet: !1,
                extraParams: e.tableQuery,
                tableProps: e.tableProps,
                formProps: e.formProps,
                onRegister: c
              }, {
                middle: s(() => [
                  o(V, {
                    value: e.tableQuery.status,
                    "onUpdate:value": p[2] || (p[2] = (f) => e.tableQuery.status = f),
                    onChange: a.table.reload
                  }, {
                    default: s(() => [
                      (F(!0), D(q, null, H(e.tabsList, (f, Z) => (F(), J(_, {
                        value: f.tabParam,
                        key: Z
                      }, {
                        default: s(() => [
                          y(X(f.tabName), 1)
                        ]),
                        _: 2
                      }, 1032, ["value"]))), 128))
                    ]),
                    _: 1
                  }, 8, ["value", "onChange"])
                ]),
                formRight: s(() => [
                  o(m(M), {
                    type: "primary",
                    onClick: L,
                    loading: e.loading
                  }, {
                    default: s(() => [
                      y(" \u5BFC\u51FA ")
                    ]),
                    _: 1
                  }, 8, ["loading"]),
                  o(m(M), {
                    danger: "",
                    onClick: U,
                    loading: e.loading
                  }, {
                    default: s(() => [
                      y(" \u7EC8\u6B62 ")
                    ]),
                    _: 1
                  }, 8, ["loading"]),
                  o(O, {
                    type: "danger",
                    onClick: Q
                  }, {
                    overlay: s(() => [
                      o(Y, { onClick: K }, {
                        default: s(() => [
                          o(P, { key: "1" }, {
                            default: s(() => [
                              y("\u4E00\u952E\u50AC\u529E")
                            ]),
                            _: 1
                          }),
                          o(P, { key: "2" }, {
                            default: s(() => [
                              y("\u4E00\u952E\u50AC\u529E\u4E0B\u4E00\u6B65")
                            ]),
                            _: 1
                          })
                        ]),
                        _: 1
                      })
                    ]),
                    icon: s(() => [
                      o(m(le))
                    ]),
                    default: s(() => [
                      y(" \u50AC\u529E ")
                    ]),
                    _: 1
                  })
                ]),
                _: 1
              }, 8, ["api", "extraParams", "tableProps", "formProps"])
            ]),
            _: 1
          })
        ]),
        o(se, { onRegister: u }),
        o(ce, { onRegister: g }),
        o(de, { onRegister: l }),
        o(pe, { onRegister: k })
      ]);
    };
  }
});
const Me = /* @__PURE__ */ ie(we, [["__scopeId", "data-v-9d34ce1a"]]);
export {
  Me as default
};
