customerSnapshot.js
7.85 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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
const SNAPSHOT_KEY = "customerDetailSnapshot";
export const CUSTOMER_STATUS_LIST = [
{ confId: 1, confLabel: "待跟进" },
{ confId: 2, confLabel: "已升级" },
{ confId: 3, confLabel: "战败" },
{ confId: 4, confLabel: "已退款" },
];
export function buildCustomerStatusFilterOptions() {
return [
{ confId: "", confLabel: "全部" },
...CUSTOMER_STATUS_LIST,
];
}
export function saveCustomerSnapshot(row) {
if (!row) {
return;
}
try {
sessionStorage.setItem(SNAPSHOT_KEY, JSON.stringify(row));
} catch (err) {
// ignore quota errors
}
}
export function loadCustomerSnapshot() {
try {
const raw = sessionStorage.getItem(SNAPSHOT_KEY);
return raw ? JSON.parse(raw) : {};
} catch (err) {
return {};
}
}
/** 合并列表行快照与路由参数,客户分类仅来自列表数据 */
export function resolveCustomerRowFromRoute(route = {}, snapshotRow = {}) {
const row = { ...snapshotRow };
if (route.query && route.query.customerClass) {
row.customerClass = route.query.customerClass;
}
if (route.query && route.query.customerStatus !== undefined && route.query.customerStatus !== "") {
row.customerStatus = route.query.customerStatus;
}
return row;
}
function formatDateValue(value) {
if (!value) {
return "";
}
return new Date(value).toLocaleDateString();
}
export function formatCarModel(row = {}) {
const carModel = (row.carModel || "").trim();
if (carModel) {
return carModel;
}
const parts = [row.carBrand, row.carSeriesName, row.carTypeName]
.map(item => (item || "").trim())
.filter(Boolean);
return parts.length ? parts.join("-") : "";
}
export function formatCarModelForList(row = {}) {
const value = formatCarModel(row);
return value || "";
}
export function formatListPhone(row = {}) {
return row.customerPhone || row.mobile || row.phone || row.phoneNumber || "";
}
export function formatCustomerClass(row = {}) {
const customerClass = row.customerClass || row.customerCategory;
if (!customerClass) {
return "";
}
const normalized = String(customerClass).trim().toUpperCase();
if (normalized === "A" || normalized === "A类") {
return "A类";
}
if (normalized === "B" || normalized === "B类") {
return "B类";
}
if (normalized === "C" || normalized === "C类") {
return "C类";
}
return String(customerClass);
}
export function formatGroupStatus(row = {}) {
if (row.groupStatus === true || row.groupStatus === "已关联") {
return "已关联";
}
return "未关联";
}
export function formatDeliveryTime(row = {}) {
const time = row.deliveryDate;
return formatDateValue(time);
}
export function formatRecorder(row = {}) {
return row.userName || row.advanceUserName || row.createdBy || "";
}
export function formatReferrer(row = {}) {
return row.referrerName
|| row.employeeName
|| (row.order && row.order.employeeName)
|| "";
}
export function formatCustomerStatus(row = {}, statusList = CUSTOMER_STATUS_LIST) {
const customerStatus = row.customerStatus;
if (customerStatus == null || customerStatus === "") {
return "-";
}
const matched = statusList.find(item => Number(item.confId) === Number(customerStatus));
return matched ? matched.confLabel : "-";
}
export function formatServiceTime(row = {}) {
const time = row.order && row.order.installUpgradeTime;
if (!time) {
return "-";
}
return new Date(time).toLocaleDateString();
}
export function formatRemark(row = {}) {
if (!row.order) {
return "无";
}
if (row.order.upgradeFlag === "N") {
return row.order.customer
? (row.order.customer.refusalReason || "无")
: "无";
}
return row.order.remark || "无";
}
export function formatSource(row = {}) {
const source = row.order ? row.order.source : row.source;
if (source === 3) {
return "现场升级";
}
if (source === 5) {
return "核销抵扣";
}
if (source === 13) {
return "PAD录入";
}
return "系统录入";
}
export function formatCreateTime(row = {}) {
if (!row.createdDate) {
return "";
}
return formatDateValue(row.createdDate);
}
export function mapBasicInfoFromRow(row = {}, statusList = CUSTOMER_STATUS_LIST) {
const deliveryTime = formatDeliveryTime(row);
const referrer = formatReferrer(row);
const recorder = formatRecorder(row);
return {
customerName: row.customerName || "-",
mobile: formatListPhone(row) || "-",
customerCategory: formatCustomerClass(row) || "-",
carModel: formatCarModel(row) || "-",
customerStatus: formatCustomerStatus(row, statusList),
serviceTime: formatServiceTime(row),
remark: formatRemark(row),
trafficSource: row.merchantName || "-",
referrer: referrer || "-",
parkStore: row.yqMerchantName || "-",
conversionStaff: (row.order && row.order.sellerName) || "-",
groupRelInfo: formatGroupStatus(row),
createMethod: formatSource(row),
createTime: formatCreateTime(row) || "-",
deliveryTime: deliveryTime || "-",
recorder: recorder || "-",
};
}
function buildProfileCarModel(res = {}) {
const carModel = (res.carModel || "").trim();
if (carModel) {
return carModel;
}
const parts = [res.carBrand, res.carSeriesName]
.map(item => (item || "").trim())
.filter(Boolean);
return parts.length ? parts.join("-") : "";
}
export function mapProfileResponse(res = {}, snapshotRow = {}) {
const snapshotBasic = mapBasicInfoFromRow(snapshotRow);
const deliveryTime = res.deliveryDate
? formatDateValue(res.deliveryDate)
: snapshotBasic.deliveryTime;
const basicInfo = {
...snapshotBasic,
customerName: res.customerName || snapshotBasic.customerName,
mobile: res.customerPhone || snapshotBasic.mobile,
carModel: buildProfileCarModel(res) || snapshotBasic.carModel,
trafficSource: res.merchantName || snapshotBasic.trafficSource,
deliveryTime: deliveryTime || "-",
// 客户分类、客户状态仅来自列表接口,详情接口不返回
customerCategory: snapshotBasic.customerCategory,
customerStatus: snapshotBasic.customerStatus,
};
const consumptionTag = res.consumptionTag || {};
const productTag = res.productTag || {};
const behaviorTag = res.behaviorTag || {};
const consumptionDimensions = (consumptionTag.dimensions || []).map(dimension => ({
dimensionName: dimension.dimensionName || "-",
tags: (dimension.enumValues || []).map(item => item.enumName).filter(Boolean),
}));
const productDimensions = [];
const dealTags = (productTag.dealEnumValues || [])
.map(item => item.enumName)
.filter(Boolean);
if (dealTags.length) {
productDimensions.push({ dimensionName: "已成交品类", tags: dealTags });
}
const noDealTags = (productTag.noDealEnumValues || [])
.map(item => item.enumName)
.filter(Boolean);
if (noDealTags.length) {
productDimensions.push({ dimensionName: "未成交品类", tags: noDealTags });
}
const behaviorTagList = [];
(behaviorTag.dimensions || []).forEach((dimension) => {
(dimension.enumValues || []).forEach((enumValue) => {
behaviorTagList.push({
dimensionName: dimension.dimensionName || "-",
enumName: enumValue.enumName || "",
basis: enumValue.scoreBasis || "",
});
});
});
return {
basicInfo,
consumptionScore: consumptionTag.totalScore || 0,
consumptionDimensions,
productScore: productTag.totalScore || 0,
productDimensions,
behaviorScore: behaviorTag.totalScore || 0,
behaviorTagList,
};
}
export function mapGroupAssocResponse(res = {}, snapshotRow = {}) {
const snapshotBasic = mapBasicInfoFromRow(snapshotRow);
const groupRelStatus = res.groupStatus || "未关联";
const basicInfo = {
...snapshotBasic,
customerName: res.customerName || snapshotBasic.customerName,
mobile: res.customerPhone || snapshotBasic.mobile,
// 客户分类、客户状态仅来自列表接口,详情接口不返回
customerCategory: snapshotBasic.customerCategory,
customerStatus: snapshotBasic.customerStatus,
// 接口返回后同步基础信息中的群关联状态
groupRelInfo: groupRelStatus,
};
return {
basicInfo,
groupRelStatus,
groupName: res.qwGroupName || "",
groupMemberCustomer: res.wxName || "",
};
}