feat: 新增产线管理、批量操作与绩效考核自动化功能

1.  新增部门产线绑定字段,优化部门列表展示
2.  添加薪资、考核、维度明细的批量新增/修改接口与实现
3.  新增绩效考核得分计算引擎与WMS数据拉取服务
4.  新增一键生成薪资与考核记录的弹窗功能
5.  优化配置页面UI与新增批量导入项目功能
6.  隐藏 coil/ship.vue 页面的校正按钮
This commit is contained in:
砂糖
2026-07-11 14:53:42 +08:00
parent 3c506e8ca6
commit 43069d8dc6
26 changed files with 1545 additions and 147 deletions

View File

@@ -15,61 +15,85 @@
<div class="toolbar-right">
<el-button size="small" type="primary" icon="el-icon-plus" @click="handleAdd">新增</el-button>
<el-button size="small" type="success" icon="el-icon-s-operation" :loading="generating" @click="handleBatchGenerate">一键生成</el-button>
<el-button size="small" type="warning" icon="el-icon-upload" :loading="batchSaving" @click="handleBatchSave">批量保存</el-button>
</div>
</div>
<!-- 口径说明 -->
<div class="formula-bar" :class="{ expanded: formulaExpanded }" @click="formulaExpanded = !formulaExpanded">
<span class="formula-bar-title">
<i :class="formulaExpanded ? 'el-icon-arrow-down' : 'el-icon-arrow-right'" />
口径说明
</span>
<span class="formula-bar-hint" v-if="!formulaExpanded">总系数 = (岗位系数+固定系数+调整系数+手动系数+绩效系数) × 车间系数</span>
</div>
<div v-if="formulaExpanded" class="formula-detail">
<div class="formula-row"><b>绩效系数</b> = 加权总分 ÷ 100考核后自动同步</div>
<div class="formula-row"><b>车间系数</b> = 车间固定系数默认 1.0不参与加法作为整体乘数</div>
<div class="formula-row"><b>总系数</b> = (岗位系数 + 固定系数 + 调整系数 + 手动系数 + 绩效系数) × 车间系数</div>
<div class="formula-row"><b>绩效工资</b> = 绩效基数 × 总系数</div>
<div class="formula-row"><b>实领薪资</b> = 底薪 + 绩效工资 + 奖励合计 扣款合计 + 其他金额自动计算</div>
</div>
<!-- 表格 -->
<div class="table-wrap">
<el-table :data="list" stripe size="small" v-loading="loading" empty-text="暂无薪资记录" class="inline-edit-table" border>
<!-- 只读列 -->
<!-- <el-table-column prop="employeeId" label="员工ID" width="90" /> -->
<!-- 状态列同上临时停用 -->
<!-- <el-table-column prop="status" label="状态" width="70" align="center">
<template slot-scope="scope">
<el-tag :type="statusType(scope.row.status)" size="small">{{ statusLabel(scope.row.status) }}</el-tag>
</template>
</el-table-column> -->
<el-table ref="salaryTable" :data="list" stripe size="small" v-loading="loading" empty-text="暂无薪资记录" class="inline-edit-table" border>
<!-- 薪资基数 -->
<el-table-column label="底薪" width="90" align="right"><template slot-scope="s">
<input v-model="s.row.baseSalary" class="cell-input cell-input--base" @change="markDirty(s.row)" />
<el-table-column label="姓名" width="70" align="center">
<template slot-scope="scope">
<span class="cell-clickable" @click.stop="toggleRowExpand(scope.row)">{{ scope.row.wmsEmployeeInfo ? scope.row.wmsEmployeeInfo.name : '-' }}</span>
</template>
</el-table-column>
<el-table-column label="岗位" width="70" align="center">
<template slot-scope="scope">
<span class="cell-clickable" @click.stop="toggleRowExpand(scope.row)">{{ scope.row.wmsEmployeeInfo ? scope.row.wmsEmployeeInfo.jobType : '-' }}</span>
</template>
</el-table-column>
<el-table-column label="底薪" width="60" align="right"><template slot-scope="s">
<input v-model="s.row.baseSalary" class="cell-input cell-input--base" @change="recalcSalary(s.row); markDirty(s.row)" />
</template></el-table-column>
<el-table-column label="绩效基数" width="90" align="right"><template slot-scope="s">
<el-table-column label="绩效基数" width="80" align="right"><template slot-scope="s">
<input v-model="s.row.perfBase" class="cell-input cell-input--base" @change="markDirty(s.row)" />
</template></el-table-column>
<!-- 考核得分 -->
<el-table-column label="考核得分" width="90" align="right"><template slot-scope="s">
<input v-model="s.row.perfScore" class="cell-input cell-input--coeff" @change="markDirty(s.row)" />
</template></el-table-column>
<el-table-column label="考核得分" width="80" align="center">
<template slot-scope="scope">
<span class="cell-clickable cell-clickable--score" @click.stop="toggleRowExpand(scope.row)">{{ scope.row.perfScore != null ? scope.row.perfScore : '-' }}</span>
</template>
</el-table-column>
<!-- 系数 -->
<el-table-column label="绩效系数" width="90" align="right"><template slot-scope="s">
<input v-model="s.row.perfCoeff" class="cell-input cell-input--coeff" @change="markDirty(s.row)" />
<el-table-column label="绩效系数" width="80" align="center">
<template slot-scope="scope">
<span class="cell-clickable cell-clickable--coeff" @click.stop="toggleRowExpand(scope.row)">{{ scope.row.perfCoeff != null ? scope.row.perfCoeff : '-' }}</span>
</template>
</el-table-column>
<el-table-column label="车间系数" width="80" align="right"><template slot-scope="s">
<input v-model="s.row.deptCoeff" class="cell-input cell-input--coeff" @change="recalcCoeffs(s.row); markDirty(s.row)" />
</template></el-table-column>
<el-table-column label="车间系数" width="90" align="right"><template slot-scope="s">
<input v-model="s.row.deptCoeff" class="cell-input cell-input--coeff" @change="markDirty(s.row)" />
<el-table-column label="岗位系数" width="80" align="right"><template slot-scope="s">
<input v-model="s.row.posCoeff" class="cell-input cell-input--coeff" @change="recalcCoeffs(s.row); markDirty(s.row)" />
</template></el-table-column>
<el-table-column label="岗位系数" width="90" align="right"><template slot-scope="s">
<input v-model="s.row.posCoeff" class="cell-input cell-input--coeff" @change="markDirty(s.row)" />
<el-table-column label="固定系数" width="80" align="right"><template slot-scope="s">
<input v-model="s.row.fixedCoeff" class="cell-input cell-input--coeff" @change="recalcCoeffs(s.row); markDirty(s.row)" />
</template></el-table-column>
<el-table-column label="固定系数" width="90" align="right"><template slot-scope="s">
<input v-model="s.row.fixedCoeff" class="cell-input cell-input--coeff" @change="markDirty(s.row)" />
<el-table-column label="调整系数" width="80" align="right"><template slot-scope="s">
<input v-model="s.row.adjCoeff" class="cell-input cell-input--coeff" @change="recalcCoeffs(s.row); markDirty(s.row)" />
</template></el-table-column>
<el-table-column label="调整系数" width="90" align="right"><template slot-scope="s">
<input v-model="s.row.adjCoeff" class="cell-input cell-input--coeff" @change="markDirty(s.row)" />
</template></el-table-column>
<el-table-column label="手动调整系数" width="100" align="right"><template slot-scope="s">
<!-- 手动系数 隐藏由考核得分自动覆盖 -->
<!-- <el-table-column label="手动系数" width="80" align="right"><template slot-scope="s">
<input v-model="s.row.adjCoeffManual" class="cell-input cell-input--coeff" @change="markDirty(s.row)" />
</template></el-table-column>
<el-table-column label="总系数" width="80" align="right"><template slot-scope="s">
<input v-model="s.row.totalCoeff" class="cell-input cell-input--coeff" @change="markDirty(s.row)" />
</template></el-table-column>
</template></el-table-column> -->
<el-table-column label="总系数" width="70" align="right">
<template slot-scope="scope"><span class="cell-readonly">{{ fmt(scope.row.totalCoeff) }}</span></template>
</el-table-column>
<!-- 绩效工资 -->
<el-table-column label="绩效工资" width="100" align="right"><template slot-scope="s">
<input v-model="s.row.perfWage" class="cell-input cell-input--amount" @change="markDirty(s.row)" />
</template></el-table-column>
<el-table-column label="绩效工资" width="80" align="right">
<template slot-scope="scope"><span class="cell-readonly">{{ fmt(scope.row.perfWage) }}</span></template>
</el-table-column>
<!-- 动态扣款列 -->
<el-table-column
@@ -78,7 +102,7 @@
><template slot-scope="s">
<input v-model="s.row._d[item.itemName]" class="cell-input cell-input--deduct" @change="onDeductChange(s.row); markDirty(s.row)" />
</template></el-table-column>
<el-table-column label="扣款合计" width="90" align="right">
<el-table-column label="扣款合计" width="80" align="right">
<template slot-scope="scope"><span class="cell-readonly cell-readonly--deduct">{{ scope.row._deductionsTotal }}</span></template>
</el-table-column>
@@ -89,20 +113,20 @@
><template slot-scope="s">
<input v-model="s.row._b[item.itemName]" class="cell-input cell-input--bonus" @change="onBonusChange(s.row); markDirty(s.row)" />
</template></el-table-column>
<el-table-column label="奖励合计" width="90" align="right">
<el-table-column label="奖励合计" width="80" align="right">
<template slot-scope="scope"><span class="cell-readonly cell-readonly--bonus">{{ scope.row._bonusesTotal }}</span></template>
</el-table-column>
<!-- 金额 -->
<el-table-column label="其他金额" width="90" align="right"><template slot-scope="s">
<input v-model="s.row.otherAmount" class="cell-input cell-input--amount" @change="markDirty(s.row)" />
</template></el-table-column>
<el-table-column label="实领薪资" width="100" align="right"><template slot-scope="s">
<input v-model="s.row.actualSalary" class="cell-input cell-input--amount" @change="markDirty(s.row)" />
<el-table-column label="其他金额" width="80" align="right"><template slot-scope="s">
<input v-model="s.row.otherAmount" class="cell-input cell-input--amount" @change="recalcSalary(s.row); markDirty(s.row)" />
</template></el-table-column>
<el-table-column label="实领薪资" width="90" align="right">
<template slot-scope="scope"><span class="cell-readonly">{{ fmt(scope.row.actualSalary) }}</span></template>
</el-table-column>
<!-- 参考值 -->
<el-table-column label="固薪参考" width="90" align="right"><template slot-scope="s">
<!-- <el-table-column label="固薪参考" width="90" align="right"><template slot-scope="s">
<input v-model="s.row.fixedSalaryRef" class="cell-input cell-input--ref" @change="markDirty(s.row)" />
</template></el-table-column>
<el-table-column label="调薪参考" width="90" align="right"><template slot-scope="s">
@@ -116,10 +140,10 @@
</template></el-table-column>
<el-table-column label="总薪参考" width="90" align="right"><template slot-scope="s">
<input v-model="s.row.totalSalaryRef" class="cell-input cell-input--ref" @change="markDirty(s.row)" />
</template></el-table-column>
</template></el-table-column> -->
<!-- 备注 -->
<el-table-column label="备注" min-width="140"><template slot-scope="s">
<el-table-column label="备注" min-width="80"><template slot-scope="s">
<input v-model="s.row.remark" class="cell-input cell-input--remark" @change="markDirty(s.row)" />
</template></el-table-column>
@@ -133,6 +157,72 @@
</el-table>
</div>
<!-- 绩效考核明细展开面板 -->
<div v-if="expandedRow" class="expand-panel" v-loading="appLoading">
<div class="expand-panel-header">
<span class="expand-panel-title">
绩效考核评分
{{ expandedRow.wmsEmployeeInfo ? expandedRow.wmsEmployeeInfo.name : expandedRow.employeeId }}
{{ expandedRow.wmsEmployeeInfo ? expandedRow.wmsEmployeeInfo.jobType : '' }}
</span>
<el-tag v-if="expandedRow._appraisal" :type="expandedRow._appraisal.status === '1' ? 'warning' : 'info'" size="mini">
{{ expandedRow._appraisal.status === '1' ? '已确认' : '草稿' }}
</el-tag>
<span v-if="expandedRow._appraisal" class="expand-panel-score">
加权总分{{ weightedTotal }}
</span>
<el-button size="mini" type="success" :loading="saveLoading" @click="handleSaveScores">保存</el-button>
<el-button type="text" size="mini" icon="el-icon-close" @click="handleCollapseExpand" style="margin-left:auto">收起</el-button>
</div>
<el-table v-if="expandedRow._appDetails && expandedRow._appDetails.length" :data="expandedRow._appDetails" size="mini" border class="expand-detail-table">
<el-table-column prop="dimName" label="考核维度" width="90" />
<el-table-column prop="quantitativeIndicator" label="考核指标" min-width="100" />
<el-table-column label="实际值" width="100" align="center">
<template slot-scope="scope">
<input v-model="scope.row.actualValue" class="cell-input cell-input--actual" @change="markDetailDirty(scope.row)" />
</template>
</el-table-column>
<el-table-column prop="targetValue" label="目标值" width="80" align="center" />
<el-table-column label="得分" width="80" align="center">
<template slot-scope="scope">
<input v-model="scope.row.dimScore" class="cell-input cell-input--score" placeholder="0" />
</template>
</el-table-column>
<el-table-column label="加分" width="70" align="center">
<template slot-scope="scope">
<input v-model="scope.row.bonus" class="cell-input cell-input--bonus" placeholder="0" />
</template>
</el-table-column>
<el-table-column label="扣分" width="70" align="center">
<template slot-scope="scope">
<input v-model="scope.row.penalty" class="cell-input cell-input--penalty" placeholder="0" />
</template>
</el-table-column>
<el-table-column prop="weight" label="权重" width="70" align="center" />
<el-table-column label="总分" width="80" align="center">
<template slot-scope="scope">
<span class="cell-subtotal">{{ subtotal(scope.row) }}</span>
</template>
</el-table-column>
<el-table-column label="原始总分" width="80" align="center">
<template slot-scope="scope">
<span class="cell-rawtotal">{{ rawRowTotal(scope.row) }}</span>
</template>
</el-table-column>
<el-table-column prop="scoreRule" label="评分规则" min-width="120" show-overflow-tooltip />
</el-table>
<div v-else-if="expandedRow._appLoaded && !appLoading" class="expand-empty">暂无绩效考核数据</div>
</div>
<!-- 一键生成弹窗 -->
<GenerateDialog
:visible.sync="showGenerateDialog"
:dept-id="deptId"
:dept-name="deptName"
:period="period"
@done="onGenerateDone"
/>
<div class="pagination-wrapper">
<el-pagination
:current-page="query.pageNum"
@@ -149,15 +239,22 @@
<script>
import { listPerfSalary, addPerfSalary, updatePerfSalary, delPerfSalary } from '@/api/perf/salary'
import { listEmployeeInfo } from '@/api/wms/employeeInfo'
import { listPerfAppraisal, updatePerfAppraisal } from '@/api/perf/appraisal'
import { listPerfAppraisalDetail, updatePerfAppraisalDetail, batchUpdatePerfAppraisalDetail } from '@/api/perf/appraisalDetail'
import { listPerfDeptItemConfig } from '@/api/perf/deptItemConfig'
import { listPerfDeptConfig } from '@/api/perf/deptConfig'
import GenerateDialog from './GenerateDialog.vue'
import { calculateTotal } from '@/utils/scoreEngine'
import { fetchProductionData } from '@/utils/perfDataService'
export default {
name: 'SalaryPanel',
components: { GenerateDialog },
props: {
deptId: { type: [Number, String], default: null },
deptName: { type: String, default: '' },
period: { type: String, default: '' }
period: { type: String, default: '' },
productionLine: { type: String, default: '' }
},
data() {
return {
@@ -172,7 +269,29 @@ export default {
},
deductionItems: [],
bonusItems: [],
generating: false
generating: false,
batchSaving: false,
showGenerateDialog: false,
expandedRow: null,
appLoading: false,
calcLoading: false,
saveLoading: false,
_prodCache: null,
formulaExpanded: false,
_defaultDeptCoeff: 1
}
},
computed: {
weightedTotal() {
if (!this.expandedRow || !this.expandedRow._appDetails || !this.expandedRow._appDetails.length) return '-'
let sum = 0
this.expandedRow._appDetails.forEach(d => {
sum += (parseFloat(d.dimScore) || 0) * (parseFloat(d.weight) || 0) / 100
})
const bonus = this.expandedRow._appDetails.reduce((s, d) => s + (parseFloat(d.bonus) || 0), 0)
const penalty = this.expandedRow._appDetails.reduce((s, d) => s + (parseFloat(d.penalty) || 0), 0)
const total = Math.min(120, Math.max(0, sum + bonus - penalty))
return total.toFixed(1)
}
},
watch: {
@@ -195,6 +314,7 @@ export default {
},
loadItemConfig() {
if (!this.deptId || !this.period) return
// 加载扣款/奖励项目
listPerfDeptItemConfig({ deptId: this.deptId, month: this.period + '-01' }).then(res => {
const rows = res.rows || []
this.deductionItems = rows.filter(r => r.itemType === 1 && r.isEnabled === 1)
@@ -203,6 +323,13 @@ export default {
this.deductionItems = []
this.bonusItems = []
})
// 加载考核参数获取车间系数默认值
listPerfDeptConfig({ deptId: this.deptId, month: this.period + '-01', pageNum: 1, pageSize: 1 }).then(res => {
const rows = res.rows || []
this._defaultDeptCoeff = rows.length ? (rows[0].deptCoeff || 1) : 1
}).catch(() => {
this._defaultDeptCoeff = 1
})
},
/* 解析扣款/奖励 JSON 到行对象 */
parseRowItems(row) {
@@ -226,8 +353,32 @@ export default {
this.$set(row, '_deductionsTotal', sumD)
this.$set(row, '_bonusesTotal', sumB)
},
onDeductChange(row) { this.recalcTotals(row) },
onBonusChange(row) { this.recalcTotals(row) },
/** 系数变化时自动重算总系数和绩效工资 */
recalcCoeffs(row) {
const pos = parseFloat(row.posCoeff) || 0
const fixed = parseFloat(row.fixedCoeff) || 0
const adj = parseFloat(row.adjCoeff) || 0
const adjManual = parseFloat(row.adjCoeffManual) || 0
const perf = parseFloat(row.perfCoeff) || 0
const dept = parseFloat(row.deptCoeff) || 1
const total = (pos + fixed + adj + adjManual + perf) * dept
this.$set(row, 'totalCoeff', total.toFixed(2))
const perfBase = parseFloat(row.perfBase) || 0
this.$set(row, 'perfWage', (perfBase * total).toFixed(2))
this.recalcSalary(row)
},
/** 自动计算实领薪资 */
recalcSalary(row) {
const baseSalary = parseFloat(row.baseSalary) || 0
const perfWage = parseFloat(row.perfWage) || 0
const bonuses = parseFloat(row._bonusesTotal) || 0
const deductions = parseFloat(row._deductionsTotal) || 0
const other = parseFloat(row.otherAmount) || 0
const actual = baseSalary + perfWage + bonuses - deductions + other
this.$set(row, 'actualSalary', actual.toFixed(2))
},
onDeductChange(row) { this.recalcTotals(row); this.recalcSalary(row) },
onBonusChange(row) { this.recalcTotals(row); this.recalcSalary(row) },
markDirty(row) { this.$set(row, '_dirty', true) },
loadList() {
@@ -244,7 +395,13 @@ export default {
this.list = (res.rows || []).map(r => {
this.$set(r, '_dirty', false)
this.$set(r, '_saving', false)
// 车间系数默认从考核参数获取,否则为 1
if (!r.deptCoeff || parseFloat(r.deptCoeff) === 0) {
this.$set(r, 'deptCoeff', (this._defaultDeptCoeff || 1).toString())
}
this.parseRowItems(r)
this.recalcCoeffs(r)
this.recalcSalary(r)
return r
})
this.total = res.total || 0
@@ -344,64 +501,206 @@ export default {
this.$message.warning('缺少部门名称')
return
}
this.$confirm(`确认根据"${this.deptName}"下的在职员工,一键生成本月薪资记录吗?`, '提示', { type: 'info' }).then(() => {
this.generating = true
listEmployeeInfo({ dept: this.deptName, isLeave: 0, pageSize: 9999 }).then(empRes => {
const employees = empRes.rows || []
if (employees.length === 0) {
this.$message.warning('该部门下暂无在职员工')
return
this.showGenerateDialog = true
},
onGenerateDone() {
this.loadList()
this.$message.success('薪资记录生成完成')
},
/** 批量保存所有已修改的行 */
handleBatchSave() {
const dirtyRows = this.list.filter(r => r._dirty)
if (dirtyRows.length === 0) {
this.$message.info('没有需要保存的修改')
return
}
this.batchSaving = true
const tasks = dirtyRows.map(row => {
this.$set(row, '_saving', true)
const data = { ...row }
data.deductionsJson = JSON.stringify(row._d || {})
data.bonusesJson = JSON.stringify(row._b || {})
data.deductionsTotal = row._deductionsTotal
data.bonusesTotal = row._bonusesTotal
delete data._d; delete data._b; delete data._dirty; delete data._saving
delete data._deductionsTotal; delete data._bonusesTotal
// 清除前端扩展字段
delete data.wmsEmployeeInfo
delete data._appLoaded; delete data._appraisal; delete data._appDetails
const api = data.id ? updatePerfSalary : addPerfSalary
return api(data).then(res => {
if (!data.id && res.data) {
this.$set(row, 'id', res.data.id || res.data)
}
listPerfSalary({ deptId: this.deptId, period: this.period, pageSize: 9999 }).then(salaryRes => {
const existing = new Set((salaryRes.rows || []).map(r => String(r.employeeId)))
const toInsert = employees.filter(e => !existing.has(String(e.employeeId) || String(e.infoId)))
if (toInsert.length === 0) {
this.$message.info('该部门下所有在职员工已有本月薪资记录')
return
}
const emptyJson = JSON.stringify({})
const tasks = toInsert.map(emp => addPerfSalary({
employeeId: emp.employeeId || emp.infoId || '',
deptId: this.deptId,
period: this.period,
baseSalary: emp.baseSalary || 0,
perfBase: emp.perfBase || 0,
posCoeff: emp.posCoeffDefault || 0,
perfScore: 0,
perfCoeff: 0,
deptCoeff: 0,
fixedCoeff: 0,
adjCoeff: 0,
adjCoeffManual: 0,
totalCoeff: 0,
perfWage: 0,
deductionsJson: emptyJson,
deductionsTotal: 0,
bonusesJson: emptyJson,
bonusesTotal: 0,
otherAmount: 0,
actualSalary: 0,
fixedSalaryRef: '',
adjSalaryRef: '',
baoPerShiftRef: '',
baoSalaryRef: '',
totalSalaryRef: '',
status: '0',
remark: ''
}))
return Promise.allSettled(tasks)
}).then(results => {
if (!results) return
const ok = results.filter(r => r.status === 'fulfilled').length
const fail = results.filter(r => r.status === 'rejected').length
this.$message.success(`生成完成:成功 ${ok}${fail > 0 ? `,失败 ${fail}` : ''}`)
this.loadList()
})
this.$set(row, '_dirty', false)
return { ok: true }
}).catch(() => {
return { ok: false }
}).finally(() => {
this.generating = false
this.$set(row, '_saving', false)
})
}).catch(() => {})
}
})
Promise.all(tasks).then(results => {
const ok = results.filter(r => r.ok).length
const fail = results.filter(r => !r.ok).length
if (fail > 0) {
this.$message.warning(`保存完成:成功 ${ok} 条,失败 ${fail}`)
} else {
this.$message.success(`已保存 ${ok} 条记录`)
}
}).finally(() => {
this.batchSaving = false
})
},
/** 点击可点击列时切换展开,并加载绩效考核明细 */
toggleRowExpand(row) {
if (this.expandedRow === row) {
this.expandedRow = null
return
}
this.expandedRow = row
if (row._appLoaded) return
this.appLoading = true
const empId = row.employeeId
if (!empId) {
this.appLoading = false
this.$set(row, '_appLoaded', true)
return
}
listPerfAppraisal({ employeeId: empId, deptId: this.deptId, period: this.period, pageNum: 1, pageSize: 1 }).then(appRes => {
const appRows = appRes.rows || []
if (appRows.length === 0) {
this.$set(row, '_appraisal', null)
this.$set(row, '_appDetails', [])
return
}
this.$set(row, '_appraisal', appRows[0])
return listPerfAppraisalDetail({ appraisalId: appRows[0].id, pageSize: 9999 })
}).then(detailRes => {
if (detailRes) {
this.$set(row, '_appDetails', detailRes.rows || [])
}
}).catch(() => {
this.$set(row, '_appraisal', null)
this.$set(row, '_appDetails', [])
}).finally(() => {
this.appLoading = false
this.$set(row, '_appLoaded', true)
})
},
/** 计算得分 */
async handleCalcScore() {
if (!this.expandedRow._appDetails || !this.expandedRow._appDetails.length) return
this.calcLoading = true
try {
// 拉取部门生产数据(缓存按 deptId+period
if (!this._prodCache || this._prodCache.key !== `${this.deptId}_${this.period}`) {
this._prodCache = {
key: `${this.deptId}_${this.period}`,
data: await fetchProductionData(this.productionLine, this.period)
}
}
const prod = this._prodCache.data
// 将实际数据填入各维度
const details = this.expandedRow._appDetails
details.forEach(d => {
switch (d.dimName) {
case '生产效率':
if (prod.totalWeight > 0 && !d.actualValue) {
this.$set(d, 'actualValue', String(Math.round(prod.totalWeight * 100) / 100))
}
break
case '产品质量':
if (prod.totalCount > 0 && !d.actualValue) {
const ratio = Math.round((prod.abCount / prod.totalCount) * 10000) / 100
this.$set(d, 'actualValue', String(ratio))
}
break
case '成本控制':
if (prod.avgCostPerTon > 0 && !d.actualValue) {
this.$set(d, 'actualValue', String(Math.round(prod.avgCostPerTon * 100) / 100))
}
break
}
})
const { finalScore, details: computed } = calculateTotal(details)
computed.forEach((d, i) => {
this.$set(details[i], 'dimScore', d._dimScore)
})
this.$message.success('计算完成,请检查后保存')
} finally {
this.calcLoading = false
}
},
/** 保存得分到后端 */
async handleSaveScores() {
if (!this.expandedRow._appDetails || !this.expandedRow._appDetails.length) return
this.saveLoading = true
try {
const details = this.expandedRow._appDetails
// 构建批量更新数据
const batchData = details.map(d => ({
id: d.id,
actualValue: d.actualValue || '',
dimScore: parseFloat(d.dimScore) || 0,
bonus: parseFloat(d.bonus) || 0,
penalty: parseFloat(d.penalty) || 0
}))
// 批量更新维度明细
await batchUpdatePerfAppraisalDetail(batchData)
// 按照权重计算总分
let weightedSum = 0
let totalBonus = 0
let totalPenalty = 0
details.forEach(d => {
const score = parseFloat(d.dimScore) || 0
const weight = parseFloat(d.weight) || 0
weightedSum += score * weight / 100
totalBonus += parseFloat(d.bonus) || 0
totalPenalty += parseFloat(d.penalty) || 0
})
const finalScore = Math.min(120, Math.max(0, weightedSum + totalBonus - totalPenalty))
// 更新总考核记录
if (this.expandedRow._appraisal && this.expandedRow._appraisal.id) {
await updatePerfAppraisal({ id: this.expandedRow._appraisal.id, finalScore })
this.$set(this.expandedRow._appraisal, 'finalScore', finalScore)
}
// 同步绩效系数到薪资记录
const perfCoeff = finalScore / 100
if (this.expandedRow.id) {
await updatePerfSalary({ id: this.expandedRow.id, perfCoeff })
this.$set(this.expandedRow, 'perfCoeff', perfCoeff)
this.recalcCoeffs(this.expandedRow)
}
this.$message.success('保存成功')
} catch {
this.$message.error('保存失败')
} finally {
this.saveLoading = false
}
},
/** 收起展开面板 */
handleCollapseExpand() {
this.expandedRow = null
},
/** 标记 detail 已修改 */
markDetailDirty() {},
subtotal(row) {
const score = parseFloat(row.dimScore) || 0
const weight = parseFloat(row.weight) || 0
return (score * weight / 100).toFixed(1)
},
rawRowTotal(row) {
const score = parseFloat(row.dimScore) || 0
const bonus = parseFloat(row.bonus) || 0
const penalty = parseFloat(row.penalty) || 0
return (score + bonus - penalty).toFixed(1)
},
handleExpandChange() {}
}
}
</script>
@@ -504,7 +803,202 @@ export default {
flex-shrink: 0;
}
/* 口径说明 */
.formula-bar {
display: flex;
align-items: center;
padding: 4px 8px;
background: #f0f5ff;
border: 1px solid #d9ecff;
border-radius: 4px;
cursor: pointer;
user-select: none;
flex-shrink: 0;
transition: background 0.15s;
&:hover {
background: #e6f0fc;
}
&.expanded {
border-radius: 4px 4px 0 0;
margin-bottom: 0;
}
}
.formula-bar-title {
font-size: 12px;
font-weight: 600;
color: #409eff;
display: flex;
align-items: center;
gap: 4px;
flex-shrink: 0;
}
.formula-bar-hint {
font-size: 11px;
color: #909399;
margin-left: 12px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.formula-detail {
padding: 8px 12px;
background: #fafbfc;
border: 1px solid #d9ecff;
border-top: none;
border-radius: 0 0 4px 4px;
flex-shrink: 0;
}
.formula-row {
font-size: 12px;
color: #606266;
line-height: 1.8;
b {
color: #303133;
}
}
.el-table .el-button + .el-button {
margin-left: 0;
}
/* 展开面板 */
.expand-panel {
margin-top: 8px;
padding: 12px 16px;
background: #fafafa;
border: 1px solid #ebeef5;
border-radius: 4px;
flex-shrink: 0;
}
.expand-panel-header {
display: flex;
align-items: center;
margin-bottom: 8px;
}
.expand-panel-title {
font-size: 13px;
font-weight: 600;
color: #303133;
}
.expand-panel-score {
margin-left: 12px;
font-size: 14px;
color: #409eff;
font-weight: 600;
}
.expand-detail-table {
width: 100%;
}
.expand-empty {
color: #909399;
font-size: 13px;
text-align: center;
padding: 12px 0;
}
/* 实际值输入 */
.cell-input--actual {
width: 100%;
height: 26px;
border: 1px solid #dcdfe6;
outline: none;
text-align: center;
padding: 0 4px;
font-size: 12px;
color: #303133;
box-sizing: border-box;
transition: border-color 0.15s;
&:focus {
border-color: #409eff;
}
}
/* 加分扣分输入 */
.cell-input--bonus,
.cell-input--penalty {
width: 100%;
height: 26px;
border: 1px solid #dcdfe6;
outline: none;
text-align: center;
padding: 0 4px;
font-size: 12px;
box-sizing: border-box;
transition: border-color 0.15s;
&:focus {
border-color: #409eff;
}
}
.cell-input--bonus {
color: #67c23a;
background: #f0f9eb;
}
.cell-input--penalty {
color: #f56c6c;
background: #fef0f0;
}
/* 得分手动输入 */
.cell-input--score {
width: 100%;
height: 26px;
border: 1px solid #dcdfe6;
outline: none;
text-align: center;
padding: 0 4px;
font-size: 12px;
color: #409eff;
font-weight: 600;
box-sizing: border-box;
transition: border-color 0.15s;
&:focus {
border-color: #409eff;
}
}
/* 总分列 */
.cell-subtotal {
font-weight: 600;
color: #e6a23c;
font-size: 13px;
}
.cell-rawtotal {
font-weight: 600;
color: #409eff;
font-size: 13px;
}
/* 得分显示 */
.cell-score {
font-weight: 600;
color: #409eff;
&--empty {
color: #c0c4cc;
}
}
/* 可点击列样式 */
.cell-clickable {
display: inline-block;
cursor: pointer;
color: #409eff;
border-bottom: 1px dashed #409eff;
padding: 0 2px;
transition: color 0.15s, border-color 0.15s;
&:hover {
color: #337ecc;
border-bottom-style: solid;
}
&--score {
color: #e6a23c;
border-bottom-color: #e6a23c;
&:hover { color: #cf9236; }
}
&--coeff {
color: #67c23a;
border-bottom-color: #67c23a;
&:hover { color: #529b2e; }
}
}
</style>