Files
JayuCloud/FingertipManager-Program/utils/mock.js
T

88 lines
2.9 KiB
JavaScript

const date = require('./date')
const artists = [
{ id: 101, name: '小王', shortName: '王', color: '#7BA7C7', status: 1, statusText: '可预约', rangeCount: 0 },
{ id: 102, name: '小李', shortName: '李', color: '#8FB89A', status: 1, statusText: '可预约', rangeCount: 0 },
{ id: 103, name: '小张', shortName: '张', color: '#A894C7', status: 1, statusText: '可预约', rangeCount: 0 }
]
function countFor(day, index) {
const seed = day.getDate() + index * 2 + day.getMonth()
if (seed % 7 === 0) return 0
return (seed % 4) + 1
}
function buildCalendar(currentDate) {
const start = date.startOfMonth(currentDate)
const end = date.endOfMonth(currentDate)
const daySummaries = []
const appointments = []
let cursor = new Date(start.getTime())
let orderItemId = 1
while (cursor <= end) {
const dateText = date.formatDate(cursor)
const artistCounts = artists.map((artist, index) => {
const count = countFor(cursor, index)
return {
artistId: artist.id,
artistName: artist.name,
shortName: artist.shortName,
color: artist.color,
count,
status: count >= 4 ? 'full' : count > 0 ? 'working' : 'free'
}
})
const totalCount = artistCounts.reduce((sum, item) => sum + item.count, 0)
daySummaries.push({
date: dateText,
totalCount,
artistCounts,
dayStatus: totalCount >= 8 ? 'full' : totalCount > 0 ? 'working' : 'free'
})
artistCounts.forEach((count, artistIndex) => {
for (let i = 0; i < Math.min(count.count, 3); i += 1) {
const startMinute = 10 * 60 + ((artistIndex * 90 + i * 110 + cursor.getDate() * 5) % 620)
const duration = i % 2 === 0 ? 90 : 60
const artist = artists[artistIndex]
appointments.push({
orderId: 9000 + orderItemId,
orderItemId,
customerName: ['王女士', '陈女士', '林女士', '赵女士'][i % 4],
customerPhone: '138****' + String(1000 + orderItemId).slice(-4),
productTitle: ['纯色美甲', '猫眼延长', '手部护理', '法式款'][i % 4],
artistId: artist.id,
artistName: artist.name,
artistColor: artist.color,
date: dateText,
startTime: `${dateText} ${date.timeFromMinutes(startMinute)}:00`,
endTime: `${dateText} ${date.timeFromMinutes(startMinute + duration)}:00`,
startMinute,
durationMinutes: duration,
status: i === 2 ? 0 : 1,
statusText: i === 2 ? '待确认' : '已确认',
remark: ''
})
orderItemId += 1
}
})
cursor = date.addDays(cursor, 1)
}
artists.forEach(artist => {
artist.rangeCount = appointments.filter(item => item.artistId === artist.id).length
})
return {
businessStartTime: '10:00',
businessEndTime: '22:00',
slotMinutes: 30,
artists,
schedules: [],
appointments,
daySummaries
}
}
module.exports = {
artists,
buildCalendar
}