orderListRowDisplay.js
11 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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
import dayjs from "dayjs";
const CUSTOMER_TAG_MAP = {
1: "已触客",
2: "已拉群",
3: "已交付引荐",
4: "首保维保客户",
5: "事故车客户",
};
const SALES_TYPE_MAP = {
0: "销售端引流 - 售前",
1: "门店引流 - 售后",
2: "自然到店",
3: "交付端引流 - 售前",
};
const ORDER_SOURCE_MAP = {
7: "系统导入",
12: "冀联小程序",
};
const CAR_DAMAGE_SALES_TYPE_MAP = {
0: "门店引流 - 售前",
1: "门店引流 - 售后",
2: "自然到店",
};
/**
* @param {object} [row]
* @param {boolean} [authFlag]
* @returns {boolean} 是否显示订单审批按钮
*/
export function canShowOrderApprovalButton(row, authFlag = false) {
return Number(row?.goodsOrderApplyStatus) === 2
&& (Number(row?.canApplyFlag) === 1 || Boolean(authFlag));
}
/**
* @param {string|number|null|undefined} value
* @returns {string} 格式化后的中文标签
*/
export function formatCustomerTags(value) {
if (value == null || String(value).trim() === "") {
return "-";
}
return String(value)
.split(/[,,]/)
.map(item => item.trim())
.filter(Boolean)
.map(item => CUSTOMER_TAG_MAP[item] || item)
.join(",") || "-";
}
/**
* @param {string|number|null|undefined} value
* @returns {string} 格式化后的交付日期
*/
export function formatActualDeliveryDate(value) {
if (value == null || value === "") {
return "-";
}
const result = dayjs(value).format("YYYY-MM-DD");
return result === "Invalid Date" ? "-" : result;
}
/**
* @param {string} [text]
* @param {number} [maxLen]
* @returns {string} 截断后的展示文本
*/
export function truncateDisplay(text, maxLen = 10) {
if (!text) {
return "-";
}
return text.length > maxLen ? `${text.substring(0, maxLen)}...` : text;
}
/**
* @param {object} [item]
* @returns {string} 商品类目名称
*/
export function getGoodsTypeName(item) {
const {
upgradeGoodsTypeName,
upgradeSecondaryGoodsTypeName,
upgradeThirdLevelGoodsTypeName,
} = item || {};
return [
upgradeGoodsTypeName,
upgradeSecondaryGoodsTypeName,
upgradeThirdLevelGoodsTypeName,
].filter(Boolean).join("-");
}
/**
* @param {object} item
* @param {Array<{ position: string|number, confName: string }>} positionTypeList
* @returns {object} 商品展示信息
*/
export function mapSubOrderDisplayItem(item, positionTypeList) {
const goodsTypeFull = getGoodsTypeName(item);
const goodsNameFull = item.upgradeGoodsId
? (item.upgradeGoodsName || "-")
: (item.baseGoodsName || "-");
const unitPrice = item.upgradeGoodsId
? item.upgradePrice
: item.baseRetailPrice;
const salesPrice = item.upgradeGoodsId
? item.singleProductSalesPrice
: item.baseRetailPrice;
const finalUnitPrice = item.upgradeGoodsId
? item.singleProductFinalPrice
: item.baseRetailPrice;
const positionStr = positionTypeList?.filter(
sub => String(sub?.position) === String(item?.upgradeGoodsPosition),
)[0]?.confName || item.positionStr || "-";
return {
...item,
positionStr,
goodsNameFull,
goodsNameDisplay: truncateDisplay(goodsNameFull),
goodsTypeFull,
goodsTypeDisplay: truncateDisplay(goodsTypeFull),
unitPriceDisplay: unitPrice != null ? `¥ ${unitPrice}` : "-",
salesPriceDisplay: salesPrice != null ? `¥ ${salesPrice}` : "-",
finalUnitPriceDisplay: finalUnitPrice != null ? `¥ ${finalUnitPrice}` : "-",
numberDisplay: item.upgradeGoodsId ? String(item.number ?? "-") : "-",
discountDisplay: `¥${item.discountAmount || 0}`,
warrantyDisplay: item.upgradeWarrantyPeriod
? `${item.upgradeWarrantyPeriod}年`
: "无",
aliasDisplay: item.upgradeGoodsAlias || "-",
};
}
/**
* @param {Array<{ goodsNameFull: string }>} subOrderDisplayList
* @returns {string} 商品名称汇总
*/
function getGoodsNamesDisplay(subOrderDisplayList) {
return subOrderDisplayList
.map(item => item.goodsNameFull)
.filter(name => name && name !== "-")
.join("、") || "-";
}
/**
* @param {object} row
* @param {object} ctx
* @param {object} ctx.maps
* @returns {object} 精品订单行展示信息
*/
export function mapOrderListRow(row, ctx) {
const {
statusOpts = {},
upgradeOpts = {},
profitAllocationStatusOpts = {},
invoiceStatusOpts = {},
saleFlagTextObj = {},
djOrderTypeMap = {},
auditStatusMap = {},
positionTypeList = [],
} = ctx.maps || {};
const subOrderDisplayList = (row.subOrderList || []).map(item =>
mapSubOrderDisplayItem(item, positionTypeList),
);
const packageNamesDisplay = (row.packageGoodsList || [])
.map(p => p.packageName)
.filter(Boolean)
.join("、");
const carParts = [
row.carBrand,
row.carChildsBrandName ? `-${row.carChildsBrandName}` : "",
row.carSeriesName ? `-${row.carSeriesName}` : "",
].filter(Boolean);
const carTypeDisplay = carParts.join("") || "-";
let refundDetailDisplay = "-";
if (Number(row.status) === 12) {
const typeLabel = String(row.refundType) === "1" ? "退全款" : "退部分款";
refundDetailDisplay = `${typeLabel} ¥${row.refundAmount || 0}`;
}
const salesTypeNum = Number(row.salesType);
const salesTypeLabel = SALES_TYPE_MAP[salesTypeNum] !== undefined
? SALES_TYPE_MAP[salesTypeNum]
: "-";
return {
...row,
paySuccessDate: row.paySuccessDate || "",
customerTagsDisplay: formatCustomerTags(row.customerTags),
actualDeliveryDateDisplay: formatActualDeliveryDate(row.actualDeliveryDate),
subOrderDisplayList,
goodsNamesDisplay: getGoodsNamesDisplay(subOrderDisplayList),
packageNamesDisplay: packageNamesDisplay || "-",
djOrderTypeLabel: row.djOrderType ? (djOrderTypeMap[row.djOrderType] || "-") : "-",
goodsOrderApplyStatusLabel: row.goodsOrderApplyStatus
? (auditStatusMap[row.goodsOrderApplyStatus] || "-")
: "-",
incorrectOrderCodeDisplay: row.incorrectOrderCode || "-",
customerSexLabel: Number(row.customerSex) === 1 ? "男" : "女",
carTypeDisplay,
upgradeFlagLabel: row.upgradeFlag
? (upgradeOpts[row.upgradeFlag] || "待升级")
: "待升级",
statusLabel: statusOpts[row.status] || "-",
profitAllocationStatusLabel:
profitAllocationStatusOpts[row.profitAllocationStatus] || "-",
invoiceStatusLabel: invoiceStatusOpts[row.invoiceStatus] || "-",
totalPriceDisplay: row.totalPrice != null ? `¥${row.totalPrice}` : "",
finalPriceDisplay: row.finalPrice != null ? `¥${row.finalPrice}` : "",
refundDetailDisplay,
directSalesFlagLabel: row.directSalesFlag != null
? (saleFlagTextObj[row.directSalesFlag] || "-")
: "-",
subShopMerchantNameDisplay: row.subShopMerchantName || "-",
orderSourceLabel: ORDER_SOURCE_MAP[row.source] || "小程序订单",
salesTypeLabel,
subOrderCount: subOrderDisplayList.length,
};
}
/**
* @param {object} opt
* @returns {string} 权益场景名称
*/
function rightsSceneRowLabel(opt) {
if (!opt) {
return "-";
}
return opt.name || opt.subTypeName || opt.num || opt.baseSceneCode || "-";
}
/**
* @param {object} [row]
* @param {Array<object>} [sceneList]
* @returns {string} 权益场景展示名称
*/
export function resolveRightsSceneLabel(row, sceneList) {
if (row === null || row === undefined) {
return "-";
}
const key = String(row.baseSceneCode == null ? "" : row.baseSceneCode).trim();
if (key) {
const list = sceneList || [];
const opt = list.find(
s => String((s && s.baseSceneCode) || "").trim() === key,
);
if (opt) {
return rightsSceneRowLabel(opt);
}
return key;
}
const nm = row.baseSceneName != null ? row.baseSceneName : row.sceneName;
if (nm !== null && nm !== undefined && String(nm).trim() !== "") {
return String(nm).trim();
}
return "-";
}
/**
* @param {object} item
* @param {Array<{ position: string|number, confName: string }>} positionTypeList
* @returns {object} 权益商品展示信息
*/
export function mapCarDamageSubOrderDisplayItem(item, positionTypeList) {
const base = mapSubOrderDisplayItem(item, positionTypeList);
const packageAliasFull = item.packageAlias || "";
const couponNameFull = item.coupon?.couponName || "";
return {
...base,
packageNameDisplay: item.packageName || "-",
packageAliasFull,
packageAliasDisplay: truncateDisplay(packageAliasFull),
couponCodeDisplay: item.coupon?.customerCouponCode || "-",
couponNameFull,
couponNameDisplay: couponNameFull ? truncateDisplay(couponNameFull) : "-",
couponAmountDisplay: item.coupon?.discountPrice != null
? String(item.coupon.discountPrice)
: "-",
};
}
/**
* @param {object} row
* @param {object} ctx
* @param {object} ctx.maps
* @returns {object} 权益订单行展示信息
*/
export function mapCarDamageListRow(row, ctx) {
const {
statusOpts = {},
upgradeOpts = {},
profitAllocationStatusOpts = {},
invoiceStatusOpts = {},
saleFlagTextObj = {},
djOrderTypeMap = {},
auditStatusMap = {},
positionTypeList = [],
rightsSceneListForSearch = [],
zyVoucherStatusOpts = {},
} = ctx.maps || {};
const subOrderDisplayList = (row.subOrderList || []).map(item =>
mapCarDamageSubOrderDisplayItem(item, positionTypeList),
);
const carParts = [
row.carBrand,
row.carChildsBrandName ? `-${row.carChildsBrandName}` : "",
row.carSeriesName ? `-${row.carSeriesName}` : "",
].filter(Boolean);
const carTypeDisplay = carParts.join("") || "-";
let refundDetailDisplay = "-";
if (Number(row.status) === 12) {
const typeLabel = String(row.refundType) === "1" ? "退全款" : "退部分款";
refundDetailDisplay = `${typeLabel} ¥${row.refundAmount || 0}`;
}
const salesTypeNum = Number(row.salesType);
const salesTypeLabel = CAR_DAMAGE_SALES_TYPE_MAP[salesTypeNum] !== undefined
? CAR_DAMAGE_SALES_TYPE_MAP[salesTypeNum]
: "-";
let customerSexLabel = "-";
if (row.customerSex) {
customerSexLabel = Number(row.customerSex) === 1 ? "男" : "女";
}
return {
...row,
paySuccessDate: row.paySuccessDate || "",
customerTagsDisplay: formatCustomerTags(row.customerTags),
actualDeliveryDateDisplay: formatActualDeliveryDate(row.actualDeliveryDate),
subOrderDisplayList,
goodsNamesDisplay: getGoodsNamesDisplay(subOrderDisplayList),
djOrderTypeLabel: row.djOrderType ? (djOrderTypeMap[row.djOrderType] || "-") : "-",
goodsOrderApplyStatusLabel: row.goodsOrderApplyStatus
? (auditStatusMap[row.goodsOrderApplyStatus] || "-")
: "-",
incorrectOrderCodeDisplay: row.incorrectOrderCode || "-",
rightsSceneDisplayLabel: resolveRightsSceneLabel(
row,
rightsSceneListForSearch,
),
customerSexLabel,
carTypeDisplay,
upgradeFlagLabel: row.upgradeFlag
? (upgradeOpts[row.upgradeFlag] || "待升级")
: "待升级",
statusLabel: statusOpts[row.status] || "-",
profitAllocationStatusLabel:
profitAllocationStatusOpts[row.profitAllocationStatus] || "-",
invoiceStatusLabel: invoiceStatusOpts[row.invoiceStatus] || "-",
zyVoucherStatusLabel: zyVoucherStatusOpts[row.zyVoucherStatus] || "-",
totalPriceDisplay: row.totalPrice != null ? `¥${row.totalPrice}` : "",
finalPriceDisplay: row.finalPrice != null ? `¥${row.finalPrice}` : "",
refundDetailDisplay,
directSalesFlagLabel: row.directSalesFlag != null
? (saleFlagTextObj[row.directSalesFlag] || "-")
: "-",
subShopMerchantNameDisplay: row.subShopMerchantName || "-",
orderSourceLabel: ORDER_SOURCE_MAP[row.source] || "小程序订单",
salesTypeLabel,
subOrderCount: subOrderDisplayList.length,
};
}