调整日程日期选择与预约入口
This commit is contained in:
@@ -3,6 +3,7 @@ const assert = require('assert')
|
||||
let definition
|
||||
let modalResult = { confirm: false }
|
||||
let modalOptions
|
||||
let storedDraft = null
|
||||
const navigations = []
|
||||
|
||||
global.Page = value => { definition = value }
|
||||
@@ -13,8 +14,12 @@ global.wx = {
|
||||
},
|
||||
navigateTo(options) {
|
||||
navigations.push(options.url)
|
||||
}
|
||||
},
|
||||
getStorageSync() { return storedDraft },
|
||||
setStorageSync() {},
|
||||
removeStorageSync() {}
|
||||
}
|
||||
global.getApp = () => ({ globalData: { userInfo: { type: 2 } } })
|
||||
|
||||
require('./index')
|
||||
|
||||
@@ -40,6 +45,38 @@ function createPage() {
|
||||
}
|
||||
|
||||
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()
|
||||
let refreshes = 0
|
||||
page.loadArtists = async () => { refreshes += 1 }
|
||||
|
||||
@@ -494,7 +494,10 @@ function buildArtistSelectorItem(artist) {
|
||||
}
|
||||
|
||||
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, '/'))
|
||||
if (Number.isNaN(date.getTime())) {
|
||||
return { day: '', badge: dateValue, long: dateValue }
|
||||
@@ -596,6 +599,7 @@ Page({
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const manualDateMode = options && options.dateMode === 'manual'
|
||||
const today = dateUtil.formatDate(new Date())
|
||||
if (options && options.date && options.date < today) {
|
||||
this._pendingHistoricalArtistId = options.artistId || ''
|
||||
@@ -603,10 +607,10 @@ Page({
|
||||
return
|
||||
}
|
||||
const creatable = canCreateAppointment()
|
||||
const draftForm = creatable && !hasPresetOptions(options) ? readDraftForm() : null
|
||||
const draftForm = creatable && (manualDateMode || !hasPresetOptions(options)) ? readDraftForm() : null
|
||||
const baseForm = draftForm || {}
|
||||
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)
|
||||
this.setData({
|
||||
canCreateAppointment: creatable,
|
||||
@@ -692,8 +696,8 @@ Page({
|
||||
: {}
|
||||
try {
|
||||
const calendar = await planningApi.calendar({
|
||||
startDate: this.data.form.appointmentDate,
|
||||
endDate: this.data.form.appointmentDate
|
||||
startDate: this.data.form.appointmentDate || dateUtil.formatDate(new Date()),
|
||||
endDate: this.data.form.appointmentDate || dateUtil.formatDate(new Date())
|
||||
})
|
||||
let artists = getCalendarArtists(calendar)
|
||||
const businessHours = resolveBusinessHours(calendar)
|
||||
|
||||
@@ -320,21 +320,25 @@ Page({
|
||||
this.loadCalendar()
|
||||
},
|
||||
|
||||
quickCreateAppointment(event) {
|
||||
if (!this.data.canCreateAppointment) {
|
||||
wx.showToast({ title: '当前账号仅支持查看预约', icon: 'none' })
|
||||
return
|
||||
}
|
||||
selectMonthDate(event) {
|
||||
const appointmentDate = dateUtil.formatDate(event.currentTarget.dataset.date)
|
||||
if (appointmentDate < dateUtil.formatDate(new Date())) {
|
||||
this.openBackfillOrder(appointmentDate)
|
||||
return
|
||||
}
|
||||
if (!this.data.businessHoursConfigured) {
|
||||
wx.showToast({ title: '请先在店铺设置中配置营业时间', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.openAppointmentForm(appointmentDate)
|
||||
const target = toLocalDate(appointmentDate)
|
||||
this.setData({
|
||||
viewMode: 'day',
|
||||
currentDate: target,
|
||||
currentDateText: appointmentDate
|
||||
})
|
||||
this.loadCalendar()
|
||||
},
|
||||
|
||||
selectWeekDate(event) {
|
||||
const appointmentDate = dateUtil.formatDate(event.currentTarget.dataset.date)
|
||||
const target = toLocalDate(appointmentDate)
|
||||
this.setData({
|
||||
currentDate: target,
|
||||
currentDateText: appointmentDate
|
||||
})
|
||||
this.prepareView()
|
||||
},
|
||||
|
||||
prevRange() {
|
||||
@@ -763,7 +767,7 @@ Page({
|
||||
wx.showToast({ title: '请先在店铺设置中配置营业时间', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.openAppointmentForm(this.data.currentDateText)
|
||||
this.openAppointmentForm(this.data.viewMode === 'day' ? this.data.currentDateText : '')
|
||||
},
|
||||
|
||||
openBackfillOrder(serviceDate) {
|
||||
@@ -779,11 +783,17 @@ Page({
|
||||
},
|
||||
|
||||
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) {
|
||||
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() {
|
||||
|
||||
@@ -192,40 +192,56 @@ async function run() {
|
||||
global.wx.navigateTo = options => navigations.push(options.url)
|
||||
global.wx.showToast = options => toasts.push(options.title)
|
||||
|
||||
const quickCreatePage = createPage({ canCreateAppointment: true, businessHoursConfigured: true, selectedArtistId: '88' })
|
||||
const today = dateUtil.formatDate(new Date())
|
||||
quickCreatePage.quickCreateAppointment({ currentTarget: { dataset: { date: today } } })
|
||||
assert.strictEqual(navigations.pop(), `/pages/appointment-form/index?date=${today}&artistId=88`)
|
||||
const monthPage = createPage({ viewMode: 'month', canCreateAppointment: true, currentDateText: '2026-10-12' })
|
||||
let loadedDate = ''
|
||||
monthPage.loadCalendar = () => { loadedDate = monthPage.data.currentDateText }
|
||||
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' } } })
|
||||
assert.strictEqual(navigations.pop(), '/pages/appointment-form/index?date=2099-12-31&artistId=88')
|
||||
const weekPage = createPage({ viewMode: 'week', currentDateText: '2026-10-12' })
|
||||
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' } } })
|
||||
assert.strictEqual(navigations.pop(), '/pages/backfill-order/index?serviceDate=2000-01-01&artistId=88')
|
||||
const dayFabPage = createPage({ viewMode: 'day', canCreateAppointment: true, businessHoursConfigured: true, currentDateText: '2026-11-02', selectedArtistId: '99' })
|
||||
dayFabPage.createAppointment()
|
||||
assert.strictEqual(navigations.pop(), '/pages/appointment-form/index?date=2026-11-02&artistId=99')
|
||||
|
||||
quickCreatePage.data.selectedArtistId = ''
|
||||
quickCreatePage.quickCreateAppointment({ currentTarget: { dataset: { date: '2099-11-30' } } })
|
||||
assert.strictEqual(navigations.pop(), '/pages/appointment-form/index?date=2099-11-30')
|
||||
const monthFabPage = createPage({ viewMode: 'month', canCreateAppointment: true, businessHoursConfigured: true, currentDateText: '2026-11-02', selectedArtistId: '88' })
|
||||
monthFabPage.createAppointment()
|
||||
assert.strictEqual(navigations.pop(), '/pages/appointment-form/index?dateMode=manual&artistId=88')
|
||||
|
||||
quickCreatePage.quickCreateAppointment({ currentTarget: { dataset: { date: '2000-01-01' } } })
|
||||
assert.strictEqual(navigations.pop(), '/pages/backfill-order/index?serviceDate=2000-01-01')
|
||||
const weekFabPage = createPage({ viewMode: 'week', canCreateAppointment: true, businessHoursConfigured: true, currentDateText: '2026-11-02' })
|
||||
weekFabPage.createAppointment()
|
||||
assert.strictEqual(navigations.pop(), '/pages/appointment-form/index?dateMode=manual')
|
||||
|
||||
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(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()
|
||||
assert.strictEqual(navigations.pop(), '/pages/appointment-form/index?date=2026-10-12&artistId=99')
|
||||
|
||||
const unconfiguredPage = createPage({ canCreateAppointment: true, businessHoursConfigured: false })
|
||||
unconfiguredPage.quickCreateAppointment({ currentTarget: { dataset: { date: '2099-12-31' } } })
|
||||
unconfiguredPage.createAppointment()
|
||||
assert.strictEqual(navigations.length, 0)
|
||||
assert.strictEqual(toasts.pop(), '请先在店铺设置中配置营业时间')
|
||||
unconfiguredPage.openShopSettings()
|
||||
assert.strictEqual(navigations.pop(), '/pages/shop-settings/index')
|
||||
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 => {
|
||||
|
||||
@@ -129,7 +129,7 @@
|
||||
|
||||
<view wx:if="{{viewMode === 'week'}}" class="section">
|
||||
<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-date">{{item.day}}</text>
|
||||
<text class="week-total">{{item.totalCount}}单</text>
|
||||
@@ -173,7 +173,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="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">
|
||||
<text class="month-day">{{item.day}}</text>
|
||||
<view class="month-cell-badges">
|
||||
|
||||
Reference in New Issue
Block a user