Files
zkxw/web-admin/src/utils/project-management.ts
T
zlwu bd62416263 feat(project): add team attribution and business statistics
Add tenant-scoped teams and projects, order attribution across four businesses, conversion inheritance, scoped statistics and audited reassignment. Reuse existing Web and mobile UI patterns; team regions and hospitals remain informational.

Include incremental SQL and isolated regression coverage. Actual MySQL and browser/WebView integration validation remains pending; relates to issue #13.
2026-11-02 15:29:43 +08:00

61 lines
1.8 KiB
TypeScript

import type { BizType, ProjectRecord } from '@/api/project-management'
/** Drill-down uses the last successful statistics query, never unsaved filter edits. */
export function buildDrillFilters(
applied: ProjectRecord,
row: ProjectRecord,
bizType: BizType
): ProjectRecord {
const { groupBy, ...filters } = applied
const result = { ...filters, bizType, unassigned: row.id === 'unassigned' } as ProjectRecord
if (!result.unassigned && row.id !== 'total') {
result[groupBy === 'team' ? 'teamId' : 'projectId'] = row.id
}
return result
}
export function assignmentSnapshot(records: ProjectRecord[]) {
return records.map(({ bizType, id, projectId }) => ({
bizType,
id,
projectId: projectId ?? null
}))
}
/** Write bodies intentionally exclude response-only labels, timestamps and generated numbers. */
export function managementPayload(kind: 'teams' | 'projects', form: ProjectRecord): ProjectRecord {
const fields =
kind === 'teams'
? ['teamName', 'leaderUserId', 'enabled', 'remark']
: [
'projectName',
'teamId',
'leaderUserId',
'bizTypes',
'startDate',
'endDate',
'status',
'remark'
]
const data = Object.fromEntries(
fields.filter((key) => form[key] !== undefined).map((key) => [key, form[key]])
)
if (kind === 'teams') {
for (const [key, field] of [
['members', 'userId'],
['regions', 'regionId'],
['hospitals', 'hospitalId']
]) {
data[key] = (form[key] || []).map((row: ProjectRecord) => ({
...(row.id ? { id: row.id } : {}),
[field]: row[field]
}))
}
}
return data
}
export function projectOptionsParams(bizType: BizType, filter = false) {
return filter ? { bizType, usage: 'filter' as const } : { bizType }
}