统一项目命名并接回MinIO三副本存储
This commit is contained in:
@@ -1,12 +1,31 @@
|
||||
const planningApi = require('../../api/planning')
|
||||
const productsApi = require('../../api/products')
|
||||
const mock = require('../../utils/mock')
|
||||
const dateUtil = require('../../utils/date')
|
||||
|
||||
function buildClientRequestId(prefix) {
|
||||
return `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`
|
||||
}
|
||||
|
||||
function getCalendarArtists(calendar) {
|
||||
return calendar && Array.isArray(calendar.artists) ? calendar.artists : []
|
||||
}
|
||||
|
||||
function findArtist(artists, artistId) {
|
||||
return artists.find(item => String(item.id) === String(artistId)) || {}
|
||||
}
|
||||
|
||||
function isScheduleCoveringTime(schedule, form, startMinute, endMinute) {
|
||||
if (!schedule || String(schedule.artistId) !== String(form.artistId) || schedule.date !== form.appointmentDate) {
|
||||
return false
|
||||
}
|
||||
if (schedule.status !== 1 || Number(schedule.capacity || 0) < 1) {
|
||||
return false
|
||||
}
|
||||
const scheduleStartMinute = dateUtil.minutesOfDay(String(schedule.startTime || '').slice(0, 5))
|
||||
const scheduleEndMinute = dateUtil.minutesOfDay(String(schedule.endTime || '').slice(0, 5))
|
||||
return scheduleStartMinute <= startMinute && scheduleEndMinute >= endMinute
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
form: {
|
||||
@@ -20,7 +39,7 @@ Page({
|
||||
remark: ''
|
||||
},
|
||||
products: [],
|
||||
artists: mock.artists,
|
||||
artists: [],
|
||||
selectedProduct: {},
|
||||
selectedArtist: {},
|
||||
conflictTip: '',
|
||||
@@ -49,21 +68,29 @@ Page({
|
||||
} catch (error) {
|
||||
this.setData({ products: fallbackProducts })
|
||||
}
|
||||
if (this.data.form.artistId) {
|
||||
const selectedArtist = this.data.artists.find(item => String(item.id) === String(this.data.form.artistId)) || {}
|
||||
this.setData({ selectedArtist })
|
||||
}
|
||||
await this.loadArtists()
|
||||
this.checkAvailability()
|
||||
},
|
||||
|
||||
async loadArtists() {
|
||||
const calendar = await planningApi.calendar({
|
||||
startDate: this.data.form.appointmentDate,
|
||||
endDate: this.data.form.appointmentDate
|
||||
})
|
||||
const artists = getCalendarArtists(calendar)
|
||||
const selectedArtist = this.data.form.artistId ? findArtist(artists, this.data.form.artistId) : {}
|
||||
this.setData({ artists, selectedArtist })
|
||||
},
|
||||
|
||||
onInput(event) {
|
||||
this.setData({
|
||||
[`form.${event.currentTarget.dataset.field}`]: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
onDateChange(event) {
|
||||
async onDateChange(event) {
|
||||
this.setData({ 'form.appointmentDate': event.detail.value })
|
||||
await this.loadArtists()
|
||||
this.checkAvailability()
|
||||
},
|
||||
|
||||
@@ -106,15 +133,16 @@ Page({
|
||||
return { ok: false, tip }
|
||||
}
|
||||
try {
|
||||
let calendar
|
||||
try {
|
||||
calendar = await planningApi.calendar({
|
||||
startDate: form.appointmentDate,
|
||||
endDate: form.appointmentDate,
|
||||
artistId: form.artistId
|
||||
})
|
||||
} catch (error) {
|
||||
calendar = mock.buildCalendar(form.appointmentDate)
|
||||
const calendar = await planningApi.calendar({
|
||||
startDate: form.appointmentDate,
|
||||
endDate: form.appointmentDate,
|
||||
artistId: form.artistId
|
||||
})
|
||||
const schedule = (calendar.schedules || []).find(item => isScheduleCoveringTime(item, form, startMinute, endMinute))
|
||||
if (!schedule) {
|
||||
const tip = `${this.data.selectedArtist.name || '该美甲师'} 当前时段无可预约排班`
|
||||
this.setData({ conflictTip: tip, conflictLevel: 'danger' })
|
||||
return { ok: false, tip }
|
||||
}
|
||||
const conflicts = (calendar.appointments || []).filter(item => {
|
||||
if (String(item.artistId) !== String(form.artistId) || item.date !== form.appointmentDate) return false
|
||||
@@ -156,8 +184,8 @@ Page({
|
||||
try {
|
||||
const result = await planningApi.createAppointment({
|
||||
...form,
|
||||
productId: Number(form.productId),
|
||||
artistId: Number(form.artistId),
|
||||
productId: String(form.productId),
|
||||
artistId: String(form.artistId),
|
||||
durationMinutes: Number(form.durationMinutes || 0) || undefined,
|
||||
clientRequestId: buildClientRequestId('manager-appointment')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user