var j = ($, D, f) => new Promise((z, g) => {
  var C = (o) => {
    try {
      _(f.next(o));
    } catch (h) {
      g(h);
    }
  }, O = (o) => {
    try {
      _(f.throw(o));
    } catch (h) {
      g(h);
    }
  }, _ = (o) => o.done ? z(o.value) : Promise.resolve(o.value).then(C, O);
  _((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 P, renderList as Q, normalizeStyle as R, createCommentVNode as pe } from "vue";
import { cc as fe, cd as ge, aM as Ce, aN as we, aO as ye, U as ke, aP as Se, aG as $e, aQ as be, ce as Ne } from "./index2.js";
const Oe = { class: "s-office-select-common" }, Ue = { class: "modal-container" }, Ve = { class: "side" }, Le = { class: "main" }, Te = { class: "filter" }, je = { class: "list-wrap" }, Ae = { class: "item left-wrap" }, Ie = { class: "head" }, De = { class: "sub-title" }, ze = { class: "right" }, Be = { href: "javascript:;" }, Ee = ["onClick"], Me = { class: "cont" }, Fe = { class: "name" }, Je = { class: "job" }, Ge = {
  key: 0,
  class: "not-more"
}, Pe = { class: "item right-wrap" }, Qe = { class: "head" }, Re = { class: "sub-title" }, qe = { class: "cont" }, xe = { class: "name" }, He = { class: "job" }, Ke = ["onClick"], el = {
  __name: "SUserSelect",
  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, z = $, g = i(null), C = i(""), O = i(""), _ = i(""), o = i(!1), h = i(!1), U = i({}), m = i([]), s = i([]), w = i(1), V = i(0), b = i(!1);
    let L = null;
    const N = i(""), r = i([]), T = i(1), F = i(20), B = i(0);
    he(
      () => z.ids,
      (e) => {
        e && e.length && (s.value = e);
      },
      { immediate: !0 }
    );
    const J = () => {
      h.value = !0;
    }, q = () => {
      h.value = !1;
    }, y = (e = 1, l = 0) => j(this, null, function* () {
      if (o.value) {
        o.value = !1;
        return;
      }
      e === 1 && (r.value = []);
      let a = [];
      if (s.value.length < 100 ? (T.value = 1, B.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 Ne(a);
      r.value = r.value.concat(d), H(), L = setTimeout(() => {
        o.value = !1, clearTimeout(L);
      }, 200);
    }), x = () => {
      if (!N.value) {
        window.$message.warning("请选择部门");
        return;
      }
      w.value = 1, m.value = [], E(N.value);
    }, H = () => {
      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 : "");
    }, K = () => {
      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() : K();
    }, X = () => j(this, null, function* () {
      if (!N.value) {
        window.$message.warning("请选择部门");
        return;
      }
      const e = {
        searchValue: _.value,
        unitid: N.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 : ""), M = e.map((p) => p.id);
      f("change", d, l, M, e);
    }, le = (e, l) => {
      U.value = l.node, w.value = 1, V.value = 0, m.value = [], o.value = !0, N.value = e, E(e);
    }, E = (e) => j(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, L = setTimeout(() => {
        o.value = !1, clearTimeout(L);
      }, 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++, E([U.value.id]));
    }, se = ({ target: { offsetHeight: e, scrollHeight: l, scrollTop: a } }) => {
      o.value || e + a >= l - 20 && (B.value = T.value, T.value++, y(T.value, B.value));
    }, oe = (e) => Ce(e), ie = (e) => we(e);
    return _e(() => {
      g.value = window.$theme;
    }), (e, l) => {
      const a = ye, d = ke, M = A("s-tree"), p = A("DownOutlined"), ue = Se, ce = $e, de = be, re = A("CloseCircleOutlined"), ve = A("s-modal");
      return k(), S("div", Oe, [
        c(a, {
          value: C.value,
          "onUpdate:value": l[0] || (l[0] = (n) => C.value = n),
          readonly: "",
          placeholder: $.placeholder,
          onClick: J,
          onSearch: J
        }, 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", Ue, [
              t("div", Ve, [
                c(M, {
                  levelOneChildren: oe,
                  levelTwoChildren: ie,
                  "onSelect:modelValue": le,
                  select: O.value,
                  "onUpdate:select": l[1] || (l[1] = (n) => O.value = n),
                  height: 470
                }, null, 8, ["select"])
              ]),
              t("div", Le, [
                t("div", Te, [
                  c(a, {
                    value: _.value,
                    "onUpdate:value": l[2] || (l[2] = (n) => _.value = n),
                    placeholder: e.$l("请输入"),
                    style: { width: "330px" },
                    onSearch: x
                  }, null, 8, ["value", "placeholder"])
                ]),
                t("div", je, [
                  t("div", Ae, [
                    t("div", Ie, [
                      t("div", De, u(U.value.title || U.value.name), 1),
                      t("div", ze, [
                        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", Be, 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(P, null, Q(m.value, (n) => (k(), S("div", {
                        class: "item",
                        key: n.id,
                        onClick: (G) => te(n)
                      }, [
                        t("div", {
                          class: "icon",
                          style: R({ backgroundColor: g.value.borderColor })
                        }, u(n.name && n.name.slice(0, 1)), 5),
                        t("div", Me, [
                          t("div", Fe, u(n.name) + "(" + u(n.userid) + ")", 1),
                          t("div", Je, u(n.mainJobName), 1)
                        ])
                      ], 8, Ee))), 128)),
                      w.value >= V.value ? (k(), S("div", Ge, u(e.$l("没有更多了")), 1)) : pe("", !0)
                    ], 32)
                  ]),
                  t("div", Pe, [
                    t("div", Qe, [
                      t("div", Re, 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(P, null, Q(r.value, (n, G) => (k(), S("div", {
                        class: "item",
                        key: n.id
                      }, [
                        t("div", {
                          class: "icon",
                          style: R({ backgroundColor: g.value.borderColor })
                        }, u(n.name && n.name.slice(0, 1)), 5),
                        t("div", qe, [
                          t("div", xe, u(n.title), 1),
                          t("div", He, u(n.mainJobName), 1)
                        ]),
                        t("div", {
                          class: "icon no-bg",
                          onClick: (We) => ae(n, G)
                        }, [
                          c(re)
                        ], 8, Ke)
                      ]))), 128))
                    ], 32)
                  ])
                ])
              ])
            ])
          ]),
          _: 1
        }, 8, ["value", "title"])
      ]);
    };
  }
};
export {
  el as default
};
