30cad4e765
- 时间线位置 /30 改为 /60 - 价格预览改为按格子累加 slot_prices - 格子内显示价格(¥xx) - 新增 locked(锁场)和 no_price(无价格)格子状态 - API映射层移除 unit_price,新增 slot_prices 和 source_type - 确认页半小时段改为时段
126 lines
3.9 KiB
JavaScript
126 lines
3.9 KiB
JavaScript
import { request } from './request'
|
|
import { compactParams, toArray, toNumber } from './mappers'
|
|
import { toPrivateBooking } from './booking'
|
|
import { toOrderBrief } from './order'
|
|
|
|
const toQuoteCourt = (backendCourt = {}) => ({
|
|
id: backendCourt.id ?? null,
|
|
name: backendCourt.name || '',
|
|
court_type: backendCourt.court_type || '',
|
|
court_type_label: backendCourt.court_type_label || ''
|
|
})
|
|
|
|
const toQuoteItem = (backendItem = {}) => ({
|
|
court_id: backendItem.court_id ?? null,
|
|
court_name: backendItem.court_name || '',
|
|
start_at: backendItem.start_at || '',
|
|
end_at: backendItem.end_at || '',
|
|
unit_count: toNumber(backendItem.unit_count),
|
|
amount: backendItem.amount || '0.00'
|
|
})
|
|
|
|
const toPrivateQuote = (backendQuote = {}) => ({
|
|
amount: backendQuote.amount || '0.00',
|
|
unit_count: toNumber(backendQuote.unit_count),
|
|
start_at: backendQuote.start_at || '',
|
|
end_at: backendQuote.end_at || '',
|
|
courts: toArray(backendQuote.courts).map(toQuoteCourt),
|
|
items: toArray(backendQuote.items).map(toQuoteItem)
|
|
})
|
|
|
|
const toPrivateCreateResult = (backendData = {}) => ({
|
|
booking: toPrivateBooking(backendData.booking),
|
|
order: toOrderBrief(backendData.order)
|
|
})
|
|
|
|
const toPrivateTimeOption = (backendOption = {}) => ({
|
|
start_at: backendOption.start_at || '',
|
|
end_at: backendOption.end_at || '',
|
|
available_court_count: toNumber(backendOption.available_court_count),
|
|
available_courts: toArray(backendOption.available_courts).map(toQuoteCourt)
|
|
})
|
|
|
|
const toPrivateBookingOptions = (backendData = {}) => ({
|
|
date: backendData.date || '',
|
|
court_type: backendData.court_type || '',
|
|
court_type_label: backendData.court_type_label || '',
|
|
open_time: backendData.open_time || '',
|
|
close_time: backendData.close_time || '',
|
|
duration_units: toNumber(backendData.duration_units, 1),
|
|
duration_minutes: toNumber(backendData.duration_minutes, 60),
|
|
total_court_count: toNumber(backendData.total_court_count),
|
|
time_options: toArray(backendData.time_options).map(toPrivateTimeOption)
|
|
})
|
|
|
|
const toGridCourt = (backendCourt = {}) => ({
|
|
id: backendCourt.id ?? null,
|
|
name: backendCourt.name || ''
|
|
})
|
|
|
|
const toGridSlot = (backendSlot = {}) => ({
|
|
start: backendSlot.start || '',
|
|
end: backendSlot.end || ''
|
|
})
|
|
|
|
const toGridOccupation = (backendOcc = {}) => ({
|
|
court_id: backendOcc.court_id ?? null,
|
|
start_at: backendOcc.start_at || '',
|
|
end_at: backendOcc.end_at || '',
|
|
source_type: backendOcc.source_type || ''
|
|
})
|
|
|
|
const toPrivateBookingGrid = (backendData = {}) => ({
|
|
date: backendData.date || '',
|
|
court_type: backendData.court_type || '',
|
|
court_type_label: backendData.court_type_label || '',
|
|
open_time: backendData.open_time || '',
|
|
close_time: backendData.close_time || '',
|
|
courts: toArray(backendData.courts).map(toGridCourt),
|
|
time_slots: toArray(backendData.time_slots).map(toGridSlot),
|
|
occupations: toArray(backendData.occupations).map(toGridOccupation),
|
|
slot_prices: backendData.slot_prices || {}
|
|
})
|
|
|
|
export const privateBookingApi = {
|
|
getPrivateBookingOptions(params = {}) {
|
|
return request({
|
|
url: '/api/bookings/private/options',
|
|
data: compactParams({
|
|
date: params.date,
|
|
court_type: params.courtType || params.court_type,
|
|
duration_units: params.durationUnits || params.duration_units
|
|
})
|
|
}).then(toPrivateBookingOptions)
|
|
},
|
|
|
|
getPrivateBookingGrid(params = {}) {
|
|
return request({
|
|
url: '/api/bookings/private/grid',
|
|
data: compactParams({
|
|
date: params.date,
|
|
court_type: params.courtType || params.court_type
|
|
})
|
|
}).then(toPrivateBookingGrid)
|
|
},
|
|
|
|
quotePrivateBooking(payload = {}) {
|
|
return request({
|
|
url: '/api/bookings/private/quote',
|
|
method: 'POST',
|
|
data: {
|
|
items: toArray(payload.items)
|
|
}
|
|
}).then(toPrivateQuote)
|
|
},
|
|
|
|
createPrivateBooking(payload = {}) {
|
|
return request({
|
|
url: '/api/bookings/private',
|
|
method: 'POST',
|
|
data: {
|
|
items: toArray(payload.items)
|
|
}
|
|
}).then(toPrivateCreateResult)
|
|
}
|
|
}
|