diff --git a/frontend/src/views/Settings.vue b/frontend/src/views/Settings.vue index c024276..36e9ba0 100644 --- a/frontend/src/views/Settings.vue +++ b/frontend/src/views/Settings.vue @@ -568,21 +568,54 @@ @@ -1793,74 +1826,121 @@
+ + + + + + + + {{ currentScorePool.deptName }} + 汇总 + 共享 + 独立管理 - {{ currentScorePool.balance }} 分 + {{ getDisplayScoreBalance() }} 分 - {{ currentScorePool.totalRecharge || 0 }} 分 + {{ getDisplayTotalRecharge() }} 分 - {{ currentScorePool.totalConsume || 0 }} 分 + {{ getDisplayTotalConsume() }} 分 {{ currentScorePool.totalEarn }} 分 - 消耗限制设置 - - - - - {{ currentScorePool.limitEnabled ? '已启用' : '未启用' }} - - - - {{ currentScorePool.limitPeriod === 'DAILY' ? '每日' : - currentScorePool.limitPeriod === 'WEEKLY' ? '每周' : - currentScorePool.limitPeriod === 'MONTHLY' ? '每月' : '未知' }} - - - {{ currentScorePool.periodLimit || 0 }} 分 - - - {{ currentScorePool.periodUsed || 0 }} 分 - - ({{ Math.round((currentScorePool.periodUsed || 0) / currentScorePool.periodLimit * 100) }}%) - - - + + - 充值积分 - - - - - - - 确认充值 - - + +
@@ -2497,6 +2577,180 @@ const getDepartmentLevel = (record: DepartmentOverview): number => { return 3 } +// 当前部门的积分管理层级 +const currentDeptScoreLevel = computed(() => { + if (!currentDept.value) return 0 + return getDepartmentLevel(currentDept.value) +}) + +// 积分池弹窗标题 +const scorePoolModalTitle = computed(() => { + if (!currentDept.value) return '积分池管理' + const level = currentDeptScoreLevel.value + if (level === 1 && hasChildDepartments(currentDept.value)) { + return '积分池管理 - 汇总视图' + } else if (level === 3) { + return '积分池管理 - 共享视图' + } + return '积分池管理' +}) + +// 判断部门是否有子部门 +const hasChildDepartments = (dept: DepartmentOverview | null): boolean => { + if (!dept?.id) return false + return departments.value.some(d => d.parentId === dept.id) +} + +// 获取父部门名称 +const getParentDeptName = (dept: DepartmentOverview | null): string => { + if (!dept?.parentId) return '' + const parent = departments.value.find(d => d.id === dept.parentId) + return parent?.deptName || '' +} + +// 获取父部门(二级部门)的积分信息 +const getParentDeptScoreInfo = () => { + if (!currentDept.value?.parentId) return null + const parent = departments.value.find(d => d.id === currentDept.value?.parentId) + return parent || null +} + +// 是否可以管理积分(充值等操作) +const canManageScore = computed(() => { + if (!currentDept.value) return false + const level = currentDeptScoreLevel.value + + // 三级部门不能管理积分 + if (level === 3) return false + + // 一级部门:如果有子部门,则不能直接管理(显示汇总) + if (level === 1 && hasChildDepartments(currentDept.value)) return false + + // 二级部门可以管理 + // 没有子部门的一级部门也可以管理 + return true +}) + +// 获取显示的积分余额(考虑层级继承) +const getDisplayScoreBalance = (): number => { + if (!currentDept.value) return 0 + const level = currentDeptScoreLevel.value + + // 三级部门:显示父部门(二级)的积分 + if (level === 3) { + const parent = getParentDeptScoreInfo() + return parent?.scoreBalance || 0 + } + + // 一级部门且有子部门:计算所有二级部门的积分汇总 + if (level === 1 && hasChildDepartments(currentDept.value)) { + const childDepts = departments.value.filter(d => d.parentId === currentDept.value?.id) + return childDepts.reduce((sum, d) => sum + (d.scoreBalance || 0), 0) + } + + // 其他情况:显示本部门积分 + return currentScorePool.value?.balance || 0 +} + +// 获取显示的累计充值(考虑层级继承) +const getDisplayTotalRecharge = (): number => { + if (!currentDept.value) return 0 + const level = currentDeptScoreLevel.value + + // 三级部门:显示父部门的数据 + if (level === 3) { + const parent = getParentDeptScoreInfo() + return parent?.totalRecharge || 0 + } + + // 一级部门且有子部门:计算汇总 + if (level === 1 && hasChildDepartments(currentDept.value)) { + const childDepts = departments.value.filter(d => d.parentId === currentDept.value?.id) + return childDepts.reduce((sum, d) => sum + (d.totalRecharge || 0), 0) + } + + return currentScorePool.value?.totalRecharge || 0 +} + +// 获取显示的累计消耗(考虑层级继承) +const getDisplayTotalConsume = (): number => { + if (!currentDept.value) return 0 + const level = currentDeptScoreLevel.value + + // 三级部门:显示父部门的数据 + if (level === 3) { + const parent = getParentDeptScoreInfo() + return parent?.totalConsume || 0 + } + + // 一级部门且有子部门:计算汇总 + if (level === 1 && hasChildDepartments(currentDept.value)) { + const childDepts = departments.value.filter(d => d.parentId === currentDept.value?.id) + return childDepts.reduce((sum, d) => sum + (d.totalConsume || 0), 0) + } + + return currentScorePool.value?.totalConsume || 0 +} + +// 获取子部门积分列表(用于一级部门汇总视图) +const getChildDepartmentScores = () => { + if (!currentDept.value?.id) return [] + return departments.value + .filter(d => d.parentId === currentDept.value?.id) + .map(d => ({ + ...d, + id: d.id, + deptName: d.deptName, + scoreBalance: d.scoreBalance || 0, + totalRecharge: d.totalRecharge || 0, + totalConsume: d.totalConsume || 0 + })) +} + +// 子部门积分明细表格列 +const childDeptScoreColumns = [ + { title: '二级部门', dataIndex: 'deptName', key: 'deptName' }, + { title: '当前余额', dataIndex: 'scoreBalance', key: 'scoreBalance' }, + { title: '累计充值', dataIndex: 'totalRecharge', key: 'totalRecharge' }, + { title: '累计消耗', dataIndex: 'totalConsume', key: 'totalConsume' }, + { title: '操作', key: 'actions', width: 100 } +] + +// 获取一级部门的汇总积分(所有二级部门积分之和) +const getLevel1DeptTotalScore = (dept: DepartmentOverview): number => { + if (!dept.id) return 0 + const childDepts = departments.value.filter(d => d.parentId === dept.id) + return childDepts.reduce((sum, d) => sum + (d.scoreBalance || 0), 0) +} + +// 获取一级部门的汇总充值 +const getLevel1DeptTotalRecharge = (dept: DepartmentOverview): number => { + if (!dept.id) return 0 + const childDepts = departments.value.filter(d => d.parentId === dept.id) + return childDepts.reduce((sum, d) => sum + (d.totalRecharge || 0), 0) +} + +// 获取一级部门的汇总消耗 +const getLevel1DeptTotalConsume = (dept: DepartmentOverview): number => { + if (!dept.id) return 0 + const childDepts = departments.value.filter(d => d.parentId === dept.id) + return childDepts.reduce((sum, d) => sum + (d.totalConsume || 0), 0) +} + +// 获取父部门(二级部门)的积分(用于三级部门显示) +const getParentDeptScore = (dept: DepartmentOverview): number => { + if (!dept.parentId) return 0 + const parent = departments.value.find(d => d.id === dept.parentId) + return parent?.scoreBalance || 0 +} + +// 根据ID获取父部门名称 +const getParentDeptNameById = (parentId: number | null | undefined): string => { + if (!parentId) return '' + const parent = departments.value.find(d => d.id === parentId) + return parent?.deptName || '' +} + // 部门树形选择器数据 - 用于调整用户部门 const departmentTreeSelectData = computed(() => { // 构建树形结构