matterItem.js
6.33 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
/** TaskInfoDTO.status:0-待完成,1-已完成 */
export const MATTER_STATUS_MAP = {
0: { name: '待完成', color: '#FF9D0A', background: '#ff9d0a1a' },
1: { name: '已完成', color: '#35C376', background: '#35C3761a' },
}
/** 人员更换评估:列表/详情展示问题驻店销售 */
export const STAFF_REPLACE_ACCESS_TYPE = 'staff-replace-access'
/** taskType 枚举(接口文档) */
export const TASK_TYPE_NAME_MAP = {
[STAFF_REPLACE_ACCESS_TYPE]: '人员更换评估',
'policy-update-access': '商务政策更新评估',
'scene-expand': '多品类扩张',
'traffic-optimize': '流量问题改善',
}
/** businessType:1-延保 2-轻改 3-权益 */
export const BUSINESS_TYPE_NAME_MAP = {
1: '延保',
2: '轻改',
3: '权益',
}
function formatDateTime(val) {
if (!val) return '-'
return String(val).replace('T', ' ').replace(/\.\d+Z?$/, '').slice(0, 19)
}
/** TaskStaffRelDTO[] → 问题驻店人员展示文案 */
export function formatStaffList(staffList) {
if (!Array.isArray(staffList) || !staffList.length) return ''
return staffList
.map((s) => s.staffName)
.filter(Boolean)
.join('/')
}
function resolveBusinessTypeName(item) {
if (item.businessTypeName) return item.businessTypeName
const key = item.businessType
if (key == null || key === '') return '-'
return BUSINESS_TYPE_NAME_MAP[key] || String(key)
}
function resolveTaskTypeName(item) {
if (item.taskTypeName) return item.taskTypeName
if (item.taskType && TASK_TYPE_NAME_MAP[item.taskType]) {
return TASK_TYPE_NAME_MAP[item.taskType]
}
return item.taskType || '-'
}
export const MATTER_DETAIL_FIELDS = [
{ label: '归属门店', key: 'merchantName' },
{ label: '归属业务', key: 'businessName' },
{ label: '创建人', key: 'creatorName' },
{ label: '创建时间', key: 'createTimeText' },
{ label: '任务描述', key: 'descriptionText', multiline: true },
]
export const MATTER_LIST_FIELDS = [
{ label: '归属门店', key: 'merchantName' },
{ label: '归属业务', key: 'businessName' },
{ label: '创建人', key: 'creatorName' },
{ label: '创建时间', key: 'createTimeText' },
{ label: '任务描述', key: 'descriptionText', ellipsis: true },
]
export const MATTER_LIST_COMPLETED_FIELDS = [
{ label: '归属门店', key: 'merchantName' },
{ label: '归属业务', key: 'businessName' },
{ label: '创建人', key: 'creatorName' },
{ label: '任务描述', key: 'descriptionText', ellipsis: true },
{ label: '专项任务回复', key: 'replyText', ellipsis: true },
]
const STAFF_NAMES_LIST_FIELD = { label: '问题驻店销售', key: 'staffNames' }
/** 列表展示字段:仅 staff-replace-access 含问题驻店销售 */
export function getMatterListFields(taskType, completed = false) {
const base = completed ? MATTER_LIST_COMPLETED_FIELDS : MATTER_LIST_FIELDS
const fields = base.map((f) => ({ ...f }))
if (taskType !== STAFF_REPLACE_ACCESS_TYPE) return fields
fields.splice(2, 0, {
...STAFF_NAMES_LIST_FIELD,
ellipsis: !completed,
})
return fields
}
/** 详情展示字段:仅 staff-replace-access 含问题驻店销售 */
export function getMatterDetailFields(taskType) {
const fields = MATTER_DETAIL_FIELDS.map((f) => ({ ...f }))
if (taskType !== STAFF_REPLACE_ACCESS_TYPE) return fields
fields.splice(2, 0, { ...STAFF_NAMES_LIST_FIELD })
return fields
}
/**
* 归一化 TaskInfoDTO(列表项 / 分页 condition 同结构)
* @param {object} dto TaskInfoDTO
*/
export function normalizeMatterItem(dto = {}, index = 0) {
const statusKey = dto.status ?? 0
const completed = statusKey === 1 || statusKey === '1'
const statusStyle = completed ? MATTER_STATUS_MAP[1] : MATTER_STATUS_MAP[0]
const staffList = Array.isArray(dto.staffList) ? dto.staffList : []
const staffNames = formatStaffList(staffList)
return {
...dto,
id: dto.id ?? dto.taskCenterId ?? `matter-${index}`,
taskCenterId: dto.taskCenterId,
taskType: dto.taskType,
taskTypeText: resolveTaskTypeName(dto),
merchantName: dto.storeName || '-',
storeId: dto.storeId,
businessType: dto.businessType,
businessName: resolveBusinessTypeName(dto),
/** 问题驻店人员:仅来自 staffList */
staffList,
sellerName: staffNames || '-',
staffNames,
creatorName: dto.creator || '-',
creatorPhone: dto.creatorPhone || '',
createTimeText: formatDateTime(dto.createdDate),
descriptionText: dto.taskDescription || '-',
replyText: dto.replyContent || '',
replyTimeText: formatDateTime(dto.replyTime),
/** 指派的区域运营 */
assignedToId: dto.assignedToId,
assignedToName: dto.assignedToName || '-',
status: statusKey,
statusName: completed ? '已完成' : '待完成',
statusStyle,
completed,
showAction: !completed,
showView: completed,
listFields: getMatterListFields(dto.taskType, false),
completedListFields: getMatterListFields(dto.taskType, true),
}
}
function pickCount(data, keys) {
for (const key of keys) {
if (data[key] != null && data[key] !== '') return Number(data[key]) || 0
}
return null
}
/** 解析 count.stat 返回:待完成 / 已完成 / 全部 */
export function parseTaskCenterCountStat(data = {}) {
const pending = pickCount(data, [
'pendingCount',
'pendingTotal',
'waitCount',
'waitTotal',
'unfinishedCount',
'unCompleteCount',
'status0Count',
'toDoCount',
'pending',
'wait',
])
const done = pickCount(data, [
'completedCount',
'completedTotal',
'completeCount',
'finishCount',
'finishTotal',
'finishedCount',
'status1Count',
'doneCount',
'completed',
'finish',
'done',
])
const all = pickCount(data, [
'totalCount',
'allCount',
'allTotal',
'total',
'all',
])
const pendingNum = pending ?? 0
const doneNum = done ?? 0
const allNum = all ?? pendingNum + doneNum
return { pending: pendingNum, done: doneNum, all: allNum }
}
/** 解析分页接口 data:list 为列表,condition 为查询条件回显(TaskInfoDTO) */
export function parseTaskCenterPageData(data = {}) {
const list = (data.list || []).map((item, index) =>
normalizeMatterItem(item, index)
)
const condition = data.condition
? normalizeMatterItem(data.condition, -1)
: null
return {
list,
condition,
total: data.total ?? 0,
pageNum: data.pageNum,
pageSize: data.pageSize,
}
}