From 26491ec83e5de9a880dff84370203771f9decfa3 Mon Sep 17 00:00:00 2001 From: weizong song Date: Fri, 14 Aug 2026 08:31:33 +0800 Subject: [PATCH] up --- .../components/LeadDepartmentSummaryForm.vue | 11 +++- .../budget/collection/leadDepartment.vue | 20 ++++--- .../components/LeadDepartmentPage.spec.js | 54 +++++++++++++++++++ .../LeadDepartmentSummaryForm.spec.js | 22 ++++++++ 4 files changed, 98 insertions(+), 9 deletions(-) create mode 100644 tests/unit/components/LeadDepartmentPage.spec.js diff --git a/src/views/budget/collection/components/LeadDepartmentSummaryForm.vue b/src/views/budget/collection/components/LeadDepartmentSummaryForm.vue index b6d139f..c4f7bf1 100644 --- a/src/views/budget/collection/components/LeadDepartmentSummaryForm.vue +++ b/src/views/budget/collection/components/LeadDepartmentSummaryForm.vue @@ -1084,7 +1084,9 @@ export default { await this.initFormData() await this.loadDepartmentSubmissions() - if (this.mode === 'edit' || this.mode === 'view') { + // 小包分配时会预建一条空的 lead draft。它不是实际汇总,不能回填其 + // 0 值覆盖刚从执行科室自动聚合出的资金和实施进度数据。 + if (this.shouldLoadExistingSummary()) { await this.loadExistingSummaryData() } }, @@ -1096,6 +1098,13 @@ export default { } }, methods: { + shouldLoadExistingSummary() { + if (this.mode !== 'edit' && this.mode !== 'view') return false + + const submission = this.packageData.submission || this.packageData.lead_submission || {} + return Boolean(submission.summary_started_at || submission.summaryStartedAt) + }, + initZIndexManagement() { // 初始化层级管理,设置基础层级 this.dynamicZIndex = 3000 diff --git a/src/views/budget/collection/leadDepartment.vue b/src/views/budget/collection/leadDepartment.vue index 1f1d9ad..b847fa6 100644 --- a/src/views/budget/collection/leadDepartment.vue +++ b/src/views/budget/collection/leadDepartment.vue @@ -441,10 +441,18 @@ export default { return Boolean(submission && (submission.summary_started_at || submission.summaryStartedAt)) }, - summaryActionLabel(row) { + getSummaryMode(row) { const submission = this.getLeadSubmission(row) + const year = row.budget_year || {} + + if (year.status !== 'ACTIVE') return 'view' + if (!this.hasStartedLeadSummary(row)) return 'create' + return submission && submission.status === 'draft' ? 'edit' : 'view' + }, + + summaryActionLabel(row) { if (!this.hasStartedLeadSummary(row)) return '汇总提交' - return submission && submission.status === 'draft' ? '修改汇总' : '查看汇总' + return this.getSummaryMode(row) === 'edit' ? '修改汇总' : '查看汇总' }, canAllocate(row) { @@ -473,12 +481,8 @@ export default { openSummarySubmit(row) { // 打开汇总提交对话框 this.currentSummaryPackage = { ...row } - // 小包分解会预建 lead 草稿保存基础申请信息,不能用记录是否存在判断是否首次汇总。 - const submission = this.getLeadSubmission(row) - const isActiveYear = row.budget_year && row.budget_year.status === 'ACTIVE' - this.summaryMode = !isActiveYear - ? 'view' - : !this.hasStartedLeadSummary(row) ? 'create' : submission.status === 'draft' ? 'edit' : 'view' + // 文案和弹窗模式必须复用同一判断,避免出现“修改汇总”却以只读方式打开。 + this.summaryMode = this.getSummaryMode(row) this.summarySubmitVisible = true }, diff --git a/tests/unit/components/LeadDepartmentPage.spec.js b/tests/unit/components/LeadDepartmentPage.spec.js new file mode 100644 index 0000000..adaccb7 --- /dev/null +++ b/tests/unit/components/LeadDepartmentPage.spec.js @@ -0,0 +1,54 @@ +jest.mock('@/api/budget/budgetCollectionYear.js', () => ({})) +jest.mock('@/api/budget/leadDepartment.js', () => ({})) +jest.mock('@/views/budget/collection/components/SplitPackageForm.vue', () => ({})) +jest.mock('@/views/budget/collection/components/ProjectDetailsView.vue', () => ({})) +jest.mock('@/views/budget/collection/components/LeadDepartmentSummaryForm.vue', () => ({})) +jest.mock('@/views/budget/collection/components/BudgetSubmissionForm.vue', () => ({})) + +import LeadDepartmentPage from '@/views/budget/collection/leadDepartment.vue' + +function createContext() { + const methods = LeadDepartmentPage.methods + const context = { + currentSummaryPackage: null, + summaryMode: null, + summarySubmitVisible: false + } + context.getLeadSubmission = methods.getLeadSubmission.bind(context) + context.hasStartedLeadSummary = methods.hasStartedLeadSummary.bind(context) + context.getSummaryMode = methods.getSummaryMode.bind(context) + return context +} + +describe('LeadDepartmentPage summary action', () => { + const draftSummary = { + status: 'draft', + summary_started_at: '2026-08-14 10:00:00' + } + + it('opens an active-year draft summary in edit mode when labelled 修改汇总', () => { + const context = createContext() + const row = { + budget_year: { status: 'ACTIVE' }, + lead_submission: draftSummary + } + + expect(LeadDepartmentPage.methods.summaryActionLabel.call(context, row)).toBe('修改汇总') + LeadDepartmentPage.methods.openSummarySubmit.call(context, row) + + expect(context.summaryMode).toBe('edit') + }) + + it('uses 查看汇总 rather than 修改汇总 when a draft belongs to an inactive year', () => { + const context = createContext() + const row = { + budget_year: { status: 'INACTIVE' }, + lead_submission: draftSummary + } + + expect(LeadDepartmentPage.methods.summaryActionLabel.call(context, row)).toBe('查看汇总') + LeadDepartmentPage.methods.openSummarySubmit.call(context, row) + + expect(context.summaryMode).toBe('view') + }) +}) diff --git a/tests/unit/components/LeadDepartmentSummaryForm.spec.js b/tests/unit/components/LeadDepartmentSummaryForm.spec.js index 003d9af..46cad7a 100644 --- a/tests/unit/components/LeadDepartmentSummaryForm.spec.js +++ b/tests/unit/components/LeadDepartmentSummaryForm.spec.js @@ -132,4 +132,26 @@ describe('LeadDepartmentSummaryForm automatic aggregation', () => { fileList: [expect.objectContaining({ fileId: 201 })] })) }) + + it('does not load a pre-created empty draft as an existing summary', () => { + const context = { + mode: 'edit', + packageData: { + submission: { status: 'draft', summary_started_at: null } + } + } + + expect(LeadDepartmentSummaryForm.methods.shouldLoadExistingSummary.call(context)).toBe(false) + }) + + it('loads a genuinely started draft when editing it', () => { + const context = { + mode: 'edit', + packageData: { + submission: { status: 'draft', summary_started_at: '2026-08-14 10:00:00' } + } + } + + expect(LeadDepartmentSummaryForm.methods.shouldLoadExistingSummary.call(context)).toBe(true) + }) })