| | |
| | | }); |
| | | } |
| | | |
| | | /** 从模板字段中找到申请人字段 */ |
| | | function findApplicantField(fields) { |
| | | if (!Array.isArray(fields)) return null; |
| | | return ( |
| | | fields.find((f) => String(f?.label || "").includes("申请人")) || |
| | | fields.find((f) => f?.type === "select" && f?.optionSource === "user") || |
| | | null |
| | | ); |
| | | } |
| | | |
| | | /** 从 formPayload 的申请人字段解析 applicantId / applicantName */ |
| | | function resolveApplicantFromFormPayload(payload, fields) { |
| | | const field = findApplicantField(fields); |
| | | if (!field) return {}; |
| | | const val = payload?.[field.key]; |
| | | if (val == null || val === "") return {}; |
| | | const result = { applicantId: val }; |
| | | const opts = field.options; |
| | | if (Array.isArray(opts) && opts.length) { |
| | | const hit = opts.find((o) => String(o.value) === String(val)); |
| | | if (hit?.label) result.applicantName = hit.label; |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** 组装保存/更新审批 DTO */ |
| | | export function buildInstanceDto({ submitForm, activeTemplate, userStore, flowNodes, existingRow }) { |
| | | const payload = submitForm?.formPayload || {}; |
| | | const tpl = activeTemplate || {}; |
| | | const fields = tpl.fields || submitForm?.formFieldDefs || []; |
| | | const title = |
| | | String(payload.summary || payload.title || "").trim() || |
| | | tpl.label || |
| | |
| | | templateId, |
| | | }); |
| | | const isUpdate = Boolean(instanceId); |
| | | const fromPayload = resolveApplicantFromFormPayload(payload, fields); |
| | | |
| | | const dto = { |
| | | templateId, |
| | |
| | | } else { |
| | | dto.status = submitForm?.saveStatusApi || "PENDING"; |
| | | dto.currentLevel = 1; |
| | | dto.applicantId = userStore?.id; |
| | | dto.applicantName = userStore?.nickName || userStore?.name || ""; |
| | | dto.applicantId = fromPayload.applicantId || submitForm?.applicantId || userStore?.id; |
| | | dto.applicantName = fromPayload.applicantName || submitForm?.applicantName |
| | | || (fromPayload.applicantId ? "" : (userStore?.nickName || userStore?.name || "")); |
| | | } |
| | | return dto; |
| | | } |
| | |
| | | approvalRecords, |
| | | rejectReason: |
| | | approvalRecords.find((r) => r.result === "rejected")?.opinion || "", |
| | | storageBlobVOList: row.storageBlobVOList || row.storageBlobDTOs || row.attachmentList || [], |
| | | }; |
| | | } |
| | | |