constantData.js
3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
* 工资申诉常量数据映射
* 将API返回的数据映射到 salaryItems 数据结构
*/
// 工资项基础配置
const SALARY_ITEM_CONFIG = [
{
id: 'attendance',
title: '实际出勤天数',
centerLeft: '根据打卡数据产生',
btnText: '申诉考勤',
unit: '天',
defaultValue: 0
},
{
id: 'daily',
title: '日报完成天数',
centerLeft: '填写驻店日报天数',
btnText: '去补日报',
unit: '天',
defaultValue: 0,
hasMissingDates: true
},
{
id: 'recording',
title: '平板录音总数',
centerLeft: '触客总数为',
btnText: '申诉平板',
unit: '条',
defaultValue: 0
}
]
// API字段映射配置
const API_FIELD_MAP = {
attendance: {
value: 'actualAttendanceDays',
deduction: 'attendanceDeductionAmount',
appealable: 'attendanceAppealable'
},
daily: {
value: 'dailyReportDays',
deduction: 'dailyReportDeductionAmount',
appealable: 'dailyReportable',
missingDates: 'missingDailyReportDates'
},
recording: {
value: 'padRecordNum',
deduction: 'padDeductionAmount',
appealable: 'padAppealable'
}
}
/**
* 格式化扣款金额显示
*/
const formatDeductionAmount = (amount) => {
if (!amount || amount === 0) return ''
return amount > 0 ? `-${amount}元` : `${amount}元`
}
/**
* 格式化缺失日期显示
*/
const formatMissingDates = (dates) => {
if (!dates || !Array.isArray(dates) || dates.length === 0) return ''
return dates.map(date => {
if (date.includes('-')) {
const day = date.split('-')[2]
return day.replace(/^0+/, '')
}
return date
}).join('、') + '号'
}
/**
* 格式化数值显示
*/
const formatValue = (value, unit, defaultValue = 0) => {
const num = value !== undefined && value !== null ? value : defaultValue
return `${num}${unit}`
}
/**
* 创建单个工资项数据
*/
const createSalaryItem = (config, apiData) => {
const fieldMap = API_FIELD_MAP[config.id]
const value = apiData[fieldMap.value]
const deductionAmount = apiData[fieldMap.deduction]
const appealable = apiData[fieldMap.appealable] || false
const missingDates = config.hasMissingDates ? apiData[fieldMap.missingDates] : null
return {
id: config.id,
title: config.title,
value: formatValue(value, config.unit, config.defaultValue),
centerLeft: config.centerLeft,
centerLeftNum: '',
centerRight: deductionAmount ? '扣款' : '',
centerRightPrice: formatDeductionAmount(deductionAmount),
bottomText: missingDates && missingDates.length > 0 ? '缺失天数为' : '',
bottomDays: config.hasMissingDates ? formatMissingDates(missingDates) : '',
btnText: appealable ? config.btnText : '',
btnType: config.id,
appealable
}
}
/**
* 将API数据映射到工资项数据结构
* @param {Object} apiData - API返回的数据对象
* @returns {Array} salaryItems 数组
*/
export function mapApiDataToSalaryItems(apiData = {}) {
return SALARY_ITEM_CONFIG.map(config => createSalaryItem(config, apiData))
}
/**
* 默认的工资项数据结构(用于初始化或兜底)
*/
export const defaultSalaryItems = mapApiDataToSalaryItems({})