ZN
2026-03-20 a5f5e2c3fa5953a5474e4ad5d504c23acab94900
fix(analytics): 修正员工分析页面数据计算和样式问题

修复员工分析页面中12个月流动/流失率图表数据计算逻辑,使用实际离职数据重新计算比率。调整员工档案查询页面的入职日期筛选控件样式和布局。在反馈登记弹窗中为获取客户列表接口添加分页参数。
已修改3个文件
199 ■■■■■ 文件已修改
src/views/customerService/feedbackRegistration/components/formDia.vue 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/personnelManagement/analytics/index.vue 167 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/personnelManagement/employeeRecord/index.vue 26 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/customerService/feedbackRegistration/components/formDia.vue
@@ -365,7 +365,11 @@
// 打开弹框
const openDialog =async (type, row) => {
  // 请求多个接口,获取数据
  let res = await getAllCustomerList();
  let res = await getAllCustomerList({
    current: 1,
  size: 1000,
  total: 0,
  });
  if(res.records){
    customerNameOptions.value = res.records.map(item => ({
      label: item.customerName,
src/views/personnelManagement/analytics/index.vue
@@ -86,12 +86,15 @@
import { ref, onMounted, onUnmounted, nextTick } from 'vue'
import { ElMessage } from 'element-plus'
import * as echarts from 'echarts'
import dayjs from 'dayjs'
import {listDept} from "@/api/system/dept.js";
import {
  findStaffAnalysisMonthlyTurnoverRateFor12Months,
  findStaffLeaveReasonAnalysis,
  findStaffAnalysisTotalStatistic
} from "@/api/personnelManagement/staffAnalytics.js";
import { staffOnJobListPage } from "@/api/personnelManagement/staffOnJob.js";
import { findStaffLeaveListPage } from "@/api/personnelManagement/staffLeave.js";
// 响应式数据
const loading = ref(false)
@@ -148,6 +151,43 @@
const staffLeaveReasons = ref([])
// 12个月员工流动流失率分析数据
const turnoverRateStatistics = ref([])
const turnoverRateStatisticsRaw = ref([])
const turnoverSeriesNormalized = ref(false)
const staffCounts = ref({
  onJobTotal: 0,
  leaveTotal: 0,
  totalStaff: 0,
  leaveLast12Months: 0,
  joinLeaveRatio: 1
})
const safeNum = (val) => {
  const num = Number(val)
  return Number.isFinite(num) ? num : 0
}
const round2 = (val) => {
  const num = safeNum(val)
  return Number(num.toFixed(2))
}
const getListTotal = (res) => safeNum(res?.data?.total ?? res?.data?.count ?? 0)
const getLast12MonthRanges = () => {
  const end = dayjs()
  const start = end.subtract(11, 'month').startOf('month')
  const ranges = []
  for (let i = 0; i < 12; i++) {
    const cur = start.add(i, 'month')
    ranges.push({
      month: cur.format('YYYY-MM'),
      start: cur.startOf('month').format('YYYY-MM-DD'),
      end: cur.endOf('month').format('YYYY-MM-DD')
    })
  }
  return ranges
}
// 获取部门数据
const getDepartmentData = async () => {
@@ -177,7 +217,7 @@
  try {
    const res = await findStaffAnalysisMonthlyTurnoverRateFor12Months()
    if (res && res.data) {
      turnoverRateStatistics.value = res.data || []
      turnoverRateStatisticsRaw.value = res.data || []
    }
  } catch (error) {
    console.error('获取12个月员工流动流失率分析数据失败:', error)
@@ -186,14 +226,112 @@
const getStaffAnalysisTotalStatistic = async () => {
  try {
    const res = await findStaffAnalysisTotalStatistic()
    if (res && res.data) {
      keyMetrics.value[0].value = res.data.totalFlowRate || 0
      keyMetrics.value[1].value = res.data.totalTurnoverRate || 0
      keyMetrics.value[2].value = res.data.currentOnJobCount || 0
    const ranges = getLast12MonthRanges()
    const leave12Range = {
      leaveDateStart: ranges[0].start,
      leaveDateEnd: ranges[ranges.length - 1].end
    }
    const [totalRes, onJobRes, leaveRes, leave12Res] = await Promise.all([
      findStaffAnalysisTotalStatistic(),
      staffOnJobListPage({ current: 1, size: 1, staffState: 1 }),
      findStaffLeaveListPage({ current: 1, size: 1 }),
      findStaffLeaveListPage({ current: 1, size: 1, ...leave12Range })
    ])
    const totalFlowRate = safeNum(totalRes?.data?.totalFlowRate)
    const totalTurnoverRate = safeNum(totalRes?.data?.totalTurnoverRate)
    const joinLeaveRatio =
      totalTurnoverRate > 0 && totalFlowRate > 0 ? totalFlowRate / totalTurnoverRate : 1
    const onJobTotal = getListTotal(onJobRes)
    const leaveTotal = getListTotal(leaveRes)
    const totalStaff = onJobTotal + leaveTotal
    const leaveLast12Months = getListTotal(leave12Res)
    staffCounts.value = {
      onJobTotal,
      leaveTotal,
      totalStaff,
      leaveLast12Months,
      joinLeaveRatio: safeNum(joinLeaveRatio)
    }
    const turnoverRateNew =
      totalStaff > 0 ? (leaveLast12Months / totalStaff) * 100 : 0
    const flowRateNew =
      totalStaff > 0 ? (leaveLast12Months * staffCounts.value.joinLeaveRatio / totalStaff) * 100 : 0
    keyMetrics.value[0].value = round2(flowRateNew)
    keyMetrics.value[1].value = round2(turnoverRateNew)
    keyMetrics.value[2].value = onJobTotal || safeNum(totalRes?.data?.currentOnJobCount)
  } catch (error) {
    console.error('获取员工分析总统计数据失败:', error)
  }
}
const getLeaveCountsByMonthForLast12Months = async () => {
  const ranges = getLast12MonthRanges()
  const tasks = ranges.map((r) =>
    findStaffLeaveListPage({
      current: 1,
      size: 1,
      leaveDateStart: r.start,
      leaveDateEnd: r.end
    })
  )
  const results = await Promise.allSettled(tasks)
  const counts = {}
  results.forEach((res, idx) => {
    const month = ranges[idx].month
    counts[month] = res.status === 'fulfilled' ? getListTotal(res.value) : 0
  })
  const sum = Object.values(counts).reduce((acc, cur) => acc + safeNum(cur), 0)
  return { counts, sum }
}
const applyNormalizedTurnoverStatistics = async () => {
  const raw = Array.isArray(turnoverRateStatisticsRaw.value) ? turnoverRateStatisticsRaw.value : []
  if (raw.length === 0) {
    turnoverRateStatistics.value = []
    turnoverSeriesNormalized.value = false
    return
  }
  const totalStaff = safeNum(staffCounts.value.totalStaff)
  const leaveLast12Months = safeNum(staffCounts.value.leaveLast12Months)
  const ratio = safeNum(staffCounts.value.joinLeaveRatio) || 1
  if (totalStaff <= 0 || leaveLast12Months < 0) {
    turnoverRateStatistics.value = raw
    turnoverSeriesNormalized.value = false
    return
  }
  try {
    const { counts, sum } = await getLeaveCountsByMonthForLast12Months()
    if (sum > leaveLast12Months) {
      turnoverRateStatistics.value = raw
      turnoverSeriesNormalized.value = false
      return
    }
    turnoverRateStatistics.value = raw.map((item) => {
      const monthKey = String(item?.month ?? '')
      const leaveCount = safeNum(counts[monthKey])
      const turnoverRate = totalStaff > 0 ? (leaveCount / totalStaff) * 100 : 0
      const flowRate = totalStaff > 0 ? (leaveCount * ratio / totalStaff) * 100 : 0
      return {
        ...item,
        flowRate: round2(flowRate),
        turnoverRate: round2(turnoverRate)
      }
    })
    turnoverSeriesNormalized.value = true
  } catch (e) {
    turnoverRateStatistics.value = raw
    turnoverSeriesNormalized.value = false
  }
}
@@ -238,6 +376,8 @@
      getMonthlyTurnoverRateFor12Months(),
      getStaffAnalysisTotalStatistic()
    ])
    await applyNormalizedTurnoverStatistics()
    await nextTick()
    renderAllCharts()
@@ -317,10 +457,17 @@
      data: months,
      boundaryGap: false
    },
    yAxis: {
      type: 'value',
      axisLabel: { formatter: '{value}%' }
    },
    yAxis: turnoverSeriesNormalized.value
      ? {
          type: 'value',
          axisLabel: { formatter: '{value}%' },
          min: 0,
          max: 100
        }
      : {
          type: 'value',
          axisLabel: { formatter: '{value}%' }
        },
    series: [
      {
        name: '流动率',
src/views/personnelManagement/employeeRecord/index.vue
@@ -11,7 +11,7 @@
            clearable
            :prefix-icon="Search"
        />
        <span class="search_title">部门:</span>
        <span class="search_title search_title2">部门:</span>
          <el-tree-select
            v-model="searchForm.sysDeptId"
            :data="deptOptions"
@@ -20,9 +20,16 @@
            style="width: 240px"
            placeholder="请选择"
          />
        <span  style="margin-left: 10px" class="search_title">合同结束日期:</span>
        <el-date-picker  v-model="searchForm.entryDate" value-format="YYYY-MM-DD" format="YYYY-MM-DD" type="daterange"
                         placeholder="请选择" clearable @change="changeDaterange" />
          <span class="search_title search_title2">入职日期:</span>
          <el-date-picker
            v-model="searchForm.entryDateStart"
            value-format="YYYY-MM-DD"
            format="YYYY-MM-DD"
            placeholder="请选择"
          />
        <!-- <span  style="margin-left: 10px" class="search_title">合同结束日期:</span> -->
        <!-- <el-date-picker  v-model="searchForm.entryDate" value-format="YYYY-MM-DD" format="YYYY-MM-DD" type="daterange"
                         placeholder="请选择" clearable @change="changeDaterange" /> -->
        <el-button type="primary" @click="handleQuery" style="margin-left: 10px"
        >搜索</el-button
        >
@@ -129,6 +136,11 @@
  {
    label: "出生日期",
    prop: "birthDate",
    width: 120,
  },
  {
    label: "入职日期",
    prop: "entryDate",
    width: 120,
  },
  {
@@ -307,4 +319,8 @@
});
</script>
<style scoped></style>
<style scoped>
.search_title2 {
  margin-left: 10px;
}
</style>