优化店务小程序店铺设置和表单体验
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const planningApi = require('../../api/planning')
|
||||
const shopApi = require('../../api/shop')
|
||||
const dateUtil = require('../../utils/date')
|
||||
|
||||
const CALENDAR_ERROR_FALLBACK_MESSAGE = '规划数据暂时不可用,请稍后重试'
|
||||
@@ -98,6 +99,44 @@ function resolveDayStatusClass(items) {
|
||||
return ''
|
||||
}
|
||||
|
||||
function normalizeWorkDays(workDays, presetType) {
|
||||
if (presetType === 'DOUBLE_REST') {
|
||||
return [1, 2, 3, 4, 5]
|
||||
}
|
||||
if (presetType === 'SINGLE_REST') {
|
||||
return [1, 2, 3, 4, 5, 6]
|
||||
}
|
||||
if (presetType === 'EVERYDAY') {
|
||||
return [1, 2, 3, 4, 5, 6, 7]
|
||||
}
|
||||
const values = String(workDays || '')
|
||||
.split(',')
|
||||
.map(item => Number(String(item).trim()))
|
||||
.filter(item => item >= 1 && item <= 7)
|
||||
return Array.from(new Set(values.length ? values : [1, 2, 3, 4, 5, 6, 7]))
|
||||
}
|
||||
|
||||
function buildExceptionMap(exceptions) {
|
||||
return (exceptions || []).reduce((map, item) => {
|
||||
if (item && item.workDate) {
|
||||
map[item.workDate] = item.exceptionType
|
||||
}
|
||||
return map
|
||||
}, {})
|
||||
}
|
||||
|
||||
function isShopRestDate(date, workDays, exceptionMap) {
|
||||
const exceptionType = exceptionMap[date]
|
||||
if (exceptionType === 'REST') {
|
||||
return true
|
||||
}
|
||||
if (exceptionType === 'EXTRA_WORK' || exceptionType === 'CHANGE_SHIFT') {
|
||||
return false
|
||||
}
|
||||
const weekDay = toLocalDate(date).getDay() || 7
|
||||
return !workDays.includes(weekDay)
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
viewMode: 'month',
|
||||
@@ -126,6 +165,7 @@ Page({
|
||||
artists: [],
|
||||
appointments: [],
|
||||
daySummaries: [],
|
||||
shopRestDates: [],
|
||||
monthDays: [],
|
||||
weekDays: [],
|
||||
dayLanes: [],
|
||||
@@ -234,7 +274,8 @@ Page({
|
||||
endDate: range.end,
|
||||
artistId: this.data.selectedArtistId || undefined
|
||||
})
|
||||
this.applyCalendar(data)
|
||||
const shopSchedule = await this.loadShopSchedule(range)
|
||||
this.applyCalendar(data, shopSchedule)
|
||||
this.setData({ calendarError: '' })
|
||||
} catch (error) {
|
||||
this.clearCalendarView()
|
||||
@@ -259,6 +300,7 @@ Page({
|
||||
artists: [],
|
||||
appointments: [],
|
||||
daySummaries: [],
|
||||
shopRestDates: [],
|
||||
monthDays: [],
|
||||
weekDays: [],
|
||||
dayLanes: [],
|
||||
@@ -286,18 +328,40 @@ Page({
|
||||
return { start: current, end: current }
|
||||
},
|
||||
|
||||
applyCalendar(calendar) {
|
||||
applyCalendar(calendar, shopSchedule) {
|
||||
const artists = calendar.artists || []
|
||||
this.setData({
|
||||
businessStartTime: (calendar.businessStartTime || '10:00').slice(0, 5),
|
||||
businessEndTime: (calendar.businessEndTime || '22:00').slice(0, 5),
|
||||
artists,
|
||||
appointments: calendar.appointments || [],
|
||||
daySummaries: calendar.daySummaries || []
|
||||
daySummaries: calendar.daySummaries || [],
|
||||
shopRestDates: shopSchedule ? shopSchedule.restDates : []
|
||||
})
|
||||
this.prepareView()
|
||||
},
|
||||
|
||||
async loadShopSchedule(range) {
|
||||
const [settings, exceptions] = await Promise.all([
|
||||
shopApi.settings(),
|
||||
shopApi.scheduleExceptions({
|
||||
startDate: range.start,
|
||||
endDate: range.end
|
||||
})
|
||||
])
|
||||
const workDays = normalizeWorkDays(settings.scheduleWorkDays, settings.schedulePresetType)
|
||||
const exceptionMap = buildExceptionMap(exceptions)
|
||||
const restDates = []
|
||||
let cursor = range.start
|
||||
while (cursor <= range.end) {
|
||||
if (isShopRestDate(cursor, workDays, exceptionMap)) {
|
||||
restDates.push(cursor)
|
||||
}
|
||||
cursor = dateUtil.formatDate(dateUtil.addDays(cursor, 1))
|
||||
}
|
||||
return { restDates }
|
||||
},
|
||||
|
||||
prepareView() {
|
||||
const current = this.data.currentDateText
|
||||
const range = this.resolveRange()
|
||||
@@ -319,6 +383,7 @@ Page({
|
||||
buildMonthDays() {
|
||||
const summaryMap = this.summaryMap()
|
||||
const todayText = dateUtil.formatDate(new Date())
|
||||
const shopRestDates = this.data.shopRestDates || []
|
||||
const artistTemplate = this.data.artists.map(artist => ({
|
||||
artistId: artist.id,
|
||||
artistName: artist.name,
|
||||
@@ -338,6 +403,7 @@ Page({
|
||||
isPast: day.date < todayText,
|
||||
totalCount: summary.totalCount || 0,
|
||||
dayStatus: summary.dayStatus || 'free',
|
||||
shopRest: shopRestDates.includes(day.date),
|
||||
artistCounts,
|
||||
expandedBlocks: this.buildExpandedBlocks(artistCounts),
|
||||
rowBlocks: this.buildRowBlocks(artistCounts),
|
||||
|
||||
@@ -125,8 +125,8 @@
|
||||
<view wx:for="{{monthDays}}" wx:key="date" class="month-cell {{item.isCurrentMonth ? '' : 'out-month'}} {{item.date === currentDateText ? 'selected' : ''}}" data-date="{{item.date}}" bindtap="selectDate">
|
||||
<view class="month-cell-head">
|
||||
<text class="month-day">{{item.day}}</text>
|
||||
<text wx:if="{{!item.isPast && item.dayStatus === 'full'}}" class="day-mark full">满</text>
|
||||
<text wx:elif="{{!item.isPast && item.dayStatus === 'rest'}}" class="day-mark rest">休</text>
|
||||
<text wx:if="{{!item.isPast && item.shopRest}}" class="day-mark rest">休</text>
|
||||
<text wx:elif="{{!item.isPast && item.dayStatus === 'full'}}" class="day-mark full">满</text>
|
||||
</view>
|
||||
<view wx:if="{{monthDisplayMode === 'count'}}" class="month-bars">
|
||||
<view wx:for="{{item.artistCounts}}" wx:for-item="count" wx:key="key" wx:if="{{count.count > 0}}" class="month-artist-bar {{count.statusClass}}" style="background: {{count.color}};">
|
||||
|
||||
Reference in New Issue
Block a user