调整日程日期选择与预约入口
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)
|
||||
|
||||
Reference in New Issue
Block a user