var R = (S, F, w) => new Promise((I, m) => { var M = (h) => { try { g(w.next(h)); } catch (y) { m(y); } }, T = (h) => { try { g(w.throw(h)); } catch (y) { m(y); } }, g = (h) => h.done ? I(h.value) : Promise.resolve(h.value).then(M, T); g((w = w.apply(S, F)).next()); }); import { ref as u, watch as Ce, onMounted as ke, resolveComponent as J, openBlock as d, createElementBlock as v, createVNode as f, withCtx as $, createElementVNode as s, toDisplayString as i, createTextVNode as b, createCommentVNode as te, Fragment as j, renderList as ae } from "vue"; import { aq as Se, B as we, da as se, d0 as $e, d1 as be, db as Ee } from "./index2.js"; const Ae = { class: "s-office-select-common" }, Le = { class: "modal-container" }, Ne = { class: "side" }, Ie = { class: "main" }, Te = { class: "filter" }, Ue = { class: "list-wrap" }, Ve = { class: "item left-wrap" }, Oe = { class: "head" }, Be = { class: "sub-title" }, qe = { key: 0, class: "right" }, Re = ["onClick"], je = { class: "icon s-theme-icon-bg" }, Fe = ["src", "onError"], Me = { class: "cont" }, Pe = { class: "name" }, xe = { class: "job" }, ze = { key: 0, class: "not-more" }, Je = { class: "item right-wrap" }, De = { class: "head" }, Ke = { class: "sub-title" }, Ge = { class: "icon s-theme-icon-bg" }, He = ["src", "onError"], Qe = { class: "cont" }, We = { class: "name" }, Xe = { class: "job" }, Ye = ["onClick"], tl = { __name: "SUserSelect", props: { value: { type: [String, Array], default() { return ""; } }, placeholder: { type: String, default() { return window.$l("请选择"); } }, // 弹窗标题 title: { type: String, default() { return window.$l("人员选择"); } }, // 是否多选,传 false 为单选(只保留最后选中的一个) multiple: { type: Boolean, default: !0 } }, emits: ["change", "update:value"], setup(S, { expose: F, emit: w }) { var ee, le; const I = w, m = S, M = (((le = (ee = window.$utils) == null ? void 0 : ee.env) == null ? void 0 : le.VITE_APP_API_FILE_URL) || "/") + "", T = (e) => /^https?:\/\//.test(e) ? e : `${M}file/preview?id=${e}`, g = u(""), h = u(""), y = u(""), p = u(!1), E = u(!1), U = u({}), C = u([]), n = u([]), k = u(1), A = u(0), L = u(!1); let V = null; const D = u(""), c = u([]), O = u(1), K = u(20), P = u(0); let G = 0, H = "", Q = !1; const W = (e) => { if (e && e.length) { const l = Array.isArray(e) ? e : [e]; n.value = m.multiple ? l : l.slice(0, 1); } else n.value = []; }; Ce( () => m.value, (e) => { W(e), Q && B(); }, { immediate: !0 } ); const X = () => { E.value = !0, B(); }, Y = () => { X(); }, ne = () => { E.value = !1, W(m.value), B(); }, N = (e = 1, l = 0) => R(this, null, function* () { if (p.value) { p.value = !1; return; } e === 1 && (c.value = []); let a = []; if (n.value.length < 100 ? (O.value = 1, P.value = 0, a = n.value) : a = n.value.slice(l * (K.value || 20), e * (K.value || 20)), !a.length || c.value.length && a.length >= n.value.length && a.length >= c.value.length) return; p.value = !0; const o = yield se(a), _ = c.value.concat(o || []); c.value = [...new Map(_.map((r) => [r.id, r])).values()], V = setTimeout(() => { p.value = !1, clearTimeout(V); }, 200); }), oe = () => { k.value = 1, A.value = 0, C.value = [], x(); }, Z = () => { const l = c.value.filter((o) => n.value.includes(o.id)).map((o) => o.name), a = l.length - 1; g.value = l.slice(0, 1).join(",") + (a > 0 ? " +" + a : ""); }, B = () => R(this, null, function* () { if (!n.value.length) { g.value = "", c.value = []; return; } const e = yield se(n.value); c.value = e || [], Z(); }); ke(() => { Q = !0, B(); }); const ue = () => { C.value.forEach((e) => { if (n.value.includes(e.id)) { const l = n.value.indexOf(e.id); n.value.splice(l, 1); } }), N(); }, ce = () => { L.value = !L.value, L.value ? ie() : ue(); }, ie = () => { C.value.forEach((e) => { n.value.includes(e.id) || n.value.push(e.id); }), N(); }, re = () => { L.value = !1, n.value = [], c.value = []; }, de = () => { E.value = !1; const e = c.value.filter((r) => n.value.includes(r.id)), l = e.map((r) => r.name), a = l.length - 1, o = l.slice(0, 1).join(",") + (a > 0 ? " +" + a : ""), _ = e.map((r) => r.id); I("update:value", m.multiple ? _ : _[0] || ""), I("change", o, l, _, e), Z(); }, ve = (e, l) => { var o; const a = Array.isArray(e) ? e : e ? [e] : []; a.length && (U.value = ((o = l == null ? void 0 : l.node) == null ? void 0 : o.dataRef) || (l == null ? void 0 : l.node) || {}, D.value = a, k.value = 1, A.value = 0, C.value = [], x()); }, x = () => R(this, null, function* () { const e = ++G, l = U.value || {}, a = `${(D.value || [])[0]}_${k.value}_${y.value}`; if (a === H && p.value) return; H = a; const o = { pageNum: k.value, pageSize: 20, searchValue: y.value, unitId: l.id, unitType: l.type, containsChild: !0, isEnabled: !0 }; p.value = !0; const _ = yield Ee(o); if (e !== G) return; const r = C.value.concat(_.list || []); C.value = [...new Map(r.map((q) => [q.id, q])).values()], A.value = _.pages, V = setTimeout(() => { p.value = !1, clearTimeout(V); }, 200); }), he = (e) => { if (!m.multiple) { n.value = [e.id], c.value = [e]; return; } n.value.includes(e.id) || n.value.push(e.id), N(); }, pe = (e, l) => { c.value.splice(l, 1), n.value.splice(n.value.indexOf(e.id), 1), N(); }, _e = ({ target: { offsetHeight: e, scrollHeight: l, scrollTop: a } }) => { p.value || e + a >= l - 20 && k.value < A.value && (k.value++, x()); }, fe = ({ target: { offsetHeight: e, scrollHeight: l, scrollTop: a } }) => { p.value || e + a >= l - 20 && (P.value = O.value, O.value++, N(O.value, P.value)); }, me = (e) => be(e), ge = (e) => $e(e); return F({ open: X }), (e, l) => { const a = Se, o = we, _ = J("s-tree"), r = J("CloseCircleOutlined"), q = J("s-modal"); return d(), v("div", Ae, [ f(a, { value: g.value, "onUpdate:value": l[0] || (l[0] = (t) => g.value = t), readonly: !0, placeholder: S.placeholder, onClick: Y, onSearch: Y }, null, 8, ["value", "placeholder"]), f(q, { value: E.value, "onUpdate:value": l[3] || (l[3] = (t) => E.value = t), title: S.title, width: "1000px", showFullScreen: !1 }, { footer: $(() => [ f(o, { key: "back", onClick: ne }, { default: $(() => [ b(i(e.$l("取消")), 1) ]), _: 1 }), f(o, { key: "submit", type: "primary", loading: p.value, onClick: de }, { default: $(() => [ b(i(e.$l("确认")), 1) ]), _: 1 }, 8, ["loading"]) ]), default: $(() => [ s("div", Le, [ s("div", Ne, [ f(_, { levelOneChildren: me, levelTwoChildren: ge, "onSelect:modelValue": ve, select: h.value, "onUpdate:select": l[1] || (l[1] = (t) => h.value = t), height: 470 }, null, 8, ["select"]) ]), s("div", Ie, [ s("div", Te, [ f(a, { value: y.value, "onUpdate:value": l[2] || (l[2] = (t) => y.value = t), placeholder: e.$l("请输入"), style: { width: "330px" }, onSearch: oe }, null, 8, ["value", "placeholder"]) ]), s("div", Ue, [ s("div", Ve, [ s("div", Oe, [ s("div", Be, i(U.value.title || U.value.name), 1), S.multiple ? (d(), v("div", qe, [ f(o, { type: "link", onClick: ce }, { default: $(() => [ b(i(L.value ? e.$l("反选") : e.$l("全选")), 1) ]), _: 1 }) ])) : te("", !0) ]), s("div", { class: "user-list", onScroll: _e }, [ (d(!0), v(j, null, ae(C.value, (t) => (d(), v("div", { class: "item", key: t.id, onClick: (z) => he(t) }, [ s("div", je, [ t.avatar || t.cover ? (d(), v("img", { key: 0, class: "avatar-img", src: T(t.avatar || t.cover), alt: "", onError: (z) => t.cover = "" }, null, 40, Fe)) : (d(), v(j, { key: 1 }, [ b(i(t.name && t.name.slice(0, 1)), 1) ], 64)) ]), s("div", Me, [ s("div", Pe, i(t.name + (t.userid || t.loginName ? "(" + (t.userid || t.loginName) + ")" : "")), 1), s("div", xe, i(t.mainJobName), 1) ]) ], 8, Re))), 128)), k.value >= A.value ? (d(), v("div", ze, i(e.$l("没有更多了")), 1)) : te("", !0) ], 32) ]), s("div", Je, [ s("div", De, [ s("div", Ke, i(e.$l("本次已选")), 1), f(o, { type: "link", onClick: re }, { default: $(() => [ b(i(e.$l("清除")), 1) ]), _: 1 }) ]), s("div", { class: "user-list select-list", onScroll: fe }, [ (d(!0), v(j, null, ae(c.value, (t, z) => (d(), v("div", { class: "item", key: t.id }, [ s("div", Ge, [ t.avatar || t.cover ? (d(), v("img", { key: 0, class: "avatar-img", src: T(t.avatar || t.cover), alt: "", onError: (ye) => t.cover = "" }, null, 40, He)) : (d(), v(j, { key: 1 }, [ b(i(t.name && t.name.slice(0, 1)), 1) ], 64)) ]), s("div", Qe, [ s("div", We, i(t.name || t.title), 1), s("div", Xe, i(t.mainJobName), 1) ]), s("div", { class: "icon no-bg", onClick: (ye) => pe(t, z) }, [ f(r) ], 8, Ye) ]))), 128)) ], 32) ]) ]) ]) ]) ]), _: 1 }, 8, ["value", "title"]) ]); }; } }; export { tl as default };