改为店务小程序原生时间选择器
This commit is contained in:
@@ -457,43 +457,11 @@ function canUseTimeMinute(form, minute) {
|
||||
return minute > getCurrentMinuteOfDay()
|
||||
}
|
||||
|
||||
function splitTimeValue(value) {
|
||||
const parts = String(value || '').split(':')
|
||||
return {
|
||||
hour: parts[0] || '',
|
||||
minute: parts[1] || ''
|
||||
}
|
||||
}
|
||||
|
||||
function buildTimePickerState(selectedValue) {
|
||||
const hourValues = []
|
||||
const minuteValues = []
|
||||
for (let hour = 0; hour < 24; hour += 1) {
|
||||
hourValues.push(String(hour).padStart(2, '0'))
|
||||
}
|
||||
for (let minute = 0; minute < 60; minute += 1) {
|
||||
minuteValues.push(String(minute).padStart(2, '0'))
|
||||
}
|
||||
const selectedParts = splitTimeValue(selectedValue)
|
||||
const selectedHour = hourValues.includes(selectedParts.hour) ? selectedParts.hour : hourValues[0]
|
||||
const selectedMinute = minuteValues.includes(selectedParts.minute) ? selectedParts.minute : minuteValues[0]
|
||||
const value = `${selectedHour}:${selectedMinute}`
|
||||
return {
|
||||
hourValues,
|
||||
minuteValues,
|
||||
value,
|
||||
indices: [hourValues.indexOf(selectedHour), minuteValues.indexOf(selectedMinute)]
|
||||
}
|
||||
}
|
||||
|
||||
function resolveInitialTimePickerValue(form) {
|
||||
if (form.appointmentTime) {
|
||||
return form.appointmentTime
|
||||
return normalizeTimeText(form.appointmentTime)
|
||||
}
|
||||
if (!isToday(form.appointmentDate)) {
|
||||
return '00:00'
|
||||
}
|
||||
return dateUtil.timeFromMinutes(Math.min(DAY_MINUTES - 1, getCurrentMinuteOfDay() + 1))
|
||||
return '00:00'
|
||||
}
|
||||
|
||||
function resolveTimeConfirmTip(form) {
|
||||
@@ -795,11 +763,7 @@ Page({
|
||||
canCreateAppointment: true,
|
||||
draftSavedAtText: '',
|
||||
manualImageUploading: false,
|
||||
timeSheetVisible: false,
|
||||
timeSelectTip: '请选择预约时间',
|
||||
timePickerHours: [],
|
||||
timePickerMinutes: [],
|
||||
timePickerIndices: [0, 0],
|
||||
timePickerValue: '',
|
||||
timePickerConfirming: false,
|
||||
pageMaskVisible: false,
|
||||
@@ -1341,76 +1305,31 @@ Page({
|
||||
void this.checkAvailability(this.data.form.appointmentTime)
|
||||
},
|
||||
|
||||
canOpenTimeSheet() {
|
||||
const form = this.data.form
|
||||
return Boolean(form.appointmentDate)
|
||||
},
|
||||
|
||||
refreshAvailableTimes() {
|
||||
const form = this.data.form
|
||||
if (!form.appointmentDate) {
|
||||
this.setData({
|
||||
timeSelectTip: '请选择预约时间',
|
||||
timePickerHours: [],
|
||||
timePickerMinutes: [],
|
||||
timePickerIndices: [0, 0],
|
||||
timePickerValue: ''
|
||||
})
|
||||
return
|
||||
}
|
||||
const timePickerState = buildTimePickerState(resolveInitialTimePickerValue(form))
|
||||
this.setData({
|
||||
timeSelectTip: '请选择预约时间',
|
||||
timePickerHours: timePickerState.hourValues,
|
||||
timePickerMinutes: timePickerState.minuteValues,
|
||||
timePickerIndices: timePickerState.indices,
|
||||
timePickerValue: timePickerState.value
|
||||
timePickerValue: resolveInitialTimePickerValue(form)
|
||||
})
|
||||
},
|
||||
|
||||
async openTimeSheet() {
|
||||
if (!this.canOpenTimeSheet()) {
|
||||
wx.showToast({ title: '请先选择预约日期', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.setData({
|
||||
timeSheetVisible: true,
|
||||
timePickerConfirming: false
|
||||
})
|
||||
this.refreshAvailableTimes()
|
||||
},
|
||||
|
||||
closeTimeSheet() {
|
||||
this.setData({
|
||||
timeSheetVisible: false,
|
||||
timePickerConfirming: false
|
||||
})
|
||||
},
|
||||
|
||||
onTimePickerChange(event) {
|
||||
const value = Array.isArray(event.detail.value) ? event.detail.value : []
|
||||
const hourValues = this.data.timePickerHours || []
|
||||
const minuteValues = this.data.timePickerMinutes || []
|
||||
const hourIndex = Math.max(0, Math.min(hourValues.length - 1, Number(value[0] || 0)))
|
||||
const minuteIndex = Math.max(0, Math.min(minuteValues.length - 1, Number(value[1] || 0)))
|
||||
const selectedHour = hourValues[hourIndex] || hourValues[0] || '00'
|
||||
const selectedMinute = minuteValues[minuteIndex] || minuteValues[0] || '00'
|
||||
const selectedValue = selectedHour && selectedMinute ? `${selectedHour}:${selectedMinute}` : ''
|
||||
this.setData({
|
||||
timePickerIndices: [hourIndex, minuteIndex],
|
||||
timePickerValue: selectedValue
|
||||
})
|
||||
},
|
||||
|
||||
async confirmTimeSelection() {
|
||||
async onNativeTimeChange(event) {
|
||||
if (this.data.timePickerConfirming) {
|
||||
return
|
||||
}
|
||||
const selectedTime = this.data.timePickerValue
|
||||
const selectedTime = normalizeTimeText(event.detail.value)
|
||||
if (!selectedTime) {
|
||||
wx.showToast({ title: '请先选择预约时间', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.setData({ timePickerValue: selectedTime })
|
||||
const confirmTip = resolveTimeConfirmTip(this.data.form)
|
||||
if (confirmTip) {
|
||||
wx.showModal({
|
||||
@@ -1438,7 +1357,7 @@ Page({
|
||||
}
|
||||
this.setData({
|
||||
'form.appointmentTime': selectedTime,
|
||||
timeSheetVisible: false
|
||||
timePickerValue: selectedTime
|
||||
})
|
||||
} catch (error) {
|
||||
this.hidePageMask()
|
||||
|
||||
@@ -59,13 +59,15 @@
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label required">预约时间</text>
|
||||
<view class="field-value time-value {{form.appointmentTime ? '' : 'placeholder'}}" bindtap="openTimeSheet">
|
||||
<view>
|
||||
<text>{{form.appointmentTime || timeSelectTip}}</text>
|
||||
<text wx:if="{{form.appointmentTime}}" class="time-range">{{form.appointmentDate}} · {{selectedArtist.name}} · {{form.durationMinutes}}分钟</text>
|
||||
<picker class="time-native-picker" mode="time" value="{{timePickerValue || form.appointmentTime || '00:00'}}" start="00:00" end="23:59" disabled="{{pageMaskVisible || timePickerConfirming}}" bindchange="onNativeTimeChange">
|
||||
<view class="field-value time-value {{form.appointmentTime ? '' : 'placeholder'}}">
|
||||
<view>
|
||||
<text>{{form.appointmentTime || timeSelectTip}}</text>
|
||||
<text wx:if="{{form.appointmentTime}}" class="time-range">{{form.appointmentDate}} · {{selectedArtist.name}} · {{form.durationMinutes}}分钟</text>
|
||||
</view>
|
||||
<text class="time-arrow">›</text>
|
||||
</view>
|
||||
<text class="time-arrow">›</text>
|
||||
</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="appointment-flags">
|
||||
<view class="flag-card {{form.depositPaid ? 'active' : ''}}" data-field="depositPaid" bindtap="toggleFlag">
|
||||
@@ -221,45 +223,6 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{timeSheetVisible}}" class="modal-mask" bindtap="closeTimeSheet">
|
||||
<view class="time-modal" catchtap="stopTap">
|
||||
<view class="modal-head">
|
||||
<view>
|
||||
<text class="modal-title">选择预约时间</text>
|
||||
<text class="modal-subtitle">{{form.appointmentDate}} · {{selectedArtist.name}} · {{form.durationMinutes}}分钟</text>
|
||||
</view>
|
||||
<view class="modal-close" bindtap="closeTimeSheet">×</view>
|
||||
</view>
|
||||
<view class="time-picker-panel">
|
||||
<view class="time-picker-summary">
|
||||
<text class="time-picker-label">开始时间</text>
|
||||
<text class="time-picker-value">{{timePickerValue || '--:--'}}</text>
|
||||
</view>
|
||||
<view class="time-picker-head">
|
||||
<text>时</text>
|
||||
<text>分</text>
|
||||
</view>
|
||||
<view class="time-picker-stage">
|
||||
<picker-view class="time-picker-view" value="{{timePickerIndices}}" bindchange="onTimePickerChange" indicator-class="time-picker-indicator" mask-class="time-picker-mask">
|
||||
<picker-view-column>
|
||||
<view wx:for="{{timePickerHours}}" wx:for-index="hourIndex" wx:key="*this" class="time-picker-item {{timePickerIndices[0] == hourIndex ? 'selected' : ''}}">{{item}}</view>
|
||||
</picker-view-column>
|
||||
<picker-view-column>
|
||||
<view wx:for="{{timePickerMinutes}}" wx:for-index="minuteIndex" wx:key="*this" class="time-picker-item {{timePickerIndices[1] == minuteIndex ? 'selected' : ''}}">{{item}}</view>
|
||||
</picker-view-column>
|
||||
</picker-view>
|
||||
<view class="time-picker-selected-overlay" aria-hidden="true">
|
||||
<text>{{timePickerHours[timePickerIndices[0]] || '--'}}</text>
|
||||
<text>{{timePickerMinutes[timePickerIndices[1]] || '--'}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="time-picker-actions">
|
||||
<button class="time-confirm-btn" loading="{{timePickerConfirming}}" disabled="{{timePickerConfirming || !timePickerValue || pageMaskVisible}}" bindtap="confirmTimeSelection">确认时间</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="fixed-bottom">
|
||||
<view wx:if="{{canCreateAppointment}}" class="action-row">
|
||||
<button class="secondary-btn draft-btn" disabled="{{pageMaskVisible || loading}}" bindtap="saveDraft">保存草稿</button>
|
||||
|
||||
@@ -283,6 +283,11 @@
|
||||
color: #aaa096;
|
||||
}
|
||||
|
||||
.time-native-picker {
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.time-range {
|
||||
overflow: hidden;
|
||||
color: #9a9288;
|
||||
@@ -488,19 +493,9 @@
|
||||
box-shadow: 0 -18rpx 40rpx rgba(41, 31, 23, 0.16);
|
||||
}
|
||||
|
||||
.time-modal {
|
||||
width: 100%;
|
||||
max-height: 82vh;
|
||||
padding: 28rpx 28rpx calc(28rpx + env(safe-area-inset-bottom));
|
||||
border-radius: 28rpx 28rpx 0 0;
|
||||
background: #fffaf4;
|
||||
box-shadow: 0 -18rpx 40rpx rgba(41, 31, 23, 0.16);
|
||||
}
|
||||
|
||||
.product-modal,
|
||||
.template-modal,
|
||||
.artist-modal,
|
||||
.time-modal {
|
||||
.artist-modal {
|
||||
animation: appointment-sheet-enter 0.22s ease-out both;
|
||||
}
|
||||
|
||||
@@ -852,143 +847,6 @@
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.time-picker-panel {
|
||||
padding-top: 4rpx;
|
||||
}
|
||||
|
||||
.time-picker-summary {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 18rpx;
|
||||
padding: 18rpx 22rpx;
|
||||
border: 1rpx solid #eadfd2;
|
||||
border-radius: 18rpx;
|
||||
background: #fffdf8;
|
||||
}
|
||||
|
||||
.time-picker-label {
|
||||
display: block;
|
||||
color: #8c8177;
|
||||
font-size: 22rpx;
|
||||
line-height: 1.25;
|
||||
}
|
||||
|
||||
.time-picker-value {
|
||||
display: block;
|
||||
min-width: 160rpx;
|
||||
color: #2f2923;
|
||||
font-size: 42rpx;
|
||||
font-weight: 900;
|
||||
line-height: 1.1;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.time-picker-head {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
margin: 20rpx 0 10rpx;
|
||||
color: #8c8177;
|
||||
font-size: 22rpx;
|
||||
font-weight: 800;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.time-picker-view {
|
||||
width: 100%;
|
||||
height: 370rpx;
|
||||
overflow: hidden;
|
||||
border: 1rpx solid #eadfd2;
|
||||
border-radius: 18rpx;
|
||||
background: #fffaf4;
|
||||
}
|
||||
|
||||
.time-picker-stage {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.time-picker-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 92rpx;
|
||||
color: #c8beb2;
|
||||
font-size: 34rpx;
|
||||
font-weight: 800;
|
||||
line-height: 92rpx;
|
||||
transition: color 160ms ease, font-weight 160ms ease;
|
||||
}
|
||||
|
||||
.time-picker-item.selected {
|
||||
color: #2f2923;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.time-picker-selected-overlay {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 0;
|
||||
right: 0;
|
||||
display: grid;
|
||||
height: 92rpx;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
align-items: center;
|
||||
margin-top: -46rpx;
|
||||
background: #fff2df;
|
||||
border-top: 1rpx solid #e1d4c5;
|
||||
border-bottom: 1rpx solid #e1d4c5;
|
||||
pointer-events: none;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.time-picker-selected-overlay text {
|
||||
color: #2f2923;
|
||||
font-size: 34rpx;
|
||||
font-weight: 900;
|
||||
line-height: 92rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.time-picker-indicator {
|
||||
height: 92rpx;
|
||||
border-top: 1rpx solid #e1d4c5;
|
||||
border-bottom: 1rpx solid #e1d4c5;
|
||||
background: rgba(255, 242, 223, 0.82);
|
||||
}
|
||||
|
||||
.time-picker-mask {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.time-picker-actions {
|
||||
margin-top: 22rpx;
|
||||
}
|
||||
|
||||
.time-confirm-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 88rpx;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border-radius: 18rpx;
|
||||
background: #6f8f83;
|
||||
color: #fff;
|
||||
font-size: 28rpx;
|
||||
font-weight: 900;
|
||||
line-height: 88rpx;
|
||||
}
|
||||
|
||||
.time-confirm-btn::after {
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.time-confirm-btn[disabled] {
|
||||
background: #d7d0c8;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.time-empty {
|
||||
min-height: 220rpx;
|
||||
display: flex;
|
||||
|
||||
Reference in New Issue
Block a user