import { n as e } from "./chunk-TYymryXo.mjs";
import { t } from "./bpMliuchengfenleikongzhiqi-BXcBcxU0.mjs";
import { Fragment as n, createBlock as r, createCommentVNode as i, createElementBlock as a, createElementVNode as o, createTextVNode as s, createVNode as c, defineComponent as l, nextTick as u, onMounted as d, openBlock as f, ref as p, renderList as m, toDisplayString as h, unref as g, useModel as _, watch as v, withCtx as y } from "vue";
import { useRoute as b } from "vue-router";
import { Button as x, Form as S, FormItem as ee, Input as C, Radio as w, RadioGroup as T, Select as E, Tag as D, Textarea as O, Tooltip as k } from "ant-design-vue/es";
import { ExclamationCircleOutlined as A } from "@ant-design/icons-vue";
import { selectOrg as j, selectUser as M } from "@pubinfo/module-rbac";
//#region src/pages/flow-create/flow-model/createComponents/step1.vue?vue&type=script&setup=true&lang.ts
var N = {
	key: 0,
	"mt-10px": ""
}, P = {
	key: 1,
	"mt-10px": ""
}, F = /* @__PURE__ */ l({
	name: "CreateStep1",
	__name: "step1",
	props: {
		modelValue: {},
		modelModifiers: {}
	},
	emits: ["update:modelValue"],
	setup(e, { expose: l }) {
		let F = b(), I = p("create"), L = p(), R = _(e, "modelValue"), z = {
			name: [{
				required: !0,
				message: "请输入流程名称",
				trigger: ["change", "blur"]
			}],
			key: [{
				required: !0,
				validator: B,
				trigger: ["change", "blur"]
			}],
			category: [{
				required: !0,
				message: "请选择流程分类",
				trigger: "change"
			}],
			type: [{
				required: !0,
				message: "请选择流程类型",
				trigger: "change"
			}],
			visible: [{
				required: !0,
				message: "请选择是否可见",
				trigger: "change"
			}],
			managerUserIds: [{
				type: "array",
				required: !0,
				validator: V,
				trigger: ["change", "blur"]
			}]
		};
		async function B(e, t) {
			return t ? /^[a-z][a-z0-9-]{0,29}$/i.test(t) ? Promise.resolve() : Promise.reject(/* @__PURE__ */ Error("流程标识只能包含字母、数字、-，必须以字母开头，长度不超过30个字符")) : Promise.reject(/* @__PURE__ */ Error("请输入流程标识"));
		}
		async function V(e, t) {
			return !t || t.length === 0 ? Promise.reject(/* @__PURE__ */ Error("请选择流程管理员")) : Promise.resolve();
		}
		let H = p([]), U = [
			{
				label: "全员",
				value: 0
			},
			{
				label: "指定人员",
				value: 1
			},
			{
				label: "指定部门",
				value: 2
			}
		];
		function W() {
			t().then((e) => {
				e && e.data && (H.value = [], e.data.forEach((e) => {
					H.value.push({
						label: e.name,
						value: e.code
					});
				}));
			});
		}
		let G = p([]);
		v(() => R.value?.startUsers, (e) => {
			G.value = (e ?? []).map((e) => ({
				orgId: e.deptId ?? e.orgId ?? "",
				userId: e.id ?? e.userId ?? "",
				userName: e.nickname ?? e.userName ?? e.account ?? ""
			}));
		}, {
			immediate: !0,
			deep: !0
		});
		function K() {
			M({
				multiple: !0,
				modelValue: G.value,
				onSubmit: (e) => {
					G.value = e.map((e) => ({
						orgId: e.orgId,
						userId: e.userId,
						userName: e.userName
					}));
				}
			});
		}
		function q(e) {
			G.value = G.value.filter((t) => t.userId !== e.userId);
		}
		v(() => G.value, (e) => {
			R.value.startUserIds = e.map((e) => e.userId);
		}, { deep: !0 });
		let J = p([]);
		v(() => R.value?.startDepts, (e) => {
			J.value = (e ?? []).map((e) => ({
				orgId: e.id ?? e.orgId ?? "",
				orgName: e.name ?? e.orgName ?? ""
			}));
		}, {
			immediate: !0,
			deep: !0
		});
		function Y() {
			j({
				multiple: !0,
				modelValue: J.value,
				onSubmit: (e) => {
					J.value = e.map((e) => ({
						orgId: e.orgId,
						orgName: e.orgName
					}));
				}
			});
		}
		function X(e) {
			J.value = J.value.filter((t) => t.orgId !== e.orgId);
		}
		v(() => J.value, (e) => {
			R.value.startDeptIds = e.map((e) => e.orgId);
		}, { deep: !0 });
		let Z = p([]);
		v(() => R.value?.managerUsers, (e) => {
			Z.value = (e ?? []).map((e) => ({
				orgId: e.deptId ?? "",
				userId: e.id ?? "",
				userName: e.nickname ?? ""
			}));
		}, {
			immediate: !0,
			deep: !0
		});
		function Q() {
			M({
				multiple: !0,
				modelValue: Z.value,
				onSubmit: (e) => {
					Z.value = e.map((e) => ({
						orgId: e.orgId,
						userId: e.userId,
						userName: e.userName
					}));
				}
			});
		}
		function te(e) {
			Z.value = Z.value.filter((t) => t.userId !== e.userId);
		}
		v(() => Z.value, (e) => {
			R.value.managerUserIds = e.map((e) => e.userId), u(() => {
				L.value && typeof L.value.validateFields == "function" && L.value.validateFields(["managerUserIds"]).catch(() => {});
			});
		}, { deep: !0 });
		let $ = p(R.value?.name ?? "");
		v(() => R.value?.name, (e, t) => {
			let n = t ?? $.value;
			if (!n || e === n) {
				$.value = e ?? "";
				return;
			}
			let r = R.value?.bpmnXml;
			r && typeof r == "string" && n && (R.value.bpmnXml = r.replaceAll(n, e ?? "")), $.value = e ?? "";
		}, { deep: !1 }), d(() => {
			G.value = [], J.value = [], $.value = R.value?.name ?? "", F.params.id ? (I.value = F.params.type, R.value.startUserType === 1 ? G.value = (R.value.startUsers ?? []).map((e) => ({
				orgId: e.deptId,
				userId: e.id,
				userName: e.nickname
			})) : R.value.startUserType === 2 && (J.value = (R.value.startDepts ?? []).map((e) => ({
				orgId: e.id,
				orgName: e.name
			})))) : I.value = "create", W();
		});
		function ne() {
			return L.value.validate();
		}
		return l({ validateForm: ne }), (e, t) => {
			let l = A, u = k, d = C, p = ee, _ = E, v = O, b = w, j = T, M = D, F = x, B = S;
			return f(), r(B, {
				ref_key: "formRef",
				ref: L,
				model: R.value,
				rules: z,
				"label-col": { style: "width:120px" }
			}, {
				default: y(() => [
					c(p, { name: "key" }, {
						label: y(() => [t[8] ||= o("span", null, "流程标识\xA0", -1), c(u, null, {
							title: y(() => [...t[7] ||= [s(" 流程标识是流程的唯一标识，创建后不可修改，只能包含字母、数字、-，必须以字母开头，长度不超过30个字符。 ", -1)]]),
							default: y(() => [c(l)]),
							_: 1
						})]),
						default: y(() => [c(d, {
							value: R.value.key,
							"onUpdate:value": t[0] ||= (e) => R.value.key = e,
							maxlength: 30,
							placeholder: "请输入流程标识",
							disabled: g(I) === "edit"
						}, null, 8, ["value", "disabled"])]),
						_: 1
					}),
					c(p, {
						label: "流程名称",
						name: "name"
					}, {
						default: y(() => [c(d, {
							value: R.value.name,
							"onUpdate:value": t[1] ||= (e) => R.value.name = e,
							maxlength: 30,
							placeholder: "请输入流程名称"
						}, null, 8, ["value"])]),
						_: 1
					}),
					c(p, {
						label: "流程分类",
						name: "category"
					}, {
						default: y(() => [c(_, {
							value: R.value.category,
							"onUpdate:value": t[2] ||= (e) => R.value.category = e,
							options: g(H),
							placeholder: "请选择流程分类",
							"allow-clear": ""
						}, null, 8, ["value", "options"])]),
						_: 1
					}),
					c(p, {
						label: "流程描述",
						name: "description"
					}, {
						default: y(() => [c(v, {
							value: R.value.description,
							"onUpdate:value": t[3] ||= (e) => R.value.description = e,
							placeholder: "请输入流程描述",
							"allow-clear": ""
						}, null, 8, ["value"])]),
						_: 1
					}),
					c(p, {
						label: "流程类型",
						name: "type"
					}, {
						default: y(() => [c(j, {
							value: R.value.type,
							"onUpdate:value": t[4] ||= (e) => R.value.type = e,
							disabled: ""
						}, {
							default: y(() => [c(b, { value: 10 }, {
								default: y(() => [...t[9] ||= [s(" BPMN设计器 ", -1)]]),
								_: 1
							}), c(b, { value: 20 }, {
								default: y(() => [...t[10] ||= [s(" SIMPLE设计器 ", -1)]]),
								_: 1
							})]),
							_: 1
						}, 8, ["value"])]),
						_: 1
					}),
					c(p, {
						label: "是否可见",
						name: "visible"
					}, {
						default: y(() => [c(j, {
							value: R.value.visible,
							"onUpdate:value": t[5] ||= (e) => R.value.visible = e
						}, {
							default: y(() => [c(b, { value: !0 }, {
								default: y(() => [...t[11] ||= [s(" 是 ", -1)]]),
								_: 1
							}), c(b, { value: !1 }, {
								default: y(() => [...t[12] ||= [s(" 否 ", -1)]]),
								_: 1
							})]),
							_: 1
						}, 8, ["value"])]),
						_: 1
					}),
					c(p, {
						label: "谁可以发起",
						name: "startUserType"
					}, {
						default: y(() => [
							c(_, {
								value: R.value.startUserType,
								"onUpdate:value": t[6] ||= (e) => R.value.startUserType = e,
								options: U,
								placeholder: "请选择"
							}, null, 8, ["value"]),
							R.value.startUserType === 1 ? (f(), a("div", N, [(f(!0), a(n, null, m(g(G), (e, t) => (f(), r(M, {
								key: t,
								closable: "",
								onClose: (t) => q(e)
							}, {
								default: y(() => [s(h(e.userName), 1)]),
								_: 2
							}, 1032, ["onClose"]))), 128)), c(F, {
								size: "small",
								type: "primary",
								onClick: K
							}, {
								default: y(() => [...t[13] ||= [s(" 选择人员 ", -1)]]),
								_: 1
							})])) : i("", !0),
							R.value.startUserType === 2 ? (f(), a("div", P, [(f(!0), a(n, null, m(g(J), (e, t) => (f(), r(M, {
								key: t,
								closable: "",
								onClose: (t) => X(e)
							}, {
								default: y(() => [s(h(e.orgName), 1)]),
								_: 2
							}, 1032, ["onClose"]))), 128)), c(F, {
								size: "small",
								type: "primary",
								onClick: Y
							}, {
								default: y(() => [...t[14] ||= [s(" 选择部门 ", -1)]]),
								_: 1
							})])) : i("", !0)
						]),
						_: 1
					}),
					c(p, {
						label: "流程管理员",
						name: "managerUserIds"
					}, {
						default: y(() => [(f(!0), a(n, null, m(g(Z), (e, t) => (f(), r(M, {
							key: t,
							closable: "",
							onClose: (t) => te(e)
						}, {
							default: y(() => [s(h(e.userName), 1)]),
							_: 2
						}, 1032, ["onClose"]))), 128)), c(F, {
							size: "small",
							type: "primary",
							onClick: Q
						}, {
							default: y(() => [...t[15] ||= [s(" 选择人员 ", -1)]]),
							_: 1
						})]),
						_: 1
					})
				]),
				_: 1
			}, 8, ["model"]);
		};
	}
}), I = /* @__PURE__ */ e({ default: () => L }), L = F;
//#endregion
export { I as n, L as t };
