teachApplyItem.js
7.73 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
export const TEACH_STATUS_MAP = {
0: { name: '待审批', color: '#FF9D0A', background: '#ff9d0a1a' },
1: { name: '已通过', color: '#35C376', background: '#35C3761a' },
2: { name: '已驳回', color: '#F24724', background: '#f247241a' },
}
const DEFAULT_STATUS = TEACH_STATUS_MAP[0]
export const TEACH_LIST_FIELDS = [
{ label: '归属业务', key: 'businessName' },
{ label: '需带教驻店人员', key: 'staffNames' },
{ label: '归属区域督导', key: 'supervisorName' },
{ label: '创建时间', key: 'createTimeText' },
{ label: '申请描述', key: 'descriptionText', ellipsis: true },
]
export const TEACH_DETAIL_FIELDS = [
{ label: '归属门店', key: 'merchantName' },
{ label: '归属业务', key: 'businessName' },
{ label: '需带教驻店人员', key: 'staffNames' },
{ label: '归属区域督导', key: 'supervisorName' },
{ label: '创建时间', key: 'createTimeText' },
{ label: '申请描述', key: 'descriptionText', multiline: true },
]
export const TEACH_APPROVE_FIELDS = [
{ label: '指定督导', key: 'approveSupervisorName' },
{ label: '带教场景', key: 'teachSceneName' },
{ label: '带教时间', key: 'teachTimeText' },
{ label: '带教方式', key: 'teachMethodName' },
{ label: '带教主题', key: 'teachTopic' },
{ label: '审核人', key: 'auditorName' },
{ label: '通过时间', key: 'auditTimeText' },
]
export const TEACH_REJECT_FIELDS = [
{ label: '驳回原因', key: 'rejectReason', multiline: true },
{ label: '审核人', key: 'auditorName' },
{ label: '驳回时间', key: 'auditTimeText' },
]
function resolveStaffNames(dto) {
if (typeof dto.staffNames === 'string' && dto.staffNames) return dto.staffNames
const staffList =
dto.staffNameList || dto.teachStaffList || dto.residentStaffNames || []
if (Array.isArray(staffList) && staffList.length) {
return staffList
.map((s) => (typeof s === 'string' ? s : s.staffName))
.filter(Boolean)
.join('/')
}
return '-'
}
/**
* 归一化带教申请列表项 / condition
* @param {object} dto TeachingApplicationListItemDTO
*/
export function normalizeTeachApplyItem(dto = {}, index = 0) {
const statusKey =
dto.approvalStatus ?? dto.auditStatus ?? dto.status ?? dto.approveStatus ?? 0
const statusStyle = TEACH_STATUS_MAP[statusKey] || DEFAULT_STATUS
const statusName =
dto.approvalStatusText ||
statusStyle.name ||
(statusKey === 1 ? '已通过' : statusKey === 2 ? '已驳回' : '待审批')
const pending = statusKey === 0 || statusKey === '0'
const approved = dto.approvedInfo || {}
const rejected = dto.rejectedInfo || {}
return {
...dto,
applicationId: dto.applicationId,
id: String(dto.applicationId ?? dto.id ?? `teach-${index}`),
title: dto.merchantName || dto.shopName || dto.storeName || '-',
merchantName: dto.merchantName || dto.shopName || dto.storeName || '-',
businessName: dto.businessTypeText || dto.businessName || dto.businessTypeName || '-',
businessType: dto.businessType,
staffNames: resolveStaffNames(dto),
supervisorName:
dto.supervisorName || dto.areaSupervisorName || dto.supervisor || '-',
createTimeText: dto.createdTime || dto.createTime || dto.gmtCreate || '-',
descriptionText: dto.description || dto.applyDesc || '-',
approvalStatus: statusKey,
auditStatus: statusKey,
approveSupervisorName: approved.assignedSupervisor || '-',
teachSceneName: approved.mentoringScene || '-',
teachTimeText: approved.mentoringTime || '-',
teachMethodName: approved.mentoringMethod || '-',
teachTopic: approved.mentoringTopic || '-',
auditorName: approved.approver || rejected.approver || '-',
auditTimeText: approved.approvedTime || rejected.rejectedTime || '',
rejectReason: rejected.rejectReason || '',
approvedInfo: approved,
rejectedInfo: rejected,
statusName,
statusStyle,
pending,
showApprove: statusKey === 1 || statusKey === '1',
showReject: statusKey === 2 || statusKey === '2',
}
}
/** 策略分页 data(兼容 { code, data: { list, total } } 或直接分页对象) */
export function getStrategyPageData(res) {
if (res && Array.isArray(res.list)) return res
if (res?.data && typeof res.data === 'object' && !Array.isArray(res.data)) {
return res.data
}
return {}
}
export function parseTeachingApplicationPageData(resOrData = {}) {
const data = getStrategyPageData(resOrData)
const list = (data.list || []).map((item, index) =>
normalizeTeachApplyItem(item, index)
)
const condition = data.condition
? normalizeTeachApplyItem(data.condition, -1)
: null
return {
list,
condition,
total: data.total ?? 0,
pageNum: data.pageNum,
pageSize: data.pageSize,
}
}
function pickList(data) {
if (Array.isArray(data)) return data
if (data && Array.isArray(data.data)) return data.data
if (data?.data && typeof data.data === 'object' && Array.isArray(data.data.list)) {
return data.data.list
}
return data?.list || []
}
/** 策略列表 data 提取(数组 / data[] / data.list / list) */
export function extractStrategyList(res) {
if (Array.isArray(res)) return res
if (Array.isArray(res?.data)) return res.data
if (res?.data && typeof res.data === 'object' && Array.isArray(res.data.list)) {
return res.data.list
}
if (Array.isArray(res?.list)) return res.list
if (typeof res?.data === 'string') {
try {
const parsed = JSON.parse(res.data)
if (Array.isArray(parsed)) return parsed
if (Array.isArray(parsed?.list)) return parsed.list
} catch (e) {
// ignore
}
}
return pickList(res)
}
/** 策略接口成功判断(兼容直接返回 data 数组) */
export function isStrategyApiSuccess(res) {
if (Array.isArray(res)) return true
return res?.code === '0' || res?.code === 0 || res?.code == 0
}
/** 策略接口 data 提取(兼容 data 为数组) */
export function getStrategyApiData(res) {
return extractStrategyList(res)
}
function resolveStaffPhone(item = {}) {
return (
item.userPhone ??
item.staffPhone ??
item.phone ??
item.mobilePhone ??
item.mobile ??
item.staffMobile ??
''
)
}
function resolveStaffName(item = {}) {
return (
item.userName ??
item.staffName ??
item.name ??
item.realName ??
item.employeeName ??
''
)
}
/** 解析策略-门店列表 */
export function parseStrategyShopMerchantList(resOrData = {}) {
return extractStrategyList(resOrData)
.map((item) => ({
merchantId:
item.merchantId ??
item.shopMerchantId ??
item.storeId ??
item.id,
merchantName:
item.merchantName ??
item.shopMerchantName ??
item.storeName ??
item.name ??
'',
}))
.filter((item) => item.merchantId != null && item.merchantId !== '')
}
/** 解析策略-驻店人员列表 */
export function parseStrategyShopMerchantStaffList(resOrData = {}) {
return extractStrategyList(resOrData)
.map((item) => ({
userPhone: String(resolveStaffPhone(item) || '').trim(),
userName: String(resolveStaffName(item) || '').trim(),
}))
.filter((item) => item.userName)
}
/** 解析策略-区域督导列表 */
export function parseStrategyShopMerchantSupervisorList(resOrData = {}) {
return extractStrategyList(resOrData)
.map((item) => ({
merchantId: item.merchantId,
directorType: item.directorType,
directorUserId: item.directorUserId ?? '',
directorName: item.directorName ?? item.supervisorName ?? '',
directorPhone: item.directorPhone ?? item.supervisorPhone ?? '',
}))
.filter((item) => item.directorName)
}
/** 多个督导 directorName 用 / 拼接 */
export function formatDirectorNames(list = []) {
return list
.map((item) => item.directorName)
.filter(Boolean)
.join('/')
}