优化规划月视图空日期操作
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
const planningApi = require('../../api/planning')
|
||||
const shopApi = require('../../api/shop')
|
||||
const dateUtil = require('../../utils/date')
|
||||
const { markPlanningRefresh } = require('../../utils/planning-refresh')
|
||||
|
||||
const CALENDAR_ERROR_FALLBACK_MESSAGE = '规划数据暂时不可用,请稍后重试'
|
||||
const TECHNICAL_ERROR_PATTERNS = [
|
||||
@@ -36,6 +37,21 @@ function formatMonthDay(value) {
|
||||
return `${target.getMonth() + 1}月${target.getDate()}日`
|
||||
}
|
||||
|
||||
function formatActionDate(value) {
|
||||
const target = toLocalDate(value)
|
||||
const weekLabels = ['日', '一', '二', '三', '四', '五', '六']
|
||||
return `${target.getMonth() + 1}月${target.getDate()}日 周${weekLabels[target.getDay()]}`
|
||||
}
|
||||
|
||||
function formatShortDate(value) {
|
||||
const target = toLocalDate(value)
|
||||
return `${target.getMonth() + 1}月${target.getDate()}日`
|
||||
}
|
||||
|
||||
function buildAppointmentFormUrl(date, artistId) {
|
||||
return `/pages/appointment-form/index?date=${date}&artistId=${artistId || ''}`
|
||||
}
|
||||
|
||||
function resolveAppointmentDate(item) {
|
||||
if (item.date) return item.date
|
||||
return String(item.startTime || '').slice(0, 10)
|
||||
@@ -141,9 +157,9 @@ Page({
|
||||
data: {
|
||||
viewMode: 'month',
|
||||
viewModes: [
|
||||
{ value: 'day', label: '日' },
|
||||
{ value: 'month', label: '月' },
|
||||
{ value: 'week', label: '周' },
|
||||
{ value: 'month', label: '月' }
|
||||
{ value: 'day', label: '日' }
|
||||
],
|
||||
monthDisplayMode: 'count',
|
||||
monthDisplayModes: [
|
||||
@@ -179,7 +195,12 @@ Page({
|
||||
pendingCount: 0,
|
||||
canCreateAppointment: true,
|
||||
loading: false,
|
||||
calendarError: ''
|
||||
calendarError: '',
|
||||
emptyDateActionVisible: false,
|
||||
pendingEmptyDate: '',
|
||||
pendingEmptyDateTitle: '',
|
||||
pendingEmptyDateLabel: '',
|
||||
savingRestDate: false
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
@@ -224,14 +245,50 @@ Page({
|
||||
|
||||
selectDate(event) {
|
||||
const currentDate = dateUtil.formatDate(event.currentTarget.dataset.date)
|
||||
if (this.data.viewMode === 'month') {
|
||||
const monthDay = this.data.monthDays.find(item => item.date === currentDate)
|
||||
if (monthDay && monthDay.isCurrentMonth && Number(monthDay.totalCount || 0) === 0 && !monthDay.shopRest) {
|
||||
this.openEmptyDateAction(currentDate)
|
||||
return
|
||||
}
|
||||
}
|
||||
this.setData({
|
||||
currentDate,
|
||||
currentDateText: currentDate,
|
||||
viewMode: this.data.viewMode === 'month' ? 'day' : this.data.viewMode
|
||||
viewMode: this.data.viewMode === 'month' ? 'day' : this.data.viewMode,
|
||||
emptyDateActionVisible: false,
|
||||
pendingEmptyDate: '',
|
||||
pendingEmptyDateTitle: '',
|
||||
pendingEmptyDateLabel: ''
|
||||
})
|
||||
this.prepareView()
|
||||
},
|
||||
|
||||
openEmptyDateAction(date) {
|
||||
const currentDate = dateUtil.formatDate(date)
|
||||
this.setData({
|
||||
currentDate,
|
||||
currentDateText: currentDate,
|
||||
emptyDateActionVisible: true,
|
||||
pendingEmptyDate: currentDate,
|
||||
pendingEmptyDateTitle: formatActionDate(currentDate),
|
||||
pendingEmptyDateLabel: formatShortDate(currentDate)
|
||||
})
|
||||
this.prepareView()
|
||||
},
|
||||
|
||||
closeEmptyDateAction() {
|
||||
this.setData({
|
||||
emptyDateActionVisible: false,
|
||||
pendingEmptyDate: '',
|
||||
pendingEmptyDateTitle: '',
|
||||
pendingEmptyDateLabel: '',
|
||||
savingRestDate: false
|
||||
})
|
||||
},
|
||||
|
||||
stopTap() {},
|
||||
|
||||
prevRange() {
|
||||
this.shiftRange(-1)
|
||||
},
|
||||
@@ -579,10 +636,53 @@ Page({
|
||||
return
|
||||
}
|
||||
wx.navigateTo({
|
||||
url: `/pages/appointment-form/index?date=${this.data.currentDateText}&artistId=${this.data.selectedArtistId || ''}`
|
||||
url: buildAppointmentFormUrl(this.data.currentDateText, this.data.selectedArtistId)
|
||||
})
|
||||
},
|
||||
|
||||
createAppointmentFromEmptyDate() {
|
||||
if (!this.data.pendingEmptyDate) {
|
||||
wx.showToast({ title: '请选择预约日期', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!this.data.canCreateAppointment) {
|
||||
wx.showToast({ title: '美甲师账号只能查看预约', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.setData({ emptyDateActionVisible: false })
|
||||
wx.navigateTo({
|
||||
url: buildAppointmentFormUrl(this.data.pendingEmptyDate, this.data.selectedArtistId)
|
||||
})
|
||||
},
|
||||
|
||||
async setEmptyDateAsRest() {
|
||||
if (!this.data.pendingEmptyDate) {
|
||||
wx.showToast({ title: '请选择休息日期', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (this.data.savingRestDate) {
|
||||
return
|
||||
}
|
||||
this.setData({ savingRestDate: true })
|
||||
try {
|
||||
await shopApi.saveScheduleException({
|
||||
workDate: this.data.pendingEmptyDate,
|
||||
exceptionType: 'REST',
|
||||
startTime: null,
|
||||
endTime: null,
|
||||
remark: '规划页快速设置'
|
||||
})
|
||||
markPlanningRefresh()
|
||||
wx.showToast({ title: '已设为休息日', icon: 'success' })
|
||||
this.closeEmptyDateAction()
|
||||
await this.loadCalendar()
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '休息日设置失败', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ savingRestDate: false })
|
||||
}
|
||||
},
|
||||
|
||||
openAppointment(event) {
|
||||
wx.navigateTo({
|
||||
url: `/pages/appointment-detail/index?id=${event.currentTarget.dataset.id}`
|
||||
|
||||
@@ -122,7 +122,7 @@
|
||||
<text wx:for="{{weekLabels}}" wx:key="*this">{{item}}</text>
|
||||
</view>
|
||||
<view class="month-grid">
|
||||
<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 wx:for="{{monthDays}}" wx:key="date" class="month-cell {{item.isCurrentMonth ? '' : 'out-month'}} {{item.date === currentDateText ? 'selected' : ''}} {{emptyDateActionVisible && item.date === pendingEmptyDate ? 'action-target' : ''}} {{!item.isPast && item.shopRest ? 'is-rest' : ''}}" data-date="{{item.date}}" bindtap="selectDate">
|
||||
<view class="month-cell-head">
|
||||
<text class="month-day">{{item.day}}</text>
|
||||
<text wx:if="{{!item.isPast && item.shopRest}}" class="day-mark rest">休</text>
|
||||
@@ -153,4 +153,33 @@
|
||||
</block>
|
||||
|
||||
<button wx:if="{{canCreateAppointment && !calendarError}}" class="fab" bindtap="createAppointment">+</button>
|
||||
|
||||
<view wx:if="{{emptyDateActionVisible}}" class="empty-date-mask" catchtap="stopTap">
|
||||
<view class="empty-date-sheet" catchtap="stopTap">
|
||||
<view class="sheet-grabber"></view>
|
||||
<view class="empty-date-head">
|
||||
<view class="empty-date-title-wrap">
|
||||
<text class="empty-date-title">{{pendingEmptyDateTitle}}</text>
|
||||
<text class="empty-date-subtitle">当前日期暂无预约,可以直接创建预约或设为特殊休息日</text>
|
||||
</view>
|
||||
<button class="empty-date-close" bindtap="closeEmptyDateAction">×</button>
|
||||
</view>
|
||||
<view class="empty-date-actions">
|
||||
<button class="empty-date-action primary" bindtap="createAppointmentFromEmptyDate">
|
||||
<view class="empty-date-action-icon">+</view>
|
||||
<view class="empty-date-action-copy">
|
||||
<text class="empty-date-action-title">以 {{pendingEmptyDateLabel}} 新建预约</text>
|
||||
<text class="empty-date-action-desc">进入预约表单,并自动带入日期;员工沿用当前筛选</text>
|
||||
</view>
|
||||
</button>
|
||||
<button class="empty-date-action rest" loading="{{savingRestDate}}" bindtap="setEmptyDateAsRest">
|
||||
<view class="empty-date-action-icon">休</view>
|
||||
<view class="empty-date-action-copy">
|
||||
<text class="empty-date-action-title">设为特殊休息日期</text>
|
||||
<text class="empty-date-action-desc">保存后月历标记为“休”,当天不再生成可约时间</text>
|
||||
</view>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -724,6 +724,16 @@
|
||||
background: #eef5f1;
|
||||
}
|
||||
|
||||
.month-cell.action-target {
|
||||
background: #fbfff8;
|
||||
outline: 3rpx solid #6f8f83;
|
||||
outline-offset: -3rpx;
|
||||
}
|
||||
|
||||
.month-cell.is-rest {
|
||||
background: #fff8f6;
|
||||
}
|
||||
|
||||
.month-cell-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -827,6 +837,157 @@
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.empty-date-mask {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
z-index: 80;
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
background: rgba(38, 35, 31, 0.36);
|
||||
}
|
||||
|
||||
.empty-date-sheet {
|
||||
width: 100%;
|
||||
padding: 22rpx 28rpx calc(28rpx + env(safe-area-inset-bottom));
|
||||
border-radius: 22px 22px 0 0;
|
||||
background: #fffdf8;
|
||||
box-shadow: 0 -18rpx 44rpx rgba(38, 35, 31, 0.18);
|
||||
animation: emptyDateSheetIn 180ms ease both;
|
||||
}
|
||||
|
||||
.sheet-grabber {
|
||||
width: 84rpx;
|
||||
height: 8rpx;
|
||||
margin: 0 auto 22rpx;
|
||||
border-radius: 999rpx;
|
||||
background: #ded6cb;
|
||||
}
|
||||
|
||||
.empty-date-head {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 20rpx;
|
||||
}
|
||||
|
||||
.empty-date-title-wrap {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
flex-direction: column;
|
||||
gap: 8rpx;
|
||||
}
|
||||
|
||||
.empty-date-title {
|
||||
color: #25211d;
|
||||
font-size: 36rpx;
|
||||
font-weight: 900;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.empty-date-subtitle {
|
||||
color: #8f877e;
|
||||
font-size: 24rpx;
|
||||
font-weight: 700;
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.empty-date-close {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 60rpx;
|
||||
min-width: 60rpx;
|
||||
max-width: 60rpx;
|
||||
height: 60rpx;
|
||||
min-height: 60rpx;
|
||||
padding: 0;
|
||||
border-radius: 50%;
|
||||
background: #f0ece5;
|
||||
color: #5f5951;
|
||||
font-size: 38rpx;
|
||||
font-weight: 700;
|
||||
line-height: 60rpx;
|
||||
}
|
||||
|
||||
.empty-date-actions {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18rpx;
|
||||
margin-top: 30rpx;
|
||||
}
|
||||
|
||||
.empty-date-action {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
min-height: 136rpx;
|
||||
padding: 22rpx;
|
||||
border-radius: 12px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.empty-date-action.primary {
|
||||
background: #6f8f83;
|
||||
color: #fffdf8;
|
||||
box-shadow: 0 8rpx 18rpx rgba(111, 143, 131, 0.24);
|
||||
}
|
||||
|
||||
.empty-date-action.rest {
|
||||
border: 1rpx solid #f0d7d3;
|
||||
background: #fff8f6;
|
||||
color: #6a4743;
|
||||
}
|
||||
|
||||
.empty-date-action-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 80rpx;
|
||||
min-width: 80rpx;
|
||||
max-width: 80rpx;
|
||||
height: 80rpx;
|
||||
margin-right: 24rpx;
|
||||
border-radius: 12px;
|
||||
font-size: 38rpx;
|
||||
font-weight: 900;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.empty-date-action.primary .empty-date-action-icon {
|
||||
background: rgba(255, 255, 255, 0.18);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.empty-date-action.rest .empty-date-action-icon {
|
||||
background: #ffe9e5;
|
||||
color: #c56f6f;
|
||||
}
|
||||
|
||||
.empty-date-action-copy {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
flex-direction: column;
|
||||
gap: 8rpx;
|
||||
}
|
||||
|
||||
.empty-date-action-title {
|
||||
font-size: 30rpx;
|
||||
font-weight: 900;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.empty-date-action-desc {
|
||||
font-size: 24rpx;
|
||||
font-weight: 700;
|
||||
line-height: 1.35;
|
||||
opacity: 0.82;
|
||||
}
|
||||
|
||||
@keyframes pageFadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
@@ -837,3 +998,14 @@
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes emptyDateSheetIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(24rpx);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user