import { ref as T, computed as B, h as x, defineComponent as Z, reactive as O, watch as D, onMounted as j, resolveComponent as p, openBlock as g, createElementBlock as C, unref as m, createVNode as r, withCtx as u, createElementVNode as h, createCommentVNode as G, Fragment as $, renderList as q, createBlock as z, createTextVNode as A, toDisplayString as H, pushScopeId as J, popScopeId as X } from "vue";
import { Card as ee, InputSearch as te, Tree as oe, message as E } from "ant-design-vue";
import { useRouter as ae } from "vue-router";
import { g as y, o as ne, a as re, C as ue, D as se, W as le, d as ie, b as ce } from "./index.e7201430.js";
import { W as de, a as pe, b as me } from "./WorkflowBackModal.6c390a74.js";
import { W as fe } from "./WorkflowTaskModal.199ce16c.js";
import "sanzhi-form-design-vue3";
import "axios";
const I = T([]), N = T([]), f = T([]), P = B(() => f.value.map((n) => n.instanceId)), _e = B(() => f.value.map((n) => n.id));
function ge() {
  return new Promise((o, n) => {
    y("apis").getCategoryTree({ type: "WORKFLOW", parentId: 0 }).then((t) => {
      const { data: c } = t;
      I.value = c, c.length && N.value.push(c[0].id), o(t);
    }).catch((t) => {
      n(t);
    });
  });
}
function he() {
  return new Promise((o, n) => {
    o([{
      tabName: "\u5DF2\u5B8C\u7ED3",
      tabParam: "1",
      tabTitle: "\u5DF2\u5B8C\u7ED3"
    }, {
      tabName: "\u5DF2\u5F52\u6863",
      tabParam: "3",
      tabTitle: "\u5DF2\u5F52\u6863"
    }]);
  });
}
function ye(o) {
  const { archiveStatus: n, instanceRunStatus: t, instanceStatus: c } = o;
  return n ? { color: "success", text: "\u5DF2\u5F52\u6863" } : t === "END" ? { color: "default", text: "\u5DF2\u7EC8\u6B62" } : c ? { color: "processing", text: "\u5DF2\u5B8C\u7ED3" } : { color: "warning", text: "\u672A\u5B8C\u7ED3" };
}
function R(o = {}, n, t = {}) {
  let _ = {
    rowKey: "id",
    columns: [
      {
        title: "\u6807\u9898",
        dataIndex: "title",
        customRender: function({ record: l }) {
          const { flowId: d, instanceId: e, id: F, title: v } = l, w = { flowId: d, instanceId: e, taskId: F };
          return x("span", {
            class: "ant-btn-link pointer",
            onClick: function() {
              ne({ params: w, router: n });
            }
          }, v);
        },
        width: 350
      },
      {
        title: "\u6D41\u7A0B",
        dataIndex: "flowName",
        width: 150,
        ellipsis: !0
      },
      {
        title: "\u5F53\u524D\u6B65\u9AA4",
        dataIndex: "stepName",
        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: l }) {
          const d = ye(l);
          return x(de, {
            color: d.color,
            value: d.text
          });
        },
        width: 100
      },
      {
        title: "\u64CD\u4F5C",
        dataIndex: "actions",
        width: 80,
        fixed: "right",
        buttons: [
          {
            title: "\u6D41\u7A0B\u8F68\u8FF9",
            icon: "fund-outlined",
            props: {
              type: "primary"
            },
            key: "record",
            onClick: function(l) {
              o.modal.openModal({ data: l });
            }
          },
          {
            title: "\u5DE5\u4F5C\u4EFB\u52A1",
            icon: "control-outlined",
            props: {
              type: "primary"
            },
            key: "task",
            onClick: function(l) {
              o.taskModal.openModal({ data: l });
            }
          }
        ]
      }
    ],
    rowSelection: {
      onChange: (l, d) => {
        f.value = d;
      },
      selectedRowKeys: _e
    }
  };
  const { tableQuery: b = {} } = t;
  return b.status != "1" && delete _.rowSelection, _;
}
function M(o = {}) {
  const n = o.tableQuery && o.tableQuery.categoryId, t = o.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: "startTime",
          endTime: "endTime"
        },
        component: "a-range-picker",
        componentProps: {
          style: {
            width: "100%"
          },
          valueFormat: "YYYY-MM-DD"
        }
      }, {
        field: "categoryId",
        label: "\u5DE5\u4F5C\u6D41\u7A0B",
        hide: !t.noTree,
        defaultValue: n || "",
        component: "a-tree-select",
        componentProps: {
          "tree-data": I,
          "field-names": {
            children: "children",
            value: "id",
            label: "name"
          },
          treeDefaultExpandAll: !0
        }
      }]
    }
  };
}
const be = (o) => (J("data-v-5582bf2c"), o = o(), X(), o), Fe = { class: "workflow-manage" }, ve = {
  key: 0,
  class: "left"
}, we = { class: "input-box" }, ke = { class: "tree-box" }, De = { class: "right" }, Ce = /* @__PURE__ */ be(() => /* @__PURE__ */ h("p", null, "\u8BF7\u9009\u62E9\u5F52\u6863\u65F6\u95F4\uFF0C\u672A\u9009\u62E9\u65F6\u95F4\u5C06\u4F1A\u5F52\u6863\u5168\u90E8", -1)), Ee = /* @__PURE__ */ A("\u4E00\u952E\u5F52\u6863"), Te = /* @__PURE__ */ A(" \u5F52\u6863 "), Be = /* @__PURE__ */ Z({
  __name: "SanZhiWorkflowArchive",
  setup(o) {
    const n = ae(), t = {};
    function c(a) {
      t.table = a;
    }
    function _(a) {
      t.modal = a;
    }
    function b(a) {
      t.workflowForm = a;
    }
    function l(a) {
      t.backModal = a;
    }
    function d(a) {
      t.taskModal = a;
    }
    const e = O({
      locationQuery: re(),
      keyword: "",
      treeData: I,
      fieldNames: {
        children: "children",
        title: "name",
        key: "id"
      },
      selectedKeys: N,
      formProps: M(),
      tableProps: {},
      tabsList: [],
      tableQuery: {
        status: "1"
      },
      tableData: {},
      loading: !1,
      currentEdit: {},
      openNoticeModal: !1,
      notice: {},
      openEditModal: !1,
      isEdit: !1,
      flowId: "",
      archiveTimeRange: []
    });
    e.tableProps = R(t, n, e);
    const F = B(() => !e.locationQuery.noTree);
    D(
      () => e.selectedKeys,
      (a, s) => {
        const k = a[0] || "";
        e.tableQuery.categoryId = k, t.table.reload();
      },
      { deep: !0 }
    ), D(
      () => e.tableQuery.categoryId,
      () => {
        f.value = [];
      }
    ), D(
      () => e.tableQuery.status,
      () => {
        e.tableProps = R(t, n, e), f.value = [];
      }
    );
    function v() {
      return y("apis").getWorkflowTaskInstancePageList;
    }
    async function w() {
      const a = P.value.length;
      if (!a) {
        E.info("\u8BF7\u9009\u62E9\u81F3\u5C11\u4E00\u6761\u6570\u636E");
        return;
      }
      try {
        await ie({
          content: `\u786E\u8BA4\u5F52\u6863\u9009\u4E2D\u7684\u6D41\u7A0B\u4E48\uFF0C\u5171\u9009\u4E2D${a}\u6761`
        });
      } catch {
        return;
      }
      y("apis").archiveByInstanceList({ body: P.value }).then(() => {
        E.success("\u5F52\u6863\u6210\u529F");
      });
    }
    async function S() {
      const a = e.archiveTimeRange[0], s = e.archiveTimeRange[1];
      y("apis").archiveByLaunchTime({ startTime: a, endTime: s }).then(() => {
        E.success("\u4E00\u952E\u5F52\u6863\u6210\u529F");
      });
    }
    return j(() => {
      he().then((a) => {
        e.tabsList = a;
      }), ge().then(() => {
        e.formProps = M(e);
      });
    }), (a, s) => {
      const k = p("a-radio-button"), W = p("a-radio-group"), Q = p("a-range-picker"), K = p("a-menu-item"), L = p("a-popconfirm"), Y = p("a-menu"), V = p("a-dropdown-button");
      return g(), C("div", Fe, [
        m(F) ? (g(), C("div", ve, [
          r(m(ee), null, {
            default: u(() => [
              h("div", we, [
                r(m(te), {
                  value: e.keyword,
                  "onUpdate:value": s[0] || (s[0] = (i) => e.keyword = i),
                  placeholder: "\u8BF7\u8F93\u5165\u641C\u7D22\u5185\u5BB9"
                }, null, 8, ["value"])
              ]),
              h("div", ke, [
                r(m(oe), {
                  "tree-data": e.treeData,
                  selectedKeys: e.selectedKeys,
                  "onUpdate:selectedKeys": s[1] || (s[1] = (i) => e.selectedKeys = i),
                  fieldNames: e.fieldNames
                }, null, 8, ["tree-data", "selectedKeys", "fieldNames"])
              ])
            ]),
            _: 1
          })
        ])) : G("", !0),
        h("div", De, [
          r(m(ue), {
            api: v(),
            autoGet: !1,
            extraParams: e.tableQuery,
            tableProps: e.tableProps,
            formProps: e.formProps,
            onRegister: c
          }, {
            middle: u(() => [
              r(W, {
                value: e.tableQuery.status,
                "onUpdate:value": s[2] || (s[2] = (i) => e.tableQuery.status = i),
                onChange: t.table.reload
              }, {
                default: u(() => [
                  (g(!0), C($, null, q(e.tabsList, (i, U) => (g(), z(k, {
                    value: i.tabParam,
                    key: U
                  }, {
                    default: u(() => [
                      A(H(i.tabName), 1)
                    ]),
                    _: 2
                  }, 1032, ["value"]))), 128))
                ]),
                _: 1
              }, 8, ["value", "onChange"])
            ]),
            formRight: u(() => [
              r(V, {
                type: "primary",
                onClick: w
              }, {
                overlay: u(() => [
                  r(Y, null, {
                    default: u(() => [
                      r(L, {
                        placement: "bottom",
                        onConfirm: S
                      }, {
                        title: u(() => [
                          Ce,
                          r(Q, {
                            value: e.archiveTimeRange,
                            "onUpdate:value": s[3] || (s[3] = (i) => e.archiveTimeRange = i),
                            valueFormat: "YYYY-MM-DD",
                            dropdownClassName: "ponconfim-class"
                          }, null, 8, ["value"])
                        ]),
                        default: u(() => [
                          r(K, { key: "1" }, {
                            default: u(() => [
                              Ee
                            ]),
                            _: 1
                          })
                        ]),
                        _: 1
                      })
                    ]),
                    _: 1
                  })
                ]),
                icon: u(() => [
                  r(m(se))
                ]),
                default: u(() => [
                  Te
                ]),
                _: 1
              })
            ]),
            _: 1
          }, 8, ["api", "extraParams", "tableProps", "formProps"])
        ]),
        r(pe, { onRegister: _ }),
        r(me, { onRegister: l }),
        r(le, { onRegister: b }),
        r(fe, {
          hideActions: !0,
          onRegister: d
        })
      ]);
    };
  }
});
const We = /* @__PURE__ */ ce(Be, [["__scopeId", "data-v-5582bf2c"]]);
export {
  We as default
};
