matterItem.js
8.47 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
/** TaskInfoDTO.status:0-待完成,1-已完成 */
export const MATTER_STATUS_MAP = {
0: { name: "待完成", color: "#FF9D0A", background: "#ff9d0a1a" },
1: { name: "已完成", color: "#35C376", background: "#35C3761a" },
2: { name: "已逾期", color: "#F24724", background: "#F247241a" }
};
/** 人员更换评估:列表/详情展示问题驻店销售 */
export const STAFF_REPLACE_ACCESS_TYPE = "staff-replace-access";
/** 流量问题改善/提升触客率:列表/详情展示目标触客率 */
export const TRAFFIC_OPTIMIZE_TYPE = "traffic-optimize";
/** 督导带教 */
export const SUPERVISE_TEACH_TYPE = "spec-coach";
/** taskType 枚举(接口文档) */
export const TASK_TYPE_NAME_MAP = {
[STAFF_REPLACE_ACCESS_TYPE]: "人员更换评估",
"policy-update-access": "商务政策更新评估",
"scene-expand": "多品类扩张",
"traffic-optimize": "流量问题改善",
[SUPERVISE_TEACH_TYPE]: "督导带教",
};
/** 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: "createTimeText" },
{ label: "任务描述", key: "descriptionText", ellipsis: true },
{ label: "专项任务回复", key: "replyText", ellipsis: true },
];
const STAFF_NAMES_LIST_FIELD = { label: "问题驻店销售", key: "staffNames" };
const TARGET_TOUCH_RATE_FIELD = { label: "目标触客率", key: "targetCustomerContactRate", isBlue: true };
/** 督导带教:列表字段(带教目标、归属门店、带教方式、完成时间) */
const SUPERVISE_TEACH_LIST_FIELDS = [
{ label: "带教目标", key: "teachingTarget" },
{ label: "归属门店", key: "storeName" },
{ label: "带教方式", key: "teachingMethodName" },
{ label: "完成时间", key: "replyTime" },
];
/** 列表展示字段:不同任务类型插入不同字段 */
export function getMatterListFields(taskType, completed = false) {
// 督导带教:使用完全不同的字段列表
if (taskType === SUPERVISE_TEACH_TYPE) {
return SUPERVISE_TEACH_LIST_FIELDS.map((f) => ({ ...f }));
}
const base = completed ? MATTER_LIST_COMPLETED_FIELDS : MATTER_LIST_FIELDS;
const fields = base.map((f) => ({ ...f }));
// 人员更换评估:插入问题驻店销售
if (taskType === STAFF_REPLACE_ACCESS_TYPE) {
fields.splice(2, 0, {
...STAFF_NAMES_LIST_FIELD,
ellipsis: !completed,
});
}
// 流量问题改善:插入目标触客率
if (taskType === TRAFFIC_OPTIMIZE_TYPE) {
fields.splice(2, 0, {
...TARGET_TOUCH_RATE_FIELD,
ellipsis: !completed,
});
}
return fields;
}
/** 详情展示字段:不同任务类型插入不同字段 */
export function getMatterDetailFields(taskType) {
// 督导带教:使用完全不同的字段列表
if (taskType === SUPERVISE_TEACH_TYPE) {
return SUPERVISE_TEACH_LIST_FIELDS.map((f) => ({ ...f }));
}
const fields = MATTER_DETAIL_FIELDS.map((f) => ({ ...f }));
// 人员更换评估:插入问题驻店销售
if (taskType === STAFF_REPLACE_ACCESS_TYPE) {
fields.splice(2, 0, { ...STAFF_NAMES_LIST_FIELD });
}
// 流量问题改善:插入目标触客率
if (taskType === TRAFFIC_OPTIMIZE_TYPE) {
fields.splice(2, 0, { ...TARGET_TOUCH_RATE_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 overdue = statusKey === 2 || statusKey === "2";
const statusStyle = completed ? MATTER_STATUS_MAP[1] : overdue ? MATTER_STATUS_MAP[2] : MATTER_STATUS_MAP[0];
const staffList = Array.isArray(dto.staffList) ? dto.staffList : [];
const staffNames = formatStaffList(staffList);
// 格式化目标触客率,加上百分号
const targetCustomerContactRateValue = dto.targetCustomerContactRate != null && dto.targetCustomerContactRate !== "" ? `${dto.targetCustomerContactRate}%` : "-";
// 带教目标加上百分号
const teachingTarget = dto.teachingTarget != null && dto.teachingTarget !== "" ? `${dto.teachingTarget}%` : "-"
// 格式化督导带教的完成时间
const teachCompleteTimeValue = dto.teachCompleteTime || "-";
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,
targetCustomerContactRate: targetCustomerContactRateValue,
/** 督导带教:带教目标、带教方式、完成时间 */
teachTarget: dto.teachTarget || "-",
teachMethod: dto.teachMethod || "-",
teachCompleteTime: teachCompleteTimeValue,
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 ? "已完成" : overdue ? "已逾期" : "待完成",
statusStyle,
completed,
overdue,
showAction: !completed && !overdue,
showView: completed || overdue,
listFields: getMatterListFields(dto.taskType, false),
completedListFields: getMatterListFields(dto.taskType, true),
teachingTarget: teachingTarget
};
}
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,
};
}