import { ref as I, computed as v, h as T, defineComponent as Z, reactive as j, watch as C, onMounted as $, resolveComponent as g, openBlock as h, createElementBlock as D, unref as m, createVNode as o, withCtx as l, createElementVNode as A, createCommentVNode as G, Fragment as q, renderList as z, createBlock as H, createTextVNode as y, toDisplayString as J } from "vue";
import { message as d, Card as X, InputSearch as ee, Tree as te, Button as N } from "ant-design-vue";
import { useRouter as ue } from "vue-router";
import { g as i, o as ae, d as E, a as ne, C as oe, D as re, W as se, b as le } from "./index.e7201430.js";
import { W as ie, a as ce, b as de } from "./WorkflowBackModal.6c390a74.js";
import { W as pe } from "./WorkflowTaskModal.199ce16c.js";
import "sanzhi-form-design-vue3";
import "axios";
const P = I([]), R = I([]), B = I([]), F = v(() => B.value.map((r) => r.instanceId)), fe = v(() => B.value.map((r) => r.id));
function me() {
  return new Promise((n, r) => {
    i("apis").getCategoryTree({ type: "WORKFLOW", parentId: 0 }).then((a) => {
      const { data: c } = a;
      P.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 be(n = {}, r) {
  return {
    rowKey: "id",
    columns: [
      {
        title: "\u6807\u9898",
        dataIndex: "title",
        customRender: function({ record: u }) {
          const { flowId: s, instanceId: b, id: _, title: e } = u, w = { flowId: s, instanceId: b, taskId: _ };
          return T("span", {
            class: "ant-btn-link pointer",
            onClick: function() {
              ae({ 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 s = ye(u);
          return T(ie, {
            color: s.color,
            value: s.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: s, instanceStatus: b } = u;
              return !(!s && !b);
            },
            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: s } = u;
              return s !== "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: s } = u;
              return !s;
            },
            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, s) => {
        B.value = s;
      },
      selectedRowKeys: fe
    }
  };
}
function M(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": P,
          "field-names": {
            children: "children",
            value: "id",
            label: "name"
          },
          treeDefaultExpandAll: !0
        }
      }]
    }
  };
}
const ge = { class: "workflow-manage" }, Be = {
  key: 0,
  class: "left"
}, he = { class: "input-box" }, Fe = { class: "tree-box" }, _e = { class: "right" }, we = /* @__PURE__ */ y(" \u5BFC\u51FA "), ke = /* @__PURE__ */ y(" \u7EC8\u6B62 "), Ce = /* @__PURE__ */ y("\u4E00\u952E\u50AC\u529E"), De = /* @__PURE__ */ y("\u4E00\u952E\u50AC\u529E\u4E0B\u4E00\u6B65"), Ae = /* @__PURE__ */ y(" \u50AC\u529E "), Ie = /* @__PURE__ */ Z({
  __name: "SanZhiWorkflowInstance",
  setup(n) {
    const r = ue(), a = {};
    function c(t) {
      a.table = t;
    }
    function u(t) {
      a.modal = t;
    }
    function s(t) {
      a.workflowForm = t;
    }
    function b(t) {
      a.backModal = t;
    }
    function _(t) {
      a.taskModal = t;
    }
    const e = j({
      locationQuery: ne(),
      keyword: "",
      treeData: P,
      fieldNames: {
        children: "children",
        title: "name",
        key: "id"
      },
      selectedKeys: R,
      formProps: M(),
      tableProps: be(a, r),
      tabsList: [],
      tableQuery: {
        status: ""
      },
      tableData: {},
      loading: !1,
      currentEdit: {},
      openNoticeModal: !1,
      notice: {},
      openEditModal: !1,
      isEdit: !1,
      flowId: ""
    }), w = v(() => !e.locationQuery.noTree);
    C(
      () => e.selectedKeys,
      (t, p) => {
        const k = t[0] || "";
        e.tableQuery.categoryId = k, a.table.reload();
      },
      { deep: !0 }
    ), C(
      () => e.tableQuery.categoryId,
      () => {
        B.value = [];
      }
    ), C(
      () => e.tableQuery.status,
      () => {
        B.value = [];
      }
    );
    function W() {
      return i("apis").getWorkflowTaskInstanceLaunchPageList;
    }
    function S() {
      const t = a.table.getParams();
      e.loading = !0, i("apis").getWorkflowTaskInstanceExportExcel({ ...t }).then((p) => {
      }).finally(() => {
        e.loading = !1;
      });
    }
    async function L() {
      const t = F.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: F.value }).then(() => {
        d.success("\u50AC\u529E\u6210\u529F");
      });
    }
    async function Q({ 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 K() {
      const t = F.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: F.value }).then(() => {
        d.success("\u7EC8\u6B62\u6D41\u7A0B\u6210\u529F"), a.table.reload();
      });
    }
    return $(() => {
      Ee().then((t) => {
        e.tabsList = t;
      }), me().then(() => {
        e.formProps = M(e);
      });
    }), (t, p) => {
      const k = g("a-radio-button"), U = g("a-radio-group"), x = g("a-menu-item"), V = g("a-menu"), Y = g("a-dropdown-button");
      return h(), D("div", ge, [
        m(w) ? (h(), D("div", Be, [
          o(m(X), null, {
            default: l(() => [
              A("div", he, [
                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", Fe, [
                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", _e, [
          o(m(oe), {
            api: W(),
            autoGet: !1,
            extraParams: e.tableQuery,
            tableProps: e.tableProps,
            formProps: e.formProps,
            onRegister: c
          }, {
            middle: l(() => [
              o(U, {
                value: e.tableQuery.status,
                "onUpdate:value": p[2] || (p[2] = (f) => e.tableQuery.status = f),
                onChange: a.table.reload
              }, {
                default: l(() => [
                  (h(!0), D(q, null, z(e.tabsList, (f, O) => (h(), H(k, {
                    value: f.tabParam,
                    key: O
                  }, {
                    default: l(() => [
                      y(J(f.tabName), 1)
                    ]),
                    _: 2
                  }, 1032, ["value"]))), 128))
                ]),
                _: 1
              }, 8, ["value", "onChange"])
            ]),
            formRight: l(() => [
              o(m(N), {
                type: "primary",
                onClick: S,
                loading: e.loading
              }, {
                default: l(() => [
                  we
                ]),
                _: 1
              }, 8, ["loading"]),
              o(m(N), {
                danger: "",
                onClick: K,
                loading: e.loading
              }, {
                default: l(() => [
                  ke
                ]),
                _: 1
              }, 8, ["loading"]),
              o(Y, {
                type: "danger",
                onClick: L
              }, {
                overlay: l(() => [
                  o(V, { onClick: Q }, {
                    default: l(() => [
                      o(x, { key: "1" }, {
                        default: l(() => [
                          Ce
                        ]),
                        _: 1
                      }),
                      o(x, { key: "2" }, {
                        default: l(() => [
                          De
                        ]),
                        _: 1
                      })
                    ]),
                    _: 1
                  })
                ]),
                icon: l(() => [
                  o(m(re))
                ]),
                default: l(() => [
                  Ae
                ]),
                _: 1
              })
            ]),
            _: 1
          }, 8, ["api", "extraParams", "tableProps", "formProps"])
        ]),
        o(ce, { onRegister: u }),
        o(de, { onRegister: b }),
        o(se, { onRegister: s }),
        o(pe, { onRegister: _ })
      ]);
    };
  }
});
const Se = /* @__PURE__ */ le(Ie, [["__scopeId", "data-v-c0b36b6b"]]);
export {
  Se as default
};
