appointmentHelper.js
7.13 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
/** 预约状态:后端中文 ↔ 管理端/门店 PC 日历 UI */
export function pickRowField(row, ...keys) {
if (!row) return undefined
for (let i = 0; i < keys.length; i++) {
const v = row[keys[i]]
if (v !== undefined && v !== null && v !== '') return v
}
return undefined
}
export function parseApiDateTime(val) {
if (val == null || val === '') return null
if (val instanceof Date) return Number.isNaN(val.getTime()) ? null : val
if (typeof val === 'number') {
const d = new Date(val)
return Number.isNaN(d.getTime()) ? null : d
}
const str = String(val).trim()
if (!str) return null
if (/^\d+$/.test(str)) {
const d = new Date(Number(str))
return Number.isNaN(d.getTime()) ? null : d
}
const normalized = str.replace('T', ' ').replace(/-/g, '/')
const d = new Date(normalized)
if (!Number.isNaN(d.getTime())) return d
const d2 = new Date(str)
return Number.isNaN(d2.getTime()) ? null : d2
}
/** 后端 LqYyjl 列表 yysj 范围:毫秒时间戳,毫秒时间戳 */
export function buildYysjTimestampRange(startDate, endDate) {
const s = parseApiDateTime(startDate)
const e = parseApiDateTime(endDate)
if (!s || !e) return ''
return [s.getTime(), e.getTime()].join(',')
}
export function apiStatusToUi(fStatus) {
const s = (fStatus || '').trim()
if (s === '已预约' || s === '已确认') return 'booked'
if (s === '服务中') return 'serving'
if (s === '已转耗卡' || s === '已完成') return 'converted'
if (s === '已取消') return 'cancelled'
return 'booked'
}
export function uiStatusToApi(uiStatus) {
if (uiStatus === 'booked') return '已预约'
if (uiStatus === 'serving') return '服务中'
if (uiStatus === 'converted') return '已完成'
if (uiStatus === 'cancelled') return '已取消'
return ''
}
export function statusText(uiOrApi) {
const ui = apiStatusToUi(uiOrApi) === 'booked' && !['booked', 'serving', 'converted', 'cancelled'].includes(uiOrApi)
? uiOrApi
: apiStatusToUi(uiOrApi)
if (ui === 'booked' || uiOrApi === '已预约') return '已预约'
if (ui === 'serving' || uiOrApi === '服务中') return '服务中'
if (ui === 'converted' || uiOrApi === '已完成' || uiOrApi === '已转耗卡') return '已完成'
if (ui === 'cancelled' || uiOrApi === '已取消') return '已取消'
return uiOrApi || '无'
}
/** 是否应展示关联耗卡(已转耗卡/已完成或存在有效耗卡) */
export function hasLinkedConsume(row) {
if (!row) return false
if (pickRowField(row, 'consumeId', 'ConsumeId')) return true
if (pickRowField(row, 'hasEffectiveConsume', 'HasEffectiveConsume')) return true
const fStatus = pickRowField(row, 'F_Status', 'fStatus', 'f_Status', 'status')
return apiStatusToUi(fStatus) === 'converted'
}
export function mapRelatedConsumeList(list) {
return (list || []).map(item => ({
id: pickRowField(item, 'id', 'Id') || '',
hksj: pickRowField(item, 'hksj', 'Hksj'),
xfje: pickRowField(item, 'xfje', 'Xfje'),
hymc: pickRowField(item, 'hymc', 'Hymc') || '无'
})).filter(item => item.id)
}
export function formatDateYMD(d) {
const dt = d instanceof Date ? d : parseApiDateTime(d)
if (!dt) return ''
const y = dt.getFullYear()
const m = String(dt.getMonth() + 1).padStart(2, '0')
const day = String(dt.getDate()).padStart(2, '0')
return `${y}-${m}-${day}`
}
export function formatTimeHM(dt) {
if (!dt) return ''
const d = dt instanceof Date ? dt : parseApiDateTime(dt)
if (!d) {
const str = String(dt)
if (str.includes(' ')) {
const part = str.split(' ')[1] || ''
return part.substring(0, 5)
}
return str.length >= 5 ? str.substring(0, 5) : ''
}
return `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`
}
export function mapYyjlListRow(row) {
const yysj = pickRowField(row, 'yysj', 'Yysj')
const yyjs = pickRowField(row, 'yyjs', 'Yyjs')
const fStatus = pickRowField(row, 'F_Status', 'f_Status', 'fStatus')
const date = formatDateYMD(yysj)
const startTime = formatTimeHM(yysj)
const endTime = formatTimeHM(yyjs)
const status = apiStatusToUi(fStatus)
return {
id: pickRowField(row, 'id', 'Id', 'F_Id'),
memberId: pickRowField(row, 'gk', 'Gk'),
memberName: pickRowField(row, 'gkxm', 'Gkxm') || '无',
date,
startTime,
endTime,
timeRange: startTime && endTime ? `${startTime}-${endTime}` : '',
roomId: pickRowField(row, 'roomId', 'RoomId', 'F_RoomId') || '',
roomName: pickRowField(row, 'roomName', 'RoomName', 'F_RoomName') || '',
therapistIds: pickRowField(row, 'yyjks', 'Yyjks') ? [pickRowField(row, 'yyjks', 'Yyjks')] : [],
therapistNames: pickRowField(row, 'yyjksName', 'YyjksName') ? [pickRowField(row, 'yyjksName', 'YyjksName')] : [],
staffName: pickRowField(row, 'yyjksName', 'YyjksName') || '无',
yyr: pickRowField(row, 'yyr', 'Yyr') || '',
yyrName: pickRowField(row, 'yyrName', 'YyrName') || '无',
storeId: pickRowField(row, 'djmd', 'Djmd') || '',
storeName: pickRowField(row, 'djmdName', 'DjmdName') || '',
project: pickRowField(row, 'yytyxm', 'Yytyxm') || pickRowField(row, 'gkxm', 'Gkxm') || '无',
status,
fStatus: fStatus,
remark: pickRowField(row, 'remark', 'Remark', 'F_Remark') || '',
InviteId: pickRowField(row, 'InviteId', 'inviteId') || '',
projectSummary: pickRowField(row, 'projectSummary', 'ProjectSummary') || '',
consumeId: pickRowField(row, 'consumeId', 'ConsumeId') || '',
hasEffectiveConsume: !!pickRowField(row, 'hasEffectiveConsume', 'HasEffectiveConsume'),
mobile: '',
items: [],
itemLabels: row.yytyxm ? [row.yytyxm] : [],
colorKey: 'blue'
}
}
export function mapYyjlInfoToFormRecord(info, pxList = []) {
const date = formatDateYMD(info.yysj)
const items = (pxList || []).map(px => ({
projectId: px.billingItemId || px.px,
itemId: px.px,
billingItemId: px.billingItemId,
label: px.pxmc,
count: Number(px.projectNumber) || 1,
workers: (px.jksList || []).map(j => ({ workerId: j.jks, workerName: j.jksxm }))
}))
const itemLabels = items.map(x => `${x.label}×${x.count}`)
const therapistIds = []
const therapistNames = []
items.forEach(it => {
;(it.workers || []).forEach(w => {
if (w.workerId && !therapistIds.includes(w.workerId)) {
therapistIds.push(w.workerId)
therapistNames.push(w.workerName || w.workerId)
}
})
})
if (!therapistIds.length && info.yyjks) {
therapistIds.push(info.yyjks)
therapistNames.push(info.yyjksName || info.yyjks)
}
return {
id: info.id,
memberId: info.gk,
memberName: info.gkxm || '无',
storeId: info.djmd,
storeName: info.djmdName || '无',
yyr: info.yyr,
yyrName: info.yyrName || '无',
date,
startTime: formatTimeHM(info.yysj),
endTime: formatTimeHM(info.yyjs),
roomId: info.roomId,
roomName: info.roomName || '无',
remark: info.remark || '',
status: apiStatusToUi(info.F_Status),
fStatus: info.F_Status,
InviteId: info.InviteId || '',
consumeId: info.consumeId || '',
hasEffectiveConsume: !!info.hasEffectiveConsume,
relatedConsumes: mapRelatedConsumeList(info.relatedConsumeList),
items,
itemLabels,
therapistIds,
therapistNames
}
}