var U = ($, D, f) => new Promise((B, g) => {
  var C = (o) => {
    try {
      _(f.next(o));
    } catch (h) {
      g(h);
    }
  }, N = (o) => {
    try {
      _(f.throw(o));
    } catch (h) {
      g(h);
    }
  }, _ = (o) => o.done ? B(o.value) : Promise.resolve(o.value).then(C, N);
  _((f = f.apply($, D)).next());
});
import { ref as i, watch as he, onMounted as _e, resolveComponent as A, openBlock as k, createElementBlock as S, createVNode as c, withCtx as v, createTextVNode as I, toDisplayString as u, createElementVNode as t, withModifiers as me, Fragment as J, renderList as K, normalizeStyle as P, createCommentVNode as pe } from "vue";
import { aK as fe, aL as ge, aM as Ce, aN as we, aO as ye, U as ke, aP as Se, aG as $e, aQ as be, aR as Oe } from "./index2.js";
const Ne = { class: "s-office-select-common" }, Le = { class: "modal-container" }, Ve = { class: "side" }, Te = { class: "main" }, je = { class: "filter" }, Ue = { class: "list-wrap" }, Ae = { class: "item left-wrap" }, Ie = { class: "head" }, De = { class: "sub-title" }, Be = { class: "right" }, Ee = { href: "javascript:;" }, Me = ["onClick"], ze = { class: "cont" }, Fe = { class: "name" }, Ge = { class: "job" }, Re = {
  key: 0,
  class: "not-more"
}, Je = { class: "item right-wrap" }, Ke = { class: "head" }, Pe = { class: "sub-title" }, Qe = { class: "cont" }, qe = { class: "name" }, xe = { class: "job" }, He = ["onClick"], el = {
  __name: "SOfficeSelect",
  props: {
    ids: {
      type: [String, Array],
      default() {
        return "";
      }
    },
    placeholder: {
      type: String,
      default() {
        return window.$l("请选择");
      }
    },
    // 弹窗标题
    title: {
      type: String,
      default() {
        return window.$l("岗位选择");
      }
    }
  },
  emits: ["change"],
  setup($, { emit: D }) {
    const f = D, B = $, g = i(null), C = i(""), N = i(""), _ = i(""), o = i(!1), h = i(!1), L = i({}), m = i([]), s = i([]), w = i(1), V = i(0), b = i(!1);
    let T = null;
    const O = i(""), r = i([]), j = i(1), F = i(20), E = i(0);
    he(
      () => B.ids,
      (e) => {
        e && e.length && (s.value = e);
      },
      { immediate: !0 }
    );
    const G = () => {
      h.value = !0;
    }, Q = () => {
      h.value = !1;
    }, y = (e = 1, l = 0) => U(this, null, function* () {
      if (o.value) {
        o.value = !1;
        return;
      }
      e === 1 && (r.value = []);
      let a = [];
      if (s.value.length < 100 ? (j.value = 1, E.value = 0, a = s.value) : a = s.value.slice(l * (F.value || 20), e * (F.value || 20)), !a.length || r.value.length && a.length >= s.value.length && a.length >= r.value.length)
        return;
      o.value = !0;
      const d = yield Oe(a);
      r.value = r.value.concat(d), x(), T = setTimeout(() => {
        o.value = !1, clearTimeout(T);
      }, 200);
    }), q = () => {
      if (!O.value) {
        window.$message.warning("请选择部门");
        return;
      }
      w.value = 1, m.value = [], M(O.value);
    }, x = () => {
      const l = r.value.filter((d) => s.value.includes(d.id)).map((d) => d.name), a = l.length - 1;
      C.value = l.slice(0, 1).join(",") + (a > 0 ? " +" + a : "");
    }, H = () => {
      m.value.forEach((e) => {
        if (s.value.includes(e.id)) {
          const l = s.value.indexOf(e.id);
          s.value.splice(l, 1);
        }
      }), y()();
    }, W = () => {
      b.value = !b.value, b.value ? Y() : H();
    }, X = () => U(this, null, function* () {
      if (!O.value) {
        window.$message.warning("请选择部门");
        return;
      }
      const e = {
        searchValue: _.value,
        unitid: O.value.join(",")
      }, l = yield fe(e), a = s.value.concat(l);
      s.value = Array.from(new Set(a)), y();
    }), Y = () => {
      m.value.forEach((e) => {
        s.value.includes(e.id) || s.value.push(e.id);
      }), y();
    }, Z = () => {
      b.value = !1, C.value = "", s.value = [], r.value = [];
    }, ee = () => {
      h.value = !1;
      const e = r.value.filter((p) => s.value.includes(p.id)), l = e.map((p) => p.name), a = l.length - 1, d = l.slice(0, 1).join(",") + (a > 0 ? " +" + a : ""), z = e.map((p) => p.id);
      f("change", d, l, z, e);
    }, le = (e, l) => {
      L.value = l.node, w.value = 1, V.value = 0, m.value = [], o.value = !0, O.value = e, M(e);
    }, M = (e) => U(this, null, function* () {
      const l = {
        pageNo: w.value,
        pageSize: 20,
        searchValue: _.value,
        unitid: e.join(","),
        containsChild: !0
      };
      o.value = !0;
      const a = yield ge(l);
      m.value = m.value.concat(a.list), V.value = a.pages, T = setTimeout(() => {
        o.value = !1, clearTimeout(T);
      }, 200);
    }), te = (e) => {
      s.value.includes(e.id) || s.value.push(e.id), y();
    }, ae = (e, l) => {
      r.value.splice(l, 1), s.value.splice(s.value.indexOf(e.id), 1), y();
    }, ne = ({ target: { offsetHeight: e, scrollHeight: l, scrollTop: a } }) => {
      o.value || e + a >= l - 20 && w.value <= V.value && (w.value++, M([L.value.id]));
    }, se = ({ target: { offsetHeight: e, scrollHeight: l, scrollTop: a } }) => {
      o.value || e + a >= l - 20 && (E.value = j.value, j.value++, y(j.value, E.value));
    }, oe = (e) => Ce(e), ie = (e) => we(e);
    return _e(() => {
      g.value = window.$theme;
    }), (e, l) => {
      const a = ye, d = ke, z = A("s-tree"), p = A("DownOutlined"), ue = Se, ce = $e, de = be, re = A("CloseCircleOutlined"), ve = A("s-modal");
      return k(), S("div", Ne, [
        c(a, {
          value: C.value,
          "onUpdate:value": l[0] || (l[0] = (n) => C.value = n),
          readonly: "",
          placeholder: $.placeholder,
          onClick: G,
          onSearch: G
        }, null, 8, ["value", "placeholder"]),
        c(ve, {
          value: h.value,
          "onUpdate:value": l[4] || (l[4] = (n) => h.value = n),
          title: $.title,
          width: "1000px",
          showFullScreen: !1
        }, {
          footer: v(() => [
            c(d, {
              key: "back",
              onClick: Q
            }, {
              default: v(() => [
                I(u(e.$l("取消")), 1)
              ]),
              _: 1
            }),
            c(d, {
              key: "submit",
              type: "primary",
              loading: o.value,
              onClick: ee
            }, {
              default: v(() => [
                I(u(e.$l("确认")), 1)
              ]),
              _: 1
            }, 8, ["loading"])
          ]),
          default: v(() => [
            t("div", Le, [
              t("div", Ve, [
                c(z, {
                  levelOneChildren: oe,
                  levelTwoChildren: ie,
                  "onSelect:modelValue": le,
                  select: N.value,
                  "onUpdate:select": l[1] || (l[1] = (n) => N.value = n),
                  height: 470
                }, null, 8, ["select"])
              ]),
              t("div", Te, [
                t("div", je, [
                  c(a, {
                    value: _.value,
                    "onUpdate:value": l[2] || (l[2] = (n) => _.value = n),
                    placeholder: e.$l("请输入"),
                    style: { width: "330px" },
                    onSearch: q
                  }, null, 8, ["value", "placeholder"])
                ]),
                t("div", Ue, [
                  t("div", Ae, [
                    t("div", Ie, [
                      t("div", De, u(L.value.title || L.value.name), 1),
                      t("div", Be, [
                        c(d, {
                          type: "link",
                          onClick: W
                        }, {
                          default: v(() => [
                            I(u(b.value ? e.$l("反选") : e.$l("全选")), 1)
                          ]),
                          _: 1
                        }),
                        c(de, null, {
                          overlay: v(() => [
                            c(ce, null, {
                              default: v(() => [
                                c(ue, { onClick: X }, {
                                  default: v(() => [
                                    t("a", Ee, u(e.$l("节点全选")), 1)
                                  ]),
                                  _: 1
                                })
                              ]),
                              _: 1
                            })
                          ]),
                          default: v(() => [
                            t("a", {
                              type: "link",
                              onClick: l[3] || (l[3] = me(() => {
                              }, ["prevent"]))
                            }, [
                              c(p)
                            ])
                          ]),
                          _: 1
                        })
                      ])
                    ]),
                    t("div", {
                      class: "user-list",
                      onScroll: ne
                    }, [
                      (k(!0), S(J, null, K(m.value, (n) => (k(), S("div", {
                        class: "item",
                        key: n.id,
                        onClick: (R) => te(n)
                      }, [
                        t("div", {
                          class: "icon",
                          style: P({ backgroundColor: g.value.borderColor })
                        }, u(n.name && n.name.slice(0, 1)), 5),
                        t("div", ze, [
                          t("div", Fe, u(n.name) + " (" + u(n.nameOrCount) + ")", 1),
                          t("div", Ge, u(n.deptName), 1)
                        ])
                      ], 8, Me))), 128)),
                      w.value >= V.value ? (k(), S("div", Re, u(e.$l("没有更多了")), 1)) : pe("", !0)
                    ], 32)
                  ]),
                  t("div", Je, [
                    t("div", Ke, [
                      t("div", Pe, u(e.$l("本次已选")), 1),
                      c(d, {
                        type: "link",
                        onClick: Z
                      }, {
                        default: v(() => [
                          I(u(e.$l("清除")), 1)
                        ]),
                        _: 1
                      })
                    ]),
                    t("div", {
                      class: "user-list select-list",
                      onScroll: se
                    }, [
                      (k(!0), S(J, null, K(r.value, (n, R) => (k(), S("div", {
                        class: "item",
                        key: n.id
                      }, [
                        t("div", {
                          class: "icon",
                          style: P({ backgroundColor: g.value.borderColor })
                        }, u(n.name && n.name.slice(0, 1)), 5),
                        t("div", Qe, [
                          t("div", qe, u(n.name) + " (" + u(n.nameOrCount) + ")", 1),
                          t("div", xe, u(n.deptName), 1)
                        ]),
                        t("div", {
                          class: "icon no-bg",
                          onClick: (We) => ae(n, R)
                        }, [
                          c(re)
                        ], 8, He)
                      ]))), 128))
                    ], 32)
                  ])
                ])
              ])
            ])
          ]),
          _: 1
        }, 8, ["value", "title"])
      ]);
    };
  }
};
export {
  el as default
};
