From 0a58164ce2ea3f1a2b46781757d78b94b212883b Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期三, 20 五月 2026 15:13:49 +0800
Subject: [PATCH] 工作交接/调岗申请/转正申请/请假申请/加班申请新增调用模板
---
src/views/officeProcessAutomation/AttendManage/overtime-apply/index.vue | 670 +++++++++++++++++++++++++++++--------------------------
1 files changed, 353 insertions(+), 317 deletions(-)
diff --git a/src/views/officeProcessAutomation/AttendManage/overtime-apply/index.vue b/src/views/officeProcessAutomation/AttendManage/overtime-apply/index.vue
index a58764f..b04a9cd 100644
--- a/src/views/officeProcessAutomation/AttendManage/overtime-apply/index.vue
+++ b/src/views/officeProcessAutomation/AttendManage/overtime-apply/index.vue
@@ -22,7 +22,7 @@
<div class="search_actions">
<el-button type="success" plain @click="handleImportClick">瀵煎叆</el-button>
<el-button type="warning" plain @click="handleExport">瀵煎嚭</el-button>
- <el-button type="primary" @click="openFormDialog('add')">鏂板鍔犵彮鐢宠</el-button>
+ <el-button type="primary" @click="openAddWithTemplate">鏂板鍔犵彮鐢宠</el-button>
</div>
</div>
<input ref="importInputRef" type="file" accept="application/json,.json" class="sr-only-input" @change="onImportFile" />
@@ -42,133 +42,51 @@
<!-- 鏂板 / 缂栬緫 -->
<el-dialog
+ v-if="formDialog.visible"
v-model="formDialog.visible"
:title="formDialog.title"
- width="1040px"
+ width="960px"
append-to-body
destroy-on-close
class="overtime-apply-form-dialog"
@closed="onFormClosed"
>
<el-form ref="formRef" :model="form" :rules="formRules" label-width="140px" class="overtime-apply-form">
- <el-row :gutter="24">
- <el-col :span="24">
- <el-form-item label="鐢宠浜�" prop="applicantId">
- <el-select
- v-model="form.applicantId"
- filterable
- remote
- clearable
- reserve-keyword
- placeholder="璇烽�夋嫨鎴栨悳绱㈢敵璇蜂汉"
- style="width: 100%"
- :remote-method="remoteSearchApplicantForm"
- :loading="applicantFormSearchLoading"
- @change="onApplicantChange"
- >
- <el-option
- v-for="u in applicantFormOptions"
- :key="u.userId"
- :label="userSelectLabel(u)"
- :value="u.userId"
- />
- </el-select>
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :gutter="24">
- <el-col :span="12">
- <el-form-item label="鍔犵彮绫诲瀷" prop="overtimeType">
- <el-select v-model="form.overtimeType" placeholder="璇烽�夋嫨鍔犵彮绫诲瀷" clearable filterable style="width: 100%">
- <el-option v-for="opt in OVERTIME_TYPE_OPTIONS" :key="opt.value" :label="opt.label" :value="opt.value" />
- </el-select>
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="鍔犵彮鏃ユ湡" prop="overtimeDate">
- <el-date-picker
- v-model="form.overtimeDate"
- type="date"
- placeholder="璇烽�夋嫨鍔犵彮鏃ユ湡"
- format="YYYY-MM-DD"
- value-format="YYYY-MM-DD"
- style="width: 100%"
- />
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :gutter="24">
- <el-col :span="12">
- <el-form-item label="鍔犵彮寮�濮嬫棩鏈�" prop="overtimeStartTime">
- <el-date-picker
- v-model="form.overtimeStartTime"
- type="datetime"
- placeholder="璇烽�夋嫨寮�濮嬫椂闂�"
- format="YYYY-MM-DD HH:mm:ss"
- value-format="YYYY-MM-DD HH:mm:ss"
- style="width: 100%"
- @change="onOvertimeRangeChange"
- />
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="鍔犵彮缁撴潫鏃ユ湡" prop="overtimeEndTime">
- <el-date-picker
- v-model="form.overtimeEndTime"
- type="datetime"
- placeholder="璇烽�夋嫨缁撴潫鏃堕棿"
- format="YYYY-MM-DD HH:mm:ss"
- value-format="YYYY-MM-DD HH:mm:ss"
- style="width: 100%"
- @change="onOvertimeRangeChange"
- />
- </el-form-item>
- </el-col>
- </el-row>
+ <el-form-item v-if="form.templateSnapshot" label="瀹℃壒妯℃澘">
+ <span class="template-name">{{ form.templateSnapshot.label || form.templateName }}</span>
+ <el-button
+ v-if="formDialog.mode === 'add'"
+ type="primary"
+ link
+ class="ml12"
+ @click="reopenTemplateBind"
+ >
+ 鏇存崲妯℃澘
+ </el-button>
+ </el-form-item>
+
+ <FormPayloadFields :fields="templateDisplayFields" :form-payload="form.formPayload" />
<el-row :gutter="24">
<el-col :span="12">
<el-form-item label="鍔犵彮鏃堕暱">
- <el-input :model-value="overtimeHoursDisplay" readonly placeholder="鏍规嵁璧锋鏃堕棿鑷姩璁$畻">
+ <el-input :model-value="overtimeHoursDisplay" readonly placeholder="鏍规嵁妯℃澘涓姞鐝椂闂磋嚜鍔ㄨ绠�">
<template #append>灏忔椂</template>
</el-input>
</el-form-item>
</el-col>
</el-row>
- <el-row :gutter="24">
- <el-col :span="24">
- <el-form-item label="瀹℃壒娴佺▼" prop="approvalFlowNodes">
- <ApprovalFlowEditor
- v-model="form.approvalFlowNodes"
- :user-options="flowUserOptions"
- @update:model-value="onApprovalFlowChange"
- />
- <p class="flow-tip">鑷冲皯淇濈暀涓�涓妭鐐癸紱姣忎釜鑺傜偣閫夋嫨涓�鍚嶅鎵逛汉锛涘彲鏂板銆佸垹闄ゆ垨璋冩暣椤哄簭銆�</p>
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :gutter="24">
- <el-col :span="24">
- <el-form-item label="鍔犵彮浜嬬敱" prop="overtimeReason">
- <el-input
- v-model="form.overtimeReason"
- type="textarea"
- :rows="4"
- placeholder="璇峰~鍐欏姞鐝簨鐢�"
- maxlength="2000"
- show-word-limit
- />
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :gutter="24">
- <el-col :span="24">
- <el-form-item label="闄勪欢">
- <div class="upload-block">
- <FileUpload v-model:file-list="form.attachmentList" :limit="10" button-text="鐐瑰嚮閫夋嫨鏂囦欢" />
- </div>
- </el-form-item>
- </el-col>
- </el-row>
+ <ApprovalTemplateFormSection
+ :active-template="form.templateSnapshot"
+ :fields="form.formFieldDefs"
+ :form-payload="form.formPayload"
+ v-model:flow-nodes="form.flowNodes"
+ v-model:attachments="form.storageBlobDTOs"
+ :template-attachments="form.templateAttachments"
+ :user-options="flowUserOptions"
+ flow-attachments-only
+ hide-template-name
+ :allow-change-template="false"
+ />
</el-form>
<template #footer>
<div class="dialog-footer">
@@ -177,6 +95,14 @@
</div>
</template>
</el-dialog>
+
+ <ApprovalTemplateBindDialog
+ v-model:visible="templateBindVisible"
+ :module-key="APPROVAL_MODULE_KEYS.OVERTIME"
+ skip-form-confirm
+ @confirm="onTemplateBound"
+ @closed="onTemplateBindClosed"
+ />
<!-- 璇︽儏 -->
<el-dialog v-model="detailDialog.visible" title="鍔犵彮鐢宠璇︽儏" width="720px" append-to-body>
@@ -190,11 +116,11 @@
<el-descriptions-item label="鍔犵彮鏃堕暱">{{ formatHours(detailRow.overtimeHours) }}</el-descriptions-item>
<el-descriptions-item label="鍔犵彮浜嬬敱">{{ detailRow.overtimeReason }}</el-descriptions-item>
<el-descriptions-item label="瀹℃壒娴佺▼">
- <template v-if="sortedApprovalNodes(detailRow).length">
+ <template v-if="detailFlowSteps(detailRow).length">
<div class="detail-flow-chain">
- <template v-for="(n, i) in sortedApprovalNodes(detailRow)" :key="i">
- <span class="detail-flow-step">{{ i + 1 }}. {{ approvalNodeLabel(n) }}</span>
- <span v-if="i < sortedApprovalNodes(detailRow).length - 1" class="detail-flow-sep">鈫�</span>
+ <template v-for="(step, i) in detailFlowSteps(detailRow)" :key="i">
+ <span class="detail-flow-step">{{ step }}</span>
+ <span v-if="i < detailFlowSteps(detailRow).length - 1" class="detail-flow-sep">鈫�</span>
</template>
</div>
</template>
@@ -203,8 +129,8 @@
<el-descriptions-item label="瀹℃壒缁撴灉">{{ approvalResultLabel(detailRow.approvalResult) }}</el-descriptions-item>
<el-descriptions-item label="鍒涘缓鏃堕棿">{{ detailRow.createTime || "鈥�" }}</el-descriptions-item>
<el-descriptions-item label="闄勪欢">
- <template v-if="detailRow.attachmentList?.length">
- <el-tag v-for="(f, i) in detailRow.attachmentList" :key="i" class="mr6 mb6" type="info">
+ <template v-if="rowAttachmentList(detailRow).length">
+ <el-tag v-for="(f, i) in rowAttachmentList(detailRow)" :key="i" class="mr6 mb6" type="info">
{{ f.name }}
</el-tag>
</template>
@@ -220,7 +146,7 @@
<!-- 闄勪欢鍒楄〃 -->
<el-dialog v-model="filesDialog.visible" title="闄勪欢" width="520px" append-to-body>
- <el-table v-if="filesDialog.row?.attachmentList?.length" :data="filesDialog.row.attachmentList" border>
+ <el-table v-if="rowAttachmentList(filesDialog.row).length" :data="rowAttachmentList(filesDialog.row)" border>
<el-table-column type="index" label="搴忓彿" width="60" align="center" />
<el-table-column prop="name" label="鏂囦欢鍚�" min-width="200" show-overflow-tooltip />
<el-table-column label="鎿嶄綔" width="100" align="center">
@@ -242,10 +168,20 @@
<script setup>
import { Search } from "@element-plus/icons-vue";
import dayjs from "dayjs";
-import FileUpload from "@/components/AttachmentUpload/file/index.vue";
-import ApprovalFlowEditor from "./components/ApprovalFlowEditor.vue";
import { userListNoPageByTenantId } from "@/api/system/user.js";
-import { computed, getCurrentInstance, nextTick, reactive, ref, watch } from "vue";
+import { computed, getCurrentInstance, nextTick, onMounted, reactive, ref, watch } from "vue";
+import ApprovalTemplateBindDialog from "../../ApproveManage/approve-shared/components/ApprovalTemplateBindDialog.vue";
+import ApprovalTemplateFormSection from "../../ApproveManage/approve-shared/components/ApprovalTemplateFormSection.vue";
+import FormPayloadFields from "../../ApproveManage/approve-list/components/FormPayloadFields.vue";
+import { APPROVAL_MODULE_KEYS } from "../../ApproveManage/approve-shared/approvalModuleRegistry.js";
+import {
+ applyBindingToForm,
+ attachmentDisplayName,
+ buildFormPayloadRules,
+ validateTemplateBinding,
+} from "../../ApproveManage/approve-shared/approvalTemplateBindingUtils.js";
+import { useFlowUserOptions } from "../../ApproveManage/approve-shared/useFlowUserOptions.js";
+import { SELECT_OPTION_SOURCE } from "../../ApproveManage/approve-template/selectOptionSource.js";
/** 鍔犵彮绫诲瀷锛坴alue 涓庡悗绔榻愬崰浣嶏級 */
const OVERTIME_TYPE_OPTIONS = [
@@ -253,26 +189,6 @@
{ label: "浼戞伅鏃ュ姞鐝�", value: "weekend" },
{ label: "娉曞畾鑺傚亣鏃ュ姞鐝�", value: "holiday" },
];
-
-/** 鏈湴婕旂ず锛氫袱鏉$┖鑺傜偣锛屾彁浜ゅ墠椤讳负姣忚妭鐐归�夋嫨瀹℃壒浜� */
-function demoApprovalFlowNodes() {
- return [
- { approverId: null, approverName: "", sortOrder: 1, nodeOrder: 1, roleName: "", roleCode: "" },
- { approverId: null, approverName: "", sortOrder: 2, nodeOrder: 2, roleName: "", roleCode: "" },
- ];
-}
-
-function sortedApprovalNodes(row) {
- const list = row?.approvalFlowNodes;
- if (!Array.isArray(list) || !list.length) return [];
- return [...list].sort((a, b) => (a.sortOrder ?? a.nodeOrder ?? 0) - (b.sortOrder ?? b.nodeOrder ?? 0));
-}
-
-function approvalNodeLabel(n) {
- const name = (n.approverName || "").trim();
- if (name) return name;
- return "鏈�夋嫨瀹℃壒浜�";
-}
function overtimeTypeLabel(v) {
const hit = OVERTIME_TYPE_OPTIONS.find((x) => x.value === v);
@@ -288,11 +204,17 @@
overtimeDate: "",
overtimeStartTime: "",
overtimeEndTime: "",
+ overtimeHours: null,
overtimeReason: "",
- attachmentList: [],
- approvalFlowNodes: [
- { approverId: null, approverName: "", sortOrder: 1, nodeOrder: 1, roleName: "", roleCode: "" },
- ],
+ hasTemplateBinding: false,
+ templateId: "",
+ templateName: "",
+ templateSnapshot: null,
+ formFieldDefs: [],
+ formPayload: {},
+ flowNodes: [],
+ templateAttachments: [],
+ storageBlobDTOs: [],
});
const { proxy } = getCurrentInstance();
@@ -302,52 +224,6 @@
if (payload && Array.isArray(payload.data)) return payload.data;
if (payload && Array.isArray(payload.rows)) return payload.rows;
return [];
-}
-
-function isActiveUser(u) {
- if (u.delFlag === "2" || u.delFlag === 2) return false;
- if (u.status == null) return true;
- return String(u.status) === "0";
-}
-
-function approvalResultLabel(v) {
- if (v === "approved") return "宸查�氳繃";
- if (v === "rejected") return "宸查┏鍥�";
- if (v === "cancelled") return "宸叉挙閿�";
- return "寰呭鎵�";
-}
-
-/** 鎸夎捣姝㈡椂闂磋绠楀姞鐝椂闀匡紙灏忔椂锛屼繚鐣欎袱浣嶅皬鏁帮級 */
-function computeOvertimeHours(startStr, endStr) {
- if (!startStr || !endStr) return null;
- const t0 = dayjs(startStr);
- const t1 = dayjs(endStr);
- if (!t0.isValid() || !t1.isValid() || !t1.isAfter(t0)) return null;
- const hours = t1.diff(t0, "millisecond") / (60 * 60 * 1000);
- return Math.round(hours * 100) / 100;
-}
-
-function formatHours(v) {
- if (v == null || v === "") return "鈥�";
- return `${v} 灏忔椂`;
-}
-
-const allUsersCache = ref([]);
-
-async function loadUserPool() {
- try {
- const res = await userListNoPageByTenantId();
- allUsersCache.value = unwrapArray(res);
- } catch {
- allUsersCache.value = [];
- }
-}
-
-function userSelectLabel(u) {
- const nick = u.nickName || "";
- const name = u.userName || "";
- if (nick && name && nick !== name) return `${nick}锛�${name}锛塦;
- return nick || name || `鐢ㄦ埛${u.userId ?? u.id ?? ""}`;
}
function userById(id) {
@@ -366,41 +242,120 @@
);
}
-function filterUsersByQuery(query) {
- const list = allUsersCache.value.filter((u) => isActiveUser(u));
- const q = (query || "").trim().toLowerCase();
- if (!q) return [...list];
- return list.filter((u) => {
- const nick = (u.nickName || "").toLowerCase();
- const uname = (u.userName || "").toLowerCase();
- const phone = (u.phonenumber || u.phone || "").toString();
- return nick.includes(q) || uname.includes(q) || phone.includes(q);
- });
+function isOvertimeHoursField(field) {
+ const label = String(field?.label || "");
+ return label.includes("鍔犵彮鏃堕暱") || field?.key === "overtimeHours";
}
-const applicantFormSearchLoading = ref(false);
-const applicantFormOptions = ref([]);
+function findOvertimeTimeTemplateField(fields = []) {
+ return (
+ fields.find((f) => f?.type === "datetimerange" && String(f?.label || "").includes("鍔犵彮鏃堕棿")) ||
+ fields.find((f) => f?.type === "datetimerange" && f?.key === "dateRange") ||
+ fields.find((f) => f?.type === "datetimerange") ||
+ null
+ );
+}
-async function remoteSearchApplicantForm(query) {
- applicantFormSearchLoading.value = true;
- try {
- if (!allUsersCache.value.length) {
- await loadUserPool();
- }
- applicantFormOptions.value = filterUsersByQuery(query);
- } finally {
- applicantFormSearchLoading.value = false;
+function findApplicantTemplateField(fields = []) {
+ return (
+ fields.find((f) => String(f?.label || "").includes("鐢宠浜�")) ||
+ fields.find((f) => f?.type === "select" && f?.optionSource === SELECT_OPTION_SOURCE.USER) ||
+ null
+ );
+}
+
+/** 浠庢ā鏉垮~鎶ラ」瑙f瀽鍔犵彮璧锋鏃堕棿 */
+function resolveOvertimeTimeRange(payload, overtimeTimeField) {
+ if (!overtimeTimeField?.key) return { start: "", end: "" };
+ const val = payload?.[overtimeTimeField.key];
+ if (!Array.isArray(val) || val.length < 2) return { start: "", end: "" };
+ return { start: val[0] || "", end: val[1] || "" };
+}
+
+/** 鎸夎捣姝㈡椂闂磋绠楀姞鐝椂闀匡紙灏忔椂锛屼繚鐣欎袱浣嶅皬鏁帮級 */
+function computeOvertimeHours(startStr, endStr) {
+ if (!startStr || !endStr) return null;
+ const t0 = dayjs(startStr);
+ const t1 = dayjs(endStr);
+ if (!t0.isValid() || !t1.isValid() || !t1.isAfter(t0)) return null;
+ const hours = t1.diff(t0, "millisecond") / (60 * 60 * 1000);
+ return Math.round(hours * 100) / 100;
+}
+
+function formatHours(v) {
+ if (v == null || v === "") return "鈥�";
+ return `${v} 灏忔椂`;
+}
+
+function mapStorageBlobsToAttachmentList(blobs) {
+ return (blobs || []).map((f) => ({
+ name: attachmentDisplayName(f),
+ url: f.url || f.downloadURL || f.previewURL || f.previewUrl,
+ }));
+}
+
+function rowAttachmentList(row) {
+ if (!row) return [];
+ if (row.attachmentList?.length) return row.attachmentList;
+ return mapStorageBlobsToAttachmentList(row.storageBlobDTOs);
+}
+
+function approvalResultLabel(v) {
+ if (v === "approved") return "宸查�氳繃";
+ if (v === "rejected") return "宸查┏鍥�";
+ if (v === "cancelled") return "宸叉挙閿�";
+ return "寰呭鎵�";
+}
+
+function sortedApprovalNodes(row) {
+ const list = row?.approvalFlowNodes;
+ if (!Array.isArray(list) || !list.length) return [];
+ return [...list].sort((a, b) => (a.sortOrder ?? a.nodeOrder ?? 0) - (b.sortOrder ?? b.nodeOrder ?? 0));
+}
+
+function approvalNodeLabel(n) {
+ const name = (n.approverName || "").trim();
+ return name || "鏈�夋嫨瀹℃壒浜�";
+}
+
+/** 璇︽儏瀹℃壒娴佺▼锛氫紭鍏堟ā鏉� flowNodes锛屽吋瀹规棫鐗� approvalFlowNodes */
+function detailFlowSteps(row) {
+ const nodes = row?.flowNodes;
+ if (Array.isArray(nodes) && nodes.length) {
+ return [...nodes]
+ .sort((a, b) => (a.nodeOrder ?? 0) - (b.nodeOrder ?? 0))
+ .map((n, i) => {
+ const names = (n.approvers || [])
+ .map((a) => (a.approverName || "").trim())
+ .filter(Boolean)
+ .join("銆�");
+ return `${i + 1}. ${names || "鏈�夋嫨瀹℃壒浜�"}`;
+ });
}
+ return sortedApprovalNodes(row).map((n, i) => `${i + 1}. ${approvalNodeLabel(n)}`);
}
-function onApplicantChange(uid) {
+function syncApplicantFromUser(uid) {
const u = userById(uid);
if (u) {
+ form.applicantId = uid != null && uid !== "" ? uid : "";
form.applicantName = u.nickName || u.userName || "";
form.applicantNo = applicantNoFromUser(u);
} else {
+ form.applicantId = "";
form.applicantName = "";
form.applicantNo = "";
+ }
+}
+
+const allUsersCache = ref([]);
+
+async function loadUserPool() {
+ try {
+ const res = await userListNoPageByTenantId();
+ allUsersCache.value = unwrapArray(res);
+ } catch {
+ allUsersCache.value = [];
}
}
@@ -511,77 +466,60 @@
});
const formRef = ref();
const form = reactive(createEmptyForm());
+const templateBindVisible = ref(false);
+const pendingTemplateBinding = ref(null);
+const { flowUserOptions, loadFlowUsers } = useFlowUserOptions();
-const flowUserOptions = computed(() => allUsersCache.value.filter((u) => isActiveUser(u)));
+const overtimeTimeTemplateField = computed(() => findOvertimeTimeTemplateField(form.formFieldDefs));
+const applicantTemplateField = computed(() => findApplicantTemplateField(form.formFieldDefs));
+
+const templateDisplayFields = computed(() =>
+ (form.formFieldDefs || []).filter((f) => !isOvertimeHoursField(f))
+);
const overtimeHoursDisplay = computed(() => {
- const h = computeOvertimeHours(form.overtimeStartTime, form.overtimeEndTime);
+ const { start, end } = resolveOvertimeTimeRange(form.formPayload, overtimeTimeTemplateField.value);
+ const h = computeOvertimeHours(start, end);
return h == null ? "" : String(h);
});
-function onOvertimeRangeChange() {
- nextTick(() => {
- formRef.value?.validateField?.("overtimeEndTime");
- });
-}
+const formRules = computed(() => buildFormPayloadRules(templateDisplayFields.value));
-function onApprovalFlowChange() {
- nextTick(() => formRef.value?.validateField?.("approvalFlowNodes"));
-}
+watch(
+ () => {
+ const key = applicantTemplateField.value?.key;
+ return key ? form.formPayload[key] : undefined;
+ },
+ async (uid) => {
+ if (!applicantTemplateField.value) return;
+ if (!allUsersCache.value.length) {
+ await loadUserPool();
+ }
+ syncApplicantFromUser(uid);
+ }
+);
-const formRules = {
- applicantId: [{ required: true, message: "璇烽�夋嫨鐢宠浜�", trigger: "change" }],
- overtimeType: [{ required: true, message: "璇烽�夋嫨鍔犵彮绫诲瀷", trigger: "change" }],
- overtimeDate: [{ required: true, message: "璇烽�夋嫨鍔犵彮鏃ユ湡", trigger: "change" }],
- overtimeStartTime: [{ required: true, message: "璇烽�夋嫨鍔犵彮寮�濮嬫椂闂�", trigger: "change" }],
- overtimeEndTime: [
- { required: true, message: "璇烽�夋嫨鍔犵彮缁撴潫鏃堕棿", trigger: "change" },
- {
- validator: (_rule, val, callback) => {
- if (!form.overtimeStartTime || !val) {
- callback();
- return;
- }
- const h = computeOvertimeHours(form.overtimeStartTime, val);
- if (h == null) {
- callback(new Error("缁撴潫鏃堕棿椤绘櫄浜庡紑濮嬫椂闂�"));
- } else {
- callback();
- }
- },
- trigger: "change",
- },
- ],
- overtimeReason: [{ required: true, message: "璇峰~鍐欏姞鐝簨鐢�", trigger: "blur" }],
- approvalFlowNodes: [
- {
- validator: (_rule, _val, callback) => {
- const nodes = form.approvalFlowNodes || [];
- if (!nodes.length) {
- callback(new Error("璇疯嚦灏戜繚鐣欎竴涓鎵硅妭鐐�"));
- return;
- }
- if (nodes.some((n) => n.approverId == null || n.approverId === "")) {
- callback(new Error("姣忎釜瀹℃壒鑺傜偣蹇呴』閫夋嫨涓�鍚嶅鎵逛汉"));
- return;
- }
- const ids = nodes.map((n) => String(n.approverId));
- if (new Set(ids).size !== ids.length) {
- callback(new Error("鍚屼竴瀹℃壒浜轰笉鑳介噸澶嶅嚭鐜板湪澶氫釜鑺傜偣"));
- return;
- }
- callback();
- },
- trigger: "change",
- },
- ],
-};
+watch(
+ () => {
+ const key = overtimeTimeTemplateField.value?.key;
+ return key ? form.formPayload[key] : undefined;
+ },
+ () => {
+ const { start, end } = resolveOvertimeTimeRange(form.formPayload, overtimeTimeTemplateField.value);
+ form.overtimeStartTime = start;
+ form.overtimeEndTime = end;
+ form.overtimeHours = computeOvertimeHours(start, end);
+ if (start) {
+ form.overtimeDate = dayjs(start).format("YYYY-MM-DD");
+ }
+ },
+ { deep: true }
+);
const detailDialog = reactive({ visible: false });
const detailRow = ref({});
const filesDialog = reactive({ visible: false, row: null });
-
const importInputRef = ref(null);
function handleQuery() {
@@ -655,6 +593,7 @@
overtimeEndTime: raw.overtimeEndTime ?? "",
overtimeHours: hours == null || Number.isNaN(hours) ? 0 : Math.round(hours * 100) / 100,
overtimeReason: raw.overtimeReason ?? "",
+ hasTemplateBinding: false,
approvalFlowNodes: Array.isArray(raw.approvalFlowNodes) && raw.approvalFlowNodes.length
? raw.approvalFlowNodes.map((n) => ({ ...n }))
: [],
@@ -695,12 +634,56 @@
reader.readAsText(file, "utf-8");
}
-async function openFormDialog(mode, row) {
- formDialog.mode = mode;
- formDialog.title = mode === "add" ? "鏂板鍔犵彮鐢宠" : "缂栬緫鍔犵彮鐢宠";
- if (!allUsersCache.value.length) {
- await loadUserPool();
+function openAddWithTemplate() {
+ formDialog.visible = false;
+ pendingTemplateBinding.value = null;
+ templateBindVisible.value = true;
+}
+
+function onTemplateBound(binding) {
+ pendingTemplateBinding.value = binding;
+}
+
+async function onTemplateBindClosed() {
+ const binding = pendingTemplateBinding.value;
+ if (!binding) return;
+ pendingTemplateBinding.value = null;
+ await openFormWithBinding(binding);
+}
+
+async function openFormWithBinding(binding) {
+ Object.assign(form, createEmptyForm());
+ applyBindingToForm(form, binding);
+ form.hasTemplateBinding = true;
+ formDialog.mode = "add";
+ formDialog.title = "鏂板鍔犵彮鐢宠";
+ await Promise.all([loadUserPool(), loadFlowUsers()]);
+ const applicantKey = applicantTemplateField.value?.key;
+ if (applicantKey && form.formPayload[applicantKey]) {
+ syncApplicantFromUser(form.formPayload[applicantKey]);
}
+ const { start, end } = resolveOvertimeTimeRange(form.formPayload, overtimeTimeTemplateField.value);
+ form.overtimeStartTime = start;
+ form.overtimeEndTime = end;
+ form.overtimeHours = computeOvertimeHours(start, end);
+ if (start) form.overtimeDate = dayjs(start).format("YYYY-MM-DD");
+ formDialog.visible = true;
+ nextTick(() => formRef.value?.clearValidate?.());
+}
+
+function reopenTemplateBind() {
+ formDialog.visible = false;
+ pendingTemplateBinding.value = null;
+ templateBindVisible.value = true;
+}
+
+async function openFormDialog(mode, row) {
+ if (mode === "edit" && row && !row.hasTemplateBinding) {
+ proxy?.$modal?.msgWarning?.("璇ヨ褰曚负鏃х増鏁版嵁锛岃閲嶆柊閫氳繃妯℃澘鍙戣捣鐢宠");
+ return;
+ }
+ formDialog.mode = mode;
+ formDialog.title = "缂栬緫鍔犵彮鐢宠";
Object.assign(form, createEmptyForm());
if (mode === "edit" && row) {
Object.assign(form, {
@@ -712,26 +695,24 @@
overtimeDate: row.overtimeDate,
overtimeStartTime: row.overtimeStartTime,
overtimeEndTime: row.overtimeEndTime,
+ overtimeHours: row.overtimeHours,
overtimeReason: row.overtimeReason,
- attachmentList: JSON.parse(JSON.stringify(row.attachmentList || [])),
- approvalFlowNodes: row.approvalFlowNodes?.length
- ? JSON.parse(JSON.stringify(row.approvalFlowNodes))
- : [],
+ hasTemplateBinding: true,
+ templateId: row.templateId,
+ templateName: row.templateName,
+ templateSnapshot: row.templateSnapshot,
+ formFieldDefs: row.formFieldDefs || [],
+ formPayload: JSON.parse(JSON.stringify(row.formPayload || {})),
+ flowNodes: JSON.parse(JSON.stringify(row.flowNodes || [])),
+ templateAttachments: JSON.parse(JSON.stringify(row.templateAttachments || [])),
+ storageBlobDTOs: JSON.parse(JSON.stringify(row.storageBlobDTOs || [])),
});
- const u = userById(row.applicantId);
- if (u) {
- applicantFormOptions.value = [u];
- } else if (row.applicantId) {
- applicantFormOptions.value = [
- {
- userId: row.applicantId,
- nickName: row.applicantName,
- userName: row.applicantNo,
- },
- ];
+ await loadUserPool();
+ const applicantKey = applicantTemplateField.value?.key;
+ if (applicantKey) {
+ syncApplicantFromUser(form.formPayload[applicantKey]);
}
- } else {
- remoteSearchApplicantForm("");
+ loadFlowUsers();
}
formDialog.visible = true;
nextTick(() => formRef.value?.clearValidate?.());
@@ -741,17 +722,71 @@
formRef.value?.resetFields?.();
}
+/** 浠庢ā鏉垮~鎶ラ」鍚屾鍒楄〃灞曠ず瀛楁 */
+function syncOvertimeFieldsFromPayload() {
+ const defs = form.formFieldDefs || [];
+ const payload = form.formPayload || {};
+ const overtimeTimeField = findOvertimeTimeTemplateField(defs);
+
+ for (const f of defs) {
+ const label = String(f.label || "");
+ const val = payload[f.key];
+
+ if (label.includes("鐢宠浜�") && !label.includes("鏃ユ湡") && !label.includes("鏃堕棿")) {
+ if (val != null && val !== "") {
+ form.applicantId = val;
+ const u = userById(val);
+ if (u) {
+ form.applicantName = u.nickName || u.userName || "";
+ form.applicantNo = applicantNoFromUser(u);
+ }
+ }
+ }
+ if ((label.includes("鍔犵彮绫诲瀷") || f.key === "overtimeType") && f.type === "select") {
+ form.overtimeType = val != null && val !== "" ? val : "";
+ }
+ if (label.includes("鍔犵彮鏃ユ湡") && f.type === "date") {
+ form.overtimeDate = val || "";
+ }
+ if (label.includes("浜嬬敱") || f.key === "summary" || label.includes("鍔犵彮浜嬬敱")) {
+ form.overtimeReason = val != null ? String(val) : "";
+ }
+ }
+
+ const { start, end } = resolveOvertimeTimeRange(payload, overtimeTimeField);
+ form.overtimeStartTime = start;
+ form.overtimeEndTime = end;
+ form.overtimeHours = computeOvertimeHours(start, end);
+ if (!form.overtimeDate && start) {
+ form.overtimeDate = dayjs(start).format("YYYY-MM-DD");
+ }
+}
+
async function submitForm() {
try {
await formRef.value?.validate?.();
} catch {
return;
}
- const hours = computeOvertimeHours(form.overtimeStartTime, form.overtimeEndTime);
- if (hours == null) {
- proxy?.$modal?.msgWarning?.("璇锋鏌ュ姞鐝捣姝㈡椂闂达紝缁撴潫鏃堕棿椤绘櫄浜庡紑濮嬫椂闂�");
+ const flowCheck = validateTemplateBinding({ flowNodes: form.flowNodes });
+ if (!flowCheck.ok) {
+ proxy?.$modal?.msgWarning?.(flowCheck.message || "璇峰畬鍠勫鎵规祦绋�");
return;
}
+ form.flowNodes = flowCheck.nodes;
+
+ const applicantKey = applicantTemplateField.value?.key;
+ if (applicantKey) {
+ syncApplicantFromUser(form.formPayload[applicantKey]);
+ }
+ syncOvertimeFieldsFromPayload();
+
+ if (form.overtimeHours == null) {
+ proxy?.$modal?.msgWarning?.("璇锋鏌ユā鏉夸腑鐨勫姞鐝椂闂达紝缁撴潫鏃堕棿椤绘櫄浜庡紑濮嬫椂闂�");
+ return;
+ }
+
+ const attachmentList = mapStorageBlobsToAttachmentList(form.storageBlobDTOs);
const payload = {
applicantId: form.applicantId,
applicantNo: form.applicantNo,
@@ -760,18 +795,18 @@
overtimeDate: form.overtimeDate,
overtimeStartTime: form.overtimeStartTime,
overtimeEndTime: form.overtimeEndTime,
- overtimeHours: hours,
+ overtimeHours: form.overtimeHours,
overtimeReason: form.overtimeReason,
- approvalFlowNodes: (form.approvalFlowNodes || []).map((n, i) => ({
- approverId: n.approverId,
- approverName:
- n.approverName || userById(n.approverId)?.nickName || userById(n.approverId)?.userName || "",
- sortOrder: i + 1,
- nodeOrder: i + 1,
- roleName: n.roleName || "",
- roleCode: n.roleCode || "",
- })),
- attachmentList: JSON.parse(JSON.stringify(form.attachmentList || [])),
+ hasTemplateBinding: true,
+ templateId: form.templateId,
+ templateName: form.templateName,
+ templateSnapshot: form.templateSnapshot,
+ formFieldDefs: form.formFieldDefs,
+ formPayload: JSON.parse(JSON.stringify(form.formPayload || {})),
+ flowNodes: JSON.parse(JSON.stringify(form.flowNodes || [])),
+ templateAttachments: JSON.parse(JSON.stringify(form.templateAttachments || [])),
+ storageBlobDTOs: JSON.parse(JSON.stringify(form.storageBlobDTOs || [])),
+ attachmentList,
};
if (formDialog.mode === "add") {
const id = `local_${Date.now()}`;
@@ -800,6 +835,9 @@
handleQuery();
}
+onMounted(() => {
+ loadFlowUsers();
+});
</script>
<style scoped>
@@ -834,9 +872,6 @@
white-space: nowrap;
border: 0;
}
-.upload-block {
- width: 100%;
-}
.mr6 {
margin-right: 6px;
}
@@ -849,14 +884,15 @@
.overtime-apply-form :deep(.el-form-item) {
margin-bottom: 18px;
}
+.template-name {
+ font-weight: 600;
+ color: var(--el-text-color-primary);
+}
+.ml12 {
+ margin-left: 12px;
+}
.overtime-apply-form-dialog :deep(.el-dialog__body) {
padding-top: 12px;
-}
-.flow-tip {
- margin: 10px 0 0;
- font-size: 12px;
- line-height: 1.5;
- color: var(--el-text-color-secondary);
}
.detail-flow-chain {
display: flex;
--
Gitblit v1.9.3