| | |
| | | import { |
| | | getApprovalTemplateDetail, |
| | | listApprovalTemplate, |
| | | TEMPLATE_TYPE_BUILTIN, |
| | | TEMPLATE_TYPE_CUSTOM, |
| | | } from "@/api/officeProcessAutomation/approvalTemplate.js"; |
| | | import { |
| | |
| | | import { ElMessage, ElMessageBox } from "element-plus"; |
| | | import { computed, reactive, ref } from "vue"; |
| | | import { |
| | | fetchBusinessTypeOptions, |
| | | formatDisplayTime, |
| | | mapEnabledFromApi, |
| | | mapTemplateFromApi, |
| | | unwrapTemplateDetail, |
| | | unwrapTemplateList, |
| | | } from "../approve-template/approveTemplateConstants.js"; |
| | | import { buildSubmitTemplateFromRow } from "../approve-template/formConfigUtils.js"; |
| | | import { |
| | | buildFormPayloadRules, |
| | | buildTemplateBindingFromDetail, |
| | | validateTemplateBinding, |
| | | } from "../approve-shared/approvalTemplateBindingUtils.js"; |
| | | import { |
| | | APPROVAL_TYPE_OPTIONS, |
| | | approvalStatusLabel, |
| | |
| | | createEmptySubmitForm, |
| | | mapInstanceFromApi, |
| | | mapSubmitTemplateCard, |
| | | validateSubmitFlowNodes, |
| | | matchBusinessTypeValue, |
| | | unwrapInstancePage, |
| | | } from "./approveListConstants.js"; |
| | | |
| | |
| | | const userStore = useUserStore(); |
| | | |
| | | const tableData = ref([]); |
| | | const submitTemplateCards = ref([]); |
| | | const submitBusinessTypeOptions = ref([]); |
| | | const allSubmitTemplates = ref([]); |
| | | const selectedBusinessType = ref(""); |
| | | const submitTemplatesLoading = ref(false); |
| | | |
| | | const submitTemplateCards = computed(() => { |
| | | if (selectedBusinessType.value == null || selectedBusinessType.value === "") return []; |
| | | return allSubmitTemplates.value.filter((card) => |
| | | matchBusinessTypeValue(card.businessType, selectedBusinessType.value) |
| | | ); |
| | | }); |
| | | |
| | | const searchForm = reactive({ |
| | | approvalType: "", |
| | |
| | | if (submitDialog.mode === "edit") { |
| | | return `修改${activeTemplate.value?.label || submitForm.templateName || "审批"}`; |
| | | } |
| | | if (submitDialog.step === 1) return "选择审批模板"; |
| | | if (submitDialog.step === 1) return "选择模板类型"; |
| | | if (submitDialog.step === 2) return `选择审批模板${businessTypeLabel(selectedBusinessType.value) ? `(${businessTypeLabel(selectedBusinessType.value)})` : ""}`; |
| | | return `提交${activeTemplate.value?.label || "审批"}`; |
| | | }); |
| | | |
| | | const selectedBusinessTypeLabel = computed(() => businessTypeLabel(selectedBusinessType.value)); |
| | | |
| | | function businessTypeLabel(type) { |
| | | if (type == null || type === "") return ""; |
| | | const hit = submitBusinessTypeOptions.value.find((x) => matchBusinessTypeValue(x.value, type)); |
| | | return hit?.label || ""; |
| | | } |
| | | |
| | | function countTemplatesByBusinessType(type) { |
| | | return allSubmitTemplates.value.filter((card) => matchBusinessTypeValue(card.businessType, type)).length; |
| | | } |
| | | |
| | | const activeTemplate = computed(() => submitForm.templateSnapshot || null); |
| | | |
| | |
| | | return submitForm.formFieldDefs || []; |
| | | }); |
| | | |
| | | const submitFormRules = computed(() => { |
| | | const rules = { |
| | | templateKey: [{ required: true, message: "请选择审批类型", trigger: "change" }], |
| | | }; |
| | | submitFormFields.value.forEach((f) => { |
| | | if (!f.required) return; |
| | | if (f.type === "number") { |
| | | rules[`formPayload.${f.key}`] = [{ required: true, message: `请填写${f.label}`, trigger: "blur" }]; |
| | | } else if (f.type === "datetimerange") { |
| | | rules[`formPayload.${f.key}`] = [{ required: true, message: `请选择${f.label}`, trigger: "change" }]; |
| | | } else { |
| | | rules[`formPayload.${f.key}`] = [{ required: true, message: `请填写${f.label}`, trigger: "blur" }]; |
| | | } |
| | | }); |
| | | return rules; |
| | | }); |
| | | const submitFormRules = computed(() => ({ |
| | | templateKey: [{ required: true, message: "请选择审批类型", trigger: "change" }], |
| | | ...buildFormPayloadRules(submitFormFields.value), |
| | | })); |
| | | |
| | | const tableColumn = ref([ |
| | | { label: "申请人编号", prop: "applicantNo", width: 110 }, |
| | |
| | | async function loadSubmitTemplates() { |
| | | submitTemplatesLoading.value = true; |
| | | try { |
| | | const [builtinRes, customRes] = await Promise.all([ |
| | | listApprovalTemplate(TEMPLATE_TYPE_BUILTIN), |
| | | const [typeOptions, customRes] = await Promise.all([ |
| | | fetchBusinessTypeOptions(), |
| | | listApprovalTemplate(TEMPLATE_TYPE_CUSTOM), |
| | | ]); |
| | | const merged = [ |
| | | ...unwrapTemplateList(builtinRes), |
| | | ...unwrapTemplateList(customRes), |
| | | ].filter((row) => mapEnabledFromApi(row.enabled)); |
| | | submitTemplateCards.value = merged.map(mapSubmitTemplateCard); |
| | | submitBusinessTypeOptions.value = typeOptions; |
| | | allSubmitTemplates.value = unwrapTemplateList(customRes) |
| | | .filter((row) => mapEnabledFromApi(row.enabled)) |
| | | .map(mapSubmitTemplateCard); |
| | | } catch { |
| | | submitTemplateCards.value = []; |
| | | submitBusinessTypeOptions.value = []; |
| | | allSubmitTemplates.value = []; |
| | | ElMessage.error("加载审批模板失败"); |
| | | } finally { |
| | | submitTemplatesLoading.value = false; |
| | |
| | | function resetSubmitDialogState() { |
| | | submitDialog.mode = "add"; |
| | | submitDialog.step = 1; |
| | | selectedBusinessType.value = ""; |
| | | submitEditRow.value = null; |
| | | Object.assign(submitForm, createEmptySubmitForm("")); |
| | | } |
| | |
| | | return; |
| | | } |
| | | submitDialog.mode = "edit"; |
| | | submitDialog.step = 2; |
| | | submitDialog.step = 3; |
| | | submitEditRow.value = { ...row }; |
| | | Object.assign(submitForm, buildEditFormFromInstanceRow(row)); |
| | | submitDialog.visible = true; |
| | |
| | | submitTemplatesLoading.value = true; |
| | | try { |
| | | const res = await getApprovalTemplateDetail(card.id); |
| | | const mapped = mapTemplateFromApi(unwrapTemplateDetail(res)); |
| | | const tpl = { |
| | | ...buildSubmitTemplateFromRow(mapped), |
| | | templateId: mapped.id, |
| | | }; |
| | | const base = createEmptySubmitForm(String(card.id), tpl, mapped.flowNodes); |
| | | const applied = buildTemplateBindingFromDetail(res); |
| | | Object.assign(submitForm, { |
| | | ...base, |
| | | templateName: mapped.templateName || tpl.label || "", |
| | | templateSnapshot: tpl, |
| | | formFieldDefs: tpl.fields || [], |
| | | templateKey: String(card.id), |
| | | ...applied, |
| | | businessType: |
| | | applied.businessType ?? card.businessType ?? selectedBusinessType.value, |
| | | }); |
| | | submitDialog.step = 2; |
| | | submitDialog.step = 3; |
| | | } catch { |
| | | ElMessage.error("加载模板详情失败"); |
| | | } finally { |
| | |
| | | } |
| | | } |
| | | |
| | | function backToTemplatePick() { |
| | | function onBusinessTypePick(type) { |
| | | if (!countTemplatesByBusinessType(type)) { |
| | | ElMessage.warning("该类型下暂无可用审批模板"); |
| | | return; |
| | | } |
| | | selectedBusinessType.value = type; |
| | | submitDialog.step = 2; |
| | | } |
| | | |
| | | function backToBusinessTypePick() { |
| | | selectedBusinessType.value = ""; |
| | | submitDialog.step = 1; |
| | | } |
| | | |
| | | function backToTemplatePick() { |
| | | submitDialog.step = 2; |
| | | } |
| | | |
| | | async function submitInstanceForm() { |
| | |
| | | return false; |
| | | } |
| | | if (!activeTemplate.value) return false; |
| | | const flowCheck = validateSubmitFlowNodes(submitForm.flowNodes); |
| | | if (!flowCheck.ok) { |
| | | ElMessage.warning(flowCheck.message); |
| | | const bindingCheck = validateTemplateBinding({ flowNodes: submitForm.flowNodes }); |
| | | if (!bindingCheck.ok) { |
| | | ElMessage.warning(bindingCheck.message); |
| | | return false; |
| | | } |
| | | if (!submitForm.templateId) { |
| | |
| | | submitForm, |
| | | activeTemplate: activeTemplate.value, |
| | | userStore, |
| | | flowNodes: flowCheck.nodes, |
| | | flowNodes: bindingCheck.nodes, |
| | | }) |
| | | ); |
| | | submitDialog.visible = false; |
| | |
| | | return false; |
| | | } |
| | | if (!activeTemplate.value) return false; |
| | | const flowCheck = validateSubmitFlowNodes(submitForm.flowNodes); |
| | | if (!flowCheck.ok) { |
| | | ElMessage.warning(flowCheck.message); |
| | | const bindingCheck = validateTemplateBinding({ flowNodes: submitForm.flowNodes }); |
| | | if (!bindingCheck.ok) { |
| | | ElMessage.warning(bindingCheck.message); |
| | | return false; |
| | | } |
| | | if (!submitForm.instanceId) { |
| | |
| | | buildInstanceDto({ |
| | | submitForm, |
| | | activeTemplate: activeTemplate.value, |
| | | flowNodes: flowCheck.nodes, |
| | | flowNodes: bindingCheck.nodes, |
| | | existingRow: submitEditRow.value, |
| | | }) |
| | | ); |
| | |
| | | activeTemplate, |
| | | submitFormFields, |
| | | submitFormRules, |
| | | submitBusinessTypeOptions, |
| | | submitTemplateCards, |
| | | selectedBusinessType, |
| | | selectedBusinessTypeLabel, |
| | | businessTypeLabel, |
| | | countTemplatesByBusinessType, |
| | | submitTemplatesLoading, |
| | | handleQuery, |
| | | resetSearch, |
| | |
| | | resetSubmitDialogState, |
| | | openSubmitDialog, |
| | | openEditDialog, |
| | | onBusinessTypePick, |
| | | onTemplatePick, |
| | | backToBusinessTypePick, |
| | | backToTemplatePick, |
| | | submitInstanceForm, |
| | | submitNewApproval, |