调整日程日期选择与预约入口

This commit is contained in:
2026-10-31 03:03:34 +08:00
parent 0e4043628e
commit ddc04705e3
5 changed files with 108 additions and 41 deletions
@@ -3,6 +3,7 @@ const assert = require('assert')
let definition let definition
let modalResult = { confirm: false } let modalResult = { confirm: false }
let modalOptions let modalOptions
let storedDraft = null
const navigations = [] const navigations = []
global.Page = value => { definition = value } global.Page = value => { definition = value }
@@ -13,8 +14,12 @@ global.wx = {
}, },
navigateTo(options) { navigateTo(options) {
navigations.push(options.url) navigations.push(options.url)
},
getStorageSync() { return storedDraft },
setStorageSync() {},
removeStorageSync() {}
} }
} global.getApp = () => ({ globalData: { userInfo: { type: 2 } } })
require('./index') require('./index')
@@ -40,6 +45,38 @@ function createPage() {
} }
async function run() { async function run() {
const manualDatePage = createPage()
manualDatePage.loadOptions = () => {}
manualDatePage.data.form.appointmentTime = ''
storedDraft = null
manualDatePage.onLoad({ dateMode: 'manual', artistId: '88' })
assert.strictEqual(manualDatePage.data.form.appointmentDate, '')
assert.strictEqual(manualDatePage.data.form.appointmentTime, '')
assert.strictEqual(manualDatePage.data.form.artistId, '88')
assert.strictEqual(manualDatePage.data.appointmentDateLong, '请选择预约日期')
const restoredDate = '2099-10-10'
const draftPage = createPage()
draftPage.loadOptions = () => {}
storedDraft = {
form: {
...definition.data.form,
customerName: '草稿客户',
productId: '41',
appointmentDate: restoredDate,
appointmentTime: '14:00',
artistId: '99'
},
savedAt: Date.now()
}
draftPage.onLoad({ dateMode: 'manual', artistId: '88' })
assert.strictEqual(draftPage.data.form.appointmentDate, restoredDate)
assert.strictEqual(draftPage.data.form.appointmentTime, '14:00')
assert.strictEqual(draftPage.data.form.customerName, '草稿客户')
assert.strictEqual(draftPage.data.form.artistId, '88')
assert.strictEqual(draftPage.data.draftSavedAtText, '已恢复本机草稿')
storedDraft = null
const page = createPage() const page = createPage()
let refreshes = 0 let refreshes = 0
page.loadArtists = async () => { refreshes += 1 } page.loadArtists = async () => { refreshes += 1 }
@@ -494,7 +494,10 @@ function buildArtistSelectorItem(artist) {
} }
function buildAppointmentDateLabels(value) { function buildAppointmentDateLabels(value) {
const dateValue = String(value || dateUtil.formatDate(new Date())) const dateValue = String(value || '')
if (!dateValue) {
return { day: '', badge: '请选择预约日期', long: '请选择预约日期' }
}
const date = new Date(dateValue.replace(/-/g, '/')) const date = new Date(dateValue.replace(/-/g, '/'))
if (Number.isNaN(date.getTime())) { if (Number.isNaN(date.getTime())) {
return { day: '', badge: dateValue, long: dateValue } return { day: '', badge: dateValue, long: dateValue }
@@ -596,6 +599,7 @@ Page({
}, },
onLoad(options) { onLoad(options) {
const manualDateMode = options && options.dateMode === 'manual'
const today = dateUtil.formatDate(new Date()) const today = dateUtil.formatDate(new Date())
if (options && options.date && options.date < today) { if (options && options.date && options.date < today) {
this._pendingHistoricalArtistId = options.artistId || '' this._pendingHistoricalArtistId = options.artistId || ''
@@ -603,10 +607,10 @@ Page({
return return
} }
const creatable = canCreateAppointment() const creatable = canCreateAppointment()
const draftForm = creatable && !hasPresetOptions(options) ? readDraftForm() : null const draftForm = creatable && (manualDateMode || !hasPresetOptions(options)) ? readDraftForm() : null
const baseForm = draftForm || {} const baseForm = draftForm || {}
const manualProductImages = normalizeManualProductImages(baseForm) const manualProductImages = normalizeManualProductImages(baseForm)
const appointmentDate = options.date || baseForm.appointmentDate || dateUtil.formatDate(new Date()) const appointmentDate = options.date || baseForm.appointmentDate || (manualDateMode ? '' : today)
const dateLabels = buildAppointmentDateLabels(appointmentDate) const dateLabels = buildAppointmentDateLabels(appointmentDate)
this.setData({ this.setData({
canCreateAppointment: creatable, canCreateAppointment: creatable,
@@ -692,8 +696,8 @@ Page({
: {} : {}
try { try {
const calendar = await planningApi.calendar({ const calendar = await planningApi.calendar({
startDate: this.data.form.appointmentDate, startDate: this.data.form.appointmentDate || dateUtil.formatDate(new Date()),
endDate: this.data.form.appointmentDate endDate: this.data.form.appointmentDate || dateUtil.formatDate(new Date())
}) })
let artists = getCalendarArtists(calendar) let artists = getCalendarArtists(calendar)
const businessHours = resolveBusinessHours(calendar) const businessHours = resolveBusinessHours(calendar)
+27 -17
View File
@@ -320,21 +320,25 @@ Page({
this.loadCalendar() this.loadCalendar()
}, },
quickCreateAppointment(event) { selectMonthDate(event) {
if (!this.data.canCreateAppointment) {
wx.showToast({ title: '当前账号仅支持查看预约', icon: 'none' })
return
}
const appointmentDate = dateUtil.formatDate(event.currentTarget.dataset.date) const appointmentDate = dateUtil.formatDate(event.currentTarget.dataset.date)
if (appointmentDate < dateUtil.formatDate(new Date())) { const target = toLocalDate(appointmentDate)
this.openBackfillOrder(appointmentDate) this.setData({
return viewMode: 'day',
} currentDate: target,
if (!this.data.businessHoursConfigured) { currentDateText: appointmentDate
wx.showToast({ title: '请先在店铺设置中配置营业时间', icon: 'none' }) })
return this.loadCalendar()
} },
this.openAppointmentForm(appointmentDate)
selectWeekDate(event) {
const appointmentDate = dateUtil.formatDate(event.currentTarget.dataset.date)
const target = toLocalDate(appointmentDate)
this.setData({
currentDate: target,
currentDateText: appointmentDate
})
this.prepareView()
}, },
prevRange() { prevRange() {
@@ -763,7 +767,7 @@ Page({
wx.showToast({ title: '请先在店铺设置中配置营业时间', icon: 'none' }) wx.showToast({ title: '请先在店铺设置中配置营业时间', icon: 'none' })
return return
} }
this.openAppointmentForm(this.data.currentDateText) this.openAppointmentForm(this.data.viewMode === 'day' ? this.data.currentDateText : '')
}, },
openBackfillOrder(serviceDate) { openBackfillOrder(serviceDate) {
@@ -779,11 +783,17 @@ Page({
}, },
openAppointmentForm(appointmentDate) { openAppointmentForm(appointmentDate) {
const query = [`date=${encodeURIComponent(appointmentDate)}`] const query = []
if (appointmentDate) {
query.push(`date=${encodeURIComponent(appointmentDate)}`)
} else {
query.push('dateMode=manual')
}
if (this.data.selectedArtistId) { if (this.data.selectedArtistId) {
query.push(`artistId=${encodeURIComponent(this.data.selectedArtistId)}`) query.push(`artistId=${encodeURIComponent(this.data.selectedArtistId)}`)
} }
wx.navigateTo({ url: `/pages/appointment-form/index?${query.join('&')}` }) const queryText = query.length ? `?${query.join('&')}` : ''
wx.navigateTo({ url: `/pages/appointment-form/index${queryText}` })
}, },
openShopSettings() { openShopSettings() {
+32 -16
View File
@@ -192,40 +192,56 @@ async function run() {
global.wx.navigateTo = options => navigations.push(options.url) global.wx.navigateTo = options => navigations.push(options.url)
global.wx.showToast = options => toasts.push(options.title) global.wx.showToast = options => toasts.push(options.title)
const quickCreatePage = createPage({ canCreateAppointment: true, businessHoursConfigured: true, selectedArtistId: '88' }) const monthPage = createPage({ viewMode: 'month', canCreateAppointment: true, currentDateText: '2026-10-12' })
const today = dateUtil.formatDate(new Date()) let loadedDate = ''
quickCreatePage.quickCreateAppointment({ currentTarget: { dataset: { date: today } } }) monthPage.loadCalendar = () => { loadedDate = monthPage.data.currentDateText }
assert.strictEqual(navigations.pop(), `/pages/appointment-form/index?date=${today}&artistId=88`) monthPage.selectMonthDate({ currentTarget: { dataset: { date: '2000-01-01' } } })
assert.strictEqual(monthPage.data.viewMode, 'day')
assert.strictEqual(monthPage.data.currentDateText, '2000-01-01')
assert.strictEqual(loadedDate, '2000-01-01')
assert.strictEqual(navigations.length, 0)
quickCreatePage.quickCreateAppointment({ currentTarget: { dataset: { date: '2099-12-31' } } }) const weekPage = createPage({ viewMode: 'week', currentDateText: '2026-10-12' })
assert.strictEqual(navigations.pop(), '/pages/appointment-form/index?date=2099-12-31&artistId=88') let preparedView = false
weekPage.prepareView = () => { preparedView = true }
weekPage.selectWeekDate({ currentTarget: { dataset: { date: '2026-10-15' } } })
assert.strictEqual(weekPage.data.viewMode, 'week')
assert.strictEqual(weekPage.data.currentDateText, '2026-10-15')
assert.strictEqual(preparedView, true)
assert.strictEqual(navigations.length, 0)
quickCreatePage.quickCreateAppointment({ currentTarget: { dataset: { date: '2000-01-01' } } }) const dayFabPage = createPage({ viewMode: 'day', canCreateAppointment: true, businessHoursConfigured: true, currentDateText: '2026-11-02', selectedArtistId: '99' })
assert.strictEqual(navigations.pop(), '/pages/backfill-order/index?serviceDate=2000-01-01&artistId=88') dayFabPage.createAppointment()
assert.strictEqual(navigations.pop(), '/pages/appointment-form/index?date=2026-11-02&artistId=99')
quickCreatePage.data.selectedArtistId = '' const monthFabPage = createPage({ viewMode: 'month', canCreateAppointment: true, businessHoursConfigured: true, currentDateText: '2026-11-02', selectedArtistId: '88' })
quickCreatePage.quickCreateAppointment({ currentTarget: { dataset: { date: '2099-11-30' } } }) monthFabPage.createAppointment()
assert.strictEqual(navigations.pop(), '/pages/appointment-form/index?date=2099-11-30') assert.strictEqual(navigations.pop(), '/pages/appointment-form/index?dateMode=manual&artistId=88')
quickCreatePage.quickCreateAppointment({ currentTarget: { dataset: { date: '2000-01-01' } } }) const weekFabPage = createPage({ viewMode: 'week', canCreateAppointment: true, businessHoursConfigured: true, currentDateText: '2026-11-02' })
assert.strictEqual(navigations.pop(), '/pages/backfill-order/index?serviceDate=2000-01-01') weekFabPage.createAppointment()
assert.strictEqual(navigations.pop(), '/pages/appointment-form/index?dateMode=manual')
const readonlyPage = createPage({ canCreateAppointment: false, businessHoursConfigured: true, selectedArtistId: '88' }) const readonlyPage = createPage({ canCreateAppointment: false, businessHoursConfigured: true, selectedArtistId: '88' })
readonlyPage.quickCreateAppointment({ currentTarget: { dataset: { date: '2099-12-31' } } }) readonlyPage.createAppointment()
assert.strictEqual(navigations.length, 0) assert.strictEqual(navigations.length, 0)
assert.strictEqual(toasts.pop(), '当前账号仅支持查看预约') assert.strictEqual(toasts.pop(), '当前账号仅支持查看预约')
const fabPage = createPage({ canCreateAppointment: true, businessHoursConfigured: true, currentDateText: '2026-10-12', selectedArtistId: '99' }) const fabPage = createPage({ viewMode: 'day', canCreateAppointment: true, businessHoursConfigured: true, currentDateText: '2026-10-12', selectedArtistId: '99' })
fabPage.createAppointment() fabPage.createAppointment()
assert.strictEqual(navigations.pop(), '/pages/appointment-form/index?date=2026-10-12&artistId=99') assert.strictEqual(navigations.pop(), '/pages/appointment-form/index?date=2026-10-12&artistId=99')
const unconfiguredPage = createPage({ canCreateAppointment: true, businessHoursConfigured: false }) const unconfiguredPage = createPage({ canCreateAppointment: true, businessHoursConfigured: false })
unconfiguredPage.quickCreateAppointment({ currentTarget: { dataset: { date: '2099-12-31' } } }) unconfiguredPage.createAppointment()
assert.strictEqual(navigations.length, 0) assert.strictEqual(navigations.length, 0)
assert.strictEqual(toasts.pop(), '请先在店铺设置中配置营业时间') assert.strictEqual(toasts.pop(), '请先在店铺设置中配置营业时间')
unconfiguredPage.openShopSettings() unconfiguredPage.openShopSettings()
assert.strictEqual(navigations.pop(), '/pages/shop-settings/index') assert.strictEqual(navigations.pop(), '/pages/shop-settings/index')
assert.strictEqual(unconfiguredPage._refreshCalendarOnShow, true) assert.strictEqual(unconfiguredPage._refreshCalendarOnShow, true)
assert.match(planningWxml, /bindtap="selectMonthDate" aria-label="查看\{\{item\.date\}\}日程"/)
assert.match(planningWxml, /bindtap="selectWeekDate" aria-label="查看\{\{item\.date\}\}日程"/)
assert.match(planningWxml, /class="fab" bindtap="createAppointment"/)
} }
run().catch(error => { run().catch(error => {
+2 -2
View File
@@ -129,7 +129,7 @@
<view wx:if="{{viewMode === 'week'}}" class="section"> <view wx:if="{{viewMode === 'week'}}" class="section">
<scroll-view class="week-strip" scroll-x enable-flex> <scroll-view class="week-strip" scroll-x enable-flex>
<view wx:for="{{weekDays}}" wx:key="date" class="week-day-card card {{item.date === currentDateText ? 'active' : ''}}" data-date="{{item.date}}" bindtap="quickCreateAppointment"> <view wx:for="{{weekDays}}" wx:key="date" class="week-day-card card {{item.date === currentDateText ? 'active' : ''}}" data-date="{{item.date}}" bindtap="selectWeekDate" aria-label="查看{{item.date}}日程">
<text class="week-name">{{item.weekName}}</text> <text class="week-name">{{item.weekName}}</text>
<text class="week-date">{{item.day}}</text> <text class="week-date">{{item.day}}</text>
<text class="week-total">{{item.totalCount}}单</text> <text class="week-total">{{item.totalCount}}单</text>
@@ -173,7 +173,7 @@
<text wx:for="{{weekLabels}}" wx:key="*this">{{item}}</text> <text wx:for="{{weekLabels}}" wx:key="*this">{{item}}</text>
</view> </view>
<view class="month-grid"> <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="quickCreateAppointment"> <view wx:for="{{monthDays}}" wx:key="date" class="month-cell {{item.isCurrentMonth ? '' : 'out-month'}} {{item.date === currentDateText ? 'selected' : ''}}" data-date="{{item.date}}" bindtap="selectMonthDate" aria-label="查看{{item.date}}日程">
<view class="month-cell-head"> <view class="month-cell-head">
<text class="month-day">{{item.day}}</text> <text class="month-day">{{item.day}}</text>
<view class="month-cell-badges"> <view class="month-cell-badges">