boutiqueCustomerDailyDisplay.helpers.js
2.21 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
import { formatActualDeliveryDateForDisplay } from './actualDeliveryDate.helpers.js'
export const BOUTIQUE_CUSTOMER_TAGS = [
{ value: '1', label: '已触客' },
{ value: '2', label: '已拉群' },
{ value: '3', label: '已交付引荐' },
{ value: '4', label: '首保维保客户' },
{ value: '5', label: '事故车客户' }
]
const CUSTOMER_TAG_ORDER = BOUTIQUE_CUSTOMER_TAGS.map(item => item.value)
function toTagValues(value) {
if (Array.isArray(value)) return value
if (value === undefined || value === null || value === '') return []
return String(value).split(',')
}
export function parseCustomerTags(value, allowedValues = CUSTOMER_TAG_ORDER) {
const allowed = new Set((allowedValues || []).map(String))
const selected = new Set(
toTagValues(value)
.map(item => String(item).trim())
.filter(item => allowed.has(item))
)
return CUSTOMER_TAG_ORDER.filter(item => selected.has(item))
}
export function serializeCustomerTags(value, allowedValues = CUSTOMER_TAG_ORDER) {
return parseCustomerTags(value, allowedValues).join(',')
}
export function getCustomerTagLabels(value) {
const selected = new Set(parseCustomerTags(value))
return BOUTIQUE_CUSTOMER_TAGS.filter(item => selected.has(item.value)).map(
item => item.label
)
}
export function formatCustomerTags(value) {
return getCustomerTagLabels(value).join('/')
}
export function buildBoutiqueCustomerDailyDisplay(customer = {}) {
const source = customer || {}
const customerTagLabels = getCustomerTagLabels(source.customerTags)
const actualDeliveryDate = formatActualDeliveryDateForDisplay(
source.actualDeliveryDate
)
return {
showCustomerTags: customerTagLabels.length > 0,
showActualDeliveryDate: !!actualDeliveryDate,
customerTagLabels,
customerTagsText: customerTagLabels.join('/'),
actualDeliveryDate
}
}
export function buildBoutiqueCustomerDailyListDisplay(orderItem = {}) {
const source = orderItem || {}
const nestedCustomer = source.customer || {}
return buildBoutiqueCustomerDailyDisplay({
...nestedCustomer,
customerTags: nestedCustomer.customerTags || source.customerTags || '',
actualDeliveryDate:
nestedCustomer.actualDeliveryDate || source.actualDeliveryDate || ''
})
}