功能:支持待分配预约与首次排班引导
This commit is contained in:
@@ -7,6 +7,7 @@ Page({
|
||||
appointment: {},
|
||||
avatarText: '',
|
||||
timeText: '',
|
||||
isUnassigned: false,
|
||||
loadError: ''
|
||||
},
|
||||
|
||||
@@ -32,6 +33,7 @@ Page({
|
||||
applyAppointment(appointment) {
|
||||
this.setData({
|
||||
appointment,
|
||||
isUnassigned: appointment.assignmentStatus === 'UNASSIGNED' || !appointment.artistId,
|
||||
avatarText: String(appointment.customerName || '客').slice(0, 1),
|
||||
timeText: `${(appointment.startTime || '').slice(0, 16)} - ${(appointment.endTime || '').slice(11, 16)}`,
|
||||
loadError: ''
|
||||
@@ -39,6 +41,10 @@ Page({
|
||||
},
|
||||
|
||||
async updateStatus(status) {
|
||||
if (status !== 3 && this.data.isUnassigned) {
|
||||
wx.showToast({ title: '请先分配员工', icon: 'none' })
|
||||
return
|
||||
}
|
||||
try {
|
||||
await planningApi.updateStatus(this.data.appointment.orderId, status)
|
||||
markPlanningRefresh()
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
</view>
|
||||
<view class="detail-actions">
|
||||
<text class="tag">{{appointment.statusText}}</text>
|
||||
<button class="small-action" bindtap="goTransfer">改派</button>
|
||||
<button class="small-action" bindtap="goTransfer">{{isUnassigned ? '分配员工' : '改派'}}</button>
|
||||
</view>
|
||||
</view>
|
||||
<view class="detail-grid">
|
||||
@@ -25,7 +25,7 @@
|
||||
</view>
|
||||
<view>
|
||||
<text class="label">美甲师</text>
|
||||
<text class="value">{{appointment.artistName}}</text>
|
||||
<text class="value">{{isUnassigned ? '待分配' : appointment.artistName}}</text>
|
||||
</view>
|
||||
<view>
|
||||
<text class="label">时间</text>
|
||||
@@ -44,8 +44,8 @@
|
||||
</view>
|
||||
|
||||
<view wx:if="{{!loadError}}" class="fixed-bottom action-row">
|
||||
<button class="secondary-btn" bindtap="confirm">确认</button>
|
||||
<button class="primary-btn" bindtap="complete">完成</button>
|
||||
<button class="secondary-btn" disabled="{{isUnassigned}}" bindtap="confirm">{{isUnassigned ? '待分配' : '确认'}}</button>
|
||||
<button class="primary-btn" disabled="{{isUnassigned}}" bindtap="complete">完成</button>
|
||||
<button class="danger-btn" bindtap="cancel">取消</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -170,6 +170,24 @@ function buildAvailableTimeGroups(calendar, form, durationMinutes) {
|
||||
.filter(group => group.times.length > 0)
|
||||
}
|
||||
|
||||
function buildUnassignedTimeGroups(durationMinutes) {
|
||||
const groupMap = {
|
||||
morning: { key: 'morning', title: '上午', times: [] },
|
||||
afternoon: { key: 'afternoon', title: '下午', times: [] },
|
||||
evening: { key: 'evening', title: '晚上', times: [] }
|
||||
}
|
||||
const businessStart = dateUtil.minutesOfDay('10:00')
|
||||
const businessEnd = dateUtil.minutesOfDay('22:00')
|
||||
for (let minute = businessStart; minute + durationMinutes <= businessEnd; minute += TIME_SLOT_MINUTES) {
|
||||
const period = getTimePeriod(minute)
|
||||
groupMap[period.key].times.push({
|
||||
value: dateUtil.timeFromMinutes(minute),
|
||||
rangeText: buildTimeRangeLabel(minute, durationMinutes)
|
||||
})
|
||||
}
|
||||
return Object.keys(groupMap).map(key => groupMap[key]).filter(group => group.times.length > 0)
|
||||
}
|
||||
|
||||
function flattenTimeGroups(groups) {
|
||||
return (groups || []).reduce((list, group) => list.concat(group.times || []), [])
|
||||
}
|
||||
@@ -611,9 +629,13 @@ Page({
|
||||
|
||||
filterArtistItems(artists, keywordValue) {
|
||||
const keyword = String(keywordValue || '').trim().toLowerCase()
|
||||
return (artists || [])
|
||||
const items = (artists || [])
|
||||
.filter(item => !keyword || String(item.name || '').toLowerCase().includes(keyword))
|
||||
.map(buildArtistSelectorItem)
|
||||
if (!keyword || '暂不分配'.includes(keyword)) {
|
||||
items.unshift({ id: '__unassigned__', title: '暂不分配', subtitle: '先记录预约,后续再分配员工', badge: '待分配' })
|
||||
}
|
||||
return items
|
||||
},
|
||||
|
||||
openArtistSheet() {
|
||||
@@ -641,6 +663,17 @@ Page({
|
||||
|
||||
selectArtist(event) {
|
||||
const selectedArtist = event.detail.item || {}
|
||||
if (selectedArtist.id === '__unassigned__') {
|
||||
this.setData({
|
||||
selectedArtist: {},
|
||||
'form.artistId': '',
|
||||
artistSheetVisible: false,
|
||||
conflictTip: '',
|
||||
conflictLevel: 'free'
|
||||
})
|
||||
this.refreshAvailableTimes()
|
||||
return
|
||||
}
|
||||
this.setData({
|
||||
selectedArtist,
|
||||
'form.artistId': selectedArtist.id,
|
||||
@@ -654,7 +687,7 @@ Page({
|
||||
addEmployeeFromSelector() {
|
||||
this.setData({ artistSheetVisible: false })
|
||||
wx.navigateTo({
|
||||
url: '/pages/employee-create/index?picker=1',
|
||||
url: `/pages/employee-create/index?picker=1&date=${encodeURIComponent(this.data.form.appointmentDate || '')}&time=${encodeURIComponent(this.data.form.appointmentTime || '')}&durationMinutes=${encodeURIComponent(this.data.form.durationMinutes || '')}`,
|
||||
success: result => {
|
||||
result.eventChannel.on('employeeCreated', employee => this.handleEmployeeCreated(employee))
|
||||
}
|
||||
@@ -662,15 +695,34 @@ Page({
|
||||
},
|
||||
|
||||
async handleEmployeeCreated(employee) {
|
||||
await this.loadArtists(employee.id, employee)
|
||||
this.setData({ 'form.appointmentTime': '' })
|
||||
const originalTime = this.data.form.appointmentTime
|
||||
await this.loadArtists(employee.autoSelect === false ? '' : employee.id, employee)
|
||||
if (employee.autoSelect === false) {
|
||||
this.setData({ selectedArtist: {}, 'form.artistId': '' })
|
||||
await this.refreshAvailableTimes()
|
||||
return
|
||||
}
|
||||
if (employee.scheduleSaved && originalTime) {
|
||||
const availability = await this.checkAvailability()
|
||||
if (!availability.ok) {
|
||||
this.setData({
|
||||
selectedArtist: {},
|
||||
'form.artistId': '',
|
||||
'form.appointmentTime': originalTime,
|
||||
conflictTip: `${availability.tip || '新员工当前排班无法承接'},预约已保持待分配`,
|
||||
conflictLevel: 'danger'
|
||||
})
|
||||
}
|
||||
} else {
|
||||
this.setData({ 'form.appointmentTime': '' })
|
||||
}
|
||||
await this.refreshAvailableTimes()
|
||||
this.checkAvailability()
|
||||
if (this.data.form.artistId) this.checkAvailability()
|
||||
},
|
||||
|
||||
canOpenTimeSheet() {
|
||||
const form = this.data.form
|
||||
return Boolean(form.appointmentDate && form.artistId && normalizeDuration(form.durationMinutes))
|
||||
return Boolean(form.appointmentDate && normalizeDuration(form.durationMinutes))
|
||||
},
|
||||
|
||||
async refreshAvailableTimes() {
|
||||
@@ -678,11 +730,11 @@ Page({
|
||||
const durationMinutes = normalizeDuration(form.durationMinutes)
|
||||
const requestSeq = (this._availableTimeRequestSeq || 0) + 1
|
||||
this._availableTimeRequestSeq = requestSeq
|
||||
if (!form.appointmentDate || !form.artistId || !durationMinutes) {
|
||||
if (!form.appointmentDate || !durationMinutes) {
|
||||
const patch = {
|
||||
availableTimeGroups: [],
|
||||
timeError: '',
|
||||
timeSelectTip: '请先选择美甲师并填写时长'
|
||||
timeSelectTip: '请先填写预约日期和时长'
|
||||
}
|
||||
if (form.appointmentTime) {
|
||||
patch['form.appointmentTime'] = ''
|
||||
@@ -690,6 +742,16 @@ Page({
|
||||
this.setData(patch)
|
||||
return
|
||||
}
|
||||
if (!form.artistId) {
|
||||
const availableTimeGroups = buildUnassignedTimeGroups(durationMinutes)
|
||||
this.setData({
|
||||
availableTimeGroups,
|
||||
timeError: '',
|
||||
timeLoading: false,
|
||||
timeSelectTip: '请选择预约时间,员工可稍后分配'
|
||||
})
|
||||
return
|
||||
}
|
||||
this.setData({
|
||||
timeLoading: true,
|
||||
timeError: '',
|
||||
@@ -732,7 +794,7 @@ Page({
|
||||
|
||||
async openTimeSheet() {
|
||||
if (!this.canOpenTimeSheet()) {
|
||||
wx.showToast({ title: '请先选择美甲师并填写时长', icon: 'none' })
|
||||
wx.showToast({ title: '请先填写预约日期和时长', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.setData({ timeSheetVisible: true })
|
||||
@@ -754,7 +816,7 @@ Page({
|
||||
|
||||
async checkAvailability() {
|
||||
const form = this.data.form
|
||||
if (!form.appointmentDate || !form.appointmentTime || !form.artistId) {
|
||||
if (!form.appointmentDate || !form.appointmentTime) {
|
||||
this.setData({ conflictTip: '', conflictLevel: 'free' })
|
||||
return { ok: true }
|
||||
}
|
||||
@@ -770,6 +832,11 @@ Page({
|
||||
this.setData({ conflictTip: tip, conflictLevel: 'danger' })
|
||||
return { ok: false, tip }
|
||||
}
|
||||
if (!form.artistId) {
|
||||
const tip = '预约将保存为待分配,当前不会占用员工时间'
|
||||
this.setData({ conflictTip: tip, conflictLevel: 'free' })
|
||||
return { ok: true, tip }
|
||||
}
|
||||
try {
|
||||
const calendar = await planningApi.calendar({
|
||||
startDate: form.appointmentDate,
|
||||
@@ -815,7 +882,7 @@ Page({
|
||||
const form = this.data.form
|
||||
const hasManualProduct = String(form.manualProductTitle || '').trim() && String(form.manualProductPrice || '').trim()
|
||||
const durationMinutes = normalizeDuration(form.durationMinutes)
|
||||
if (!form.customerName || !form.phone || (!form.productId && !hasManualProduct) || !form.artistId) {
|
||||
if (!form.customerName || !form.phone || (!form.productId && !hasManualProduct) || !form.appointmentDate || !form.appointmentTime) {
|
||||
wx.showToast({ title: '请补全预约信息', icon: 'none' })
|
||||
return
|
||||
}
|
||||
@@ -832,12 +899,25 @@ Page({
|
||||
wx.showToast({ title: availability.tip || '该时段已被预约', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!form.artistId) {
|
||||
const result = await new Promise(resolve => {
|
||||
wx.showModal({
|
||||
title: '保存为待分配预约',
|
||||
content: '当前未指定员工,预约会正常保存,但不会占用员工时间。可以稍后在预约详情中分配。',
|
||||
cancelText: '返回选择',
|
||||
confirmText: '继续保存',
|
||||
success: resolve,
|
||||
fail: () => resolve({ confirm: false })
|
||||
})
|
||||
})
|
||||
if (!result.confirm) return
|
||||
}
|
||||
this.setData({ loading: true })
|
||||
try {
|
||||
const payload = {
|
||||
...form,
|
||||
customerUserId: form.customerUserId ? String(form.customerUserId) : undefined,
|
||||
artistId: String(form.artistId),
|
||||
artistId: form.artistId ? String(form.artistId) : undefined,
|
||||
durationMinutes,
|
||||
clientRequestId: buildClientRequestId('manager-appointment')
|
||||
}
|
||||
|
||||
@@ -30,9 +30,9 @@
|
||||
<text class="unit">分钟</text>
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label required">指定员工</text>
|
||||
<text class="field-label">员工(可稍后分配)</text>
|
||||
<view class="field-value reference-value" bindtap="openArtistSheet">
|
||||
<text>{{selectedArtist.name || '请选择员工'}}</text>
|
||||
<text>{{selectedArtist.name || '暂不分配'}}</text>
|
||||
<text class="reference-arrow">›</text>
|
||||
</view>
|
||||
</view>
|
||||
@@ -41,7 +41,7 @@
|
||||
<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>
|
||||
<text wx:if="{{form.appointmentTime}}" class="time-range">{{form.appointmentDate}} · {{selectedArtist.name || '待分配'}} · {{form.durationMinutes}}分钟</text>
|
||||
</view>
|
||||
<text class="time-arrow">›</text>
|
||||
</view>
|
||||
@@ -54,7 +54,7 @@
|
||||
|
||||
<view class="capacity-tip card">
|
||||
<text class="tip-title">容量校验</text>
|
||||
<text class="tip-text">提交预约时会校验营业时间、美甲师休息和同时间段容量,冲突会直接拦截。</text>
|
||||
<text class="tip-text">已指定员工时会校验排班和冲突;暂不分配时只校验营业时间,后续分配时再完整校验。</text>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{draftSavedAtText}}" class="draft-tip card">
|
||||
@@ -183,13 +183,13 @@
|
||||
<view class="modal-head">
|
||||
<view>
|
||||
<text class="modal-title">选择预约时间</text>
|
||||
<text class="modal-subtitle">{{form.appointmentDate}} · {{selectedArtist.name}} · {{form.durationMinutes}}分钟</text>
|
||||
<text class="modal-subtitle">{{form.appointmentDate}} · {{selectedArtist.name || '待分配'}} · {{form.durationMinutes}}分钟</text>
|
||||
</view>
|
||||
<view class="modal-close" bindtap="closeTimeSheet">×</view>
|
||||
</view>
|
||||
<view wx:if="{{timeLoading}}" class="time-empty">正在计算可约时间...</view>
|
||||
<view wx:elif="{{timeError}}" class="time-empty">{{timeError}}</view>
|
||||
<view wx:elif="{{availableTimeGroups.length === 0}}" class="time-empty">当前美甲师当天暂无可约时间</view>
|
||||
<view wx:elif="{{availableTimeGroups.length === 0}}" class="time-empty">当前没有可选时间</view>
|
||||
<scroll-view wx:else class="time-list" scroll-y>
|
||||
<view wx:for="{{availableTimeGroups}}" wx:key="key" class="time-group">
|
||||
<text class="time-group-title">{{item.title}}</text>
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
const assert = require('assert')
|
||||
const planningApi = require('../../api/planning')
|
||||
|
||||
let redirectedTo = ''
|
||||
global.wx = {
|
||||
getAccountInfoSync: () => ({ miniProgram: { envVersion: 'develop' } }),
|
||||
getDeviceInfo: () => ({ platform: 'devtools' }),
|
||||
removeStorageSync: () => {},
|
||||
setStorageSync: () => {},
|
||||
showToast: () => {},
|
||||
showModal: ({ success }) => success({ confirm: true }),
|
||||
redirectTo: ({ url }) => { redirectedTo = url }
|
||||
}
|
||||
global.getApp = () => ({ globalData: {} })
|
||||
global.getCurrentPages = () => []
|
||||
|
||||
let definition
|
||||
global.Page = value => { definition = value }
|
||||
require('./index')
|
||||
|
||||
function createPage() {
|
||||
return {
|
||||
...definition,
|
||||
data: JSON.parse(JSON.stringify(definition.data)),
|
||||
setData(values) {
|
||||
Object.entries(values).forEach(([key, value]) => {
|
||||
const parts = key.split('.')
|
||||
let target = this.data
|
||||
for (let index = 0; index < parts.length - 1; index += 1) target = target[parts[index]]
|
||||
target[parts[parts.length - 1]] = value
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function run() {
|
||||
const page = createPage()
|
||||
Object.assign(page.data.form, {
|
||||
customerUserId: '31',
|
||||
customerName: '测试客户',
|
||||
phone: '13800138000',
|
||||
productId: '41',
|
||||
appointmentDate: '2026-10-13',
|
||||
appointmentTime: '14:00',
|
||||
durationMinutes: '60',
|
||||
artistId: ''
|
||||
})
|
||||
|
||||
await page.refreshAvailableTimes()
|
||||
assert.strictEqual(page.data.availableTimeGroups.length > 0, true)
|
||||
assert.strictEqual(page.data.timeSelectTip, '请选择预约时间,员工可稍后分配')
|
||||
const availability = await page.checkAvailability()
|
||||
assert.strictEqual(availability.ok, true)
|
||||
assert.strictEqual(page.data.conflictTip.includes('待分配'), true)
|
||||
|
||||
let submittedPayload
|
||||
planningApi.createAppointment = async payload => {
|
||||
submittedPayload = payload
|
||||
return { orderItemId: 61 }
|
||||
}
|
||||
await page.submit()
|
||||
|
||||
assert.strictEqual(submittedPayload.artistId, undefined)
|
||||
assert.strictEqual(submittedPayload.appointmentTime, '14:00')
|
||||
assert.strictEqual(redirectedTo, '/pages/appointment-detail/index?id=61')
|
||||
}
|
||||
|
||||
run().catch(error => {
|
||||
console.error(error)
|
||||
process.exitCode = 1
|
||||
})
|
||||
@@ -1,4 +1,5 @@
|
||||
const assert = require('assert')
|
||||
const planningApi = require('../../api/planning')
|
||||
|
||||
global.wx = {
|
||||
getAccountInfoSync: () => ({ miniProgram: { envVersion: 'develop' } }),
|
||||
@@ -18,12 +19,33 @@ const page = {
|
||||
setData(values) { Object.assign(this.data, values) }
|
||||
}
|
||||
|
||||
page.data.artists = [{ id: 1, name: '小周' }, { id: 2, name: '小李' }]
|
||||
page.onArtistSearch({ detail: { value: '周' } })
|
||||
assert.deepStrictEqual(page.data.artistItems.map(item => item.id), [1])
|
||||
assert.strictEqual(page.data.artistItems[0].avatar, '/assets/images/default-user-avatar.png')
|
||||
async function run() {
|
||||
page.data.artists = [{ id: 1, name: '小周' }, { id: 2, name: '小李' }]
|
||||
page.onArtistSearch({ detail: { value: '周' } })
|
||||
assert.deepStrictEqual(page.data.artistItems.map(item => item.id), [1])
|
||||
assert.strictEqual(page.data.artistItems[0].avatar, '/assets/images/default-user-avatar.png')
|
||||
|
||||
page.selectArtist({ detail: { item: page.data.artistItems[0] } })
|
||||
assert.strictEqual(page.data.selectedArtistId, 1)
|
||||
assert.strictEqual(page.data.selectedArtist.name, '小周')
|
||||
assert.strictEqual(page.data.artistSheetVisible, false)
|
||||
page.selectArtist({ detail: { item: page.data.artistItems[0] } })
|
||||
assert.strictEqual(page.data.selectedArtistId, 1)
|
||||
assert.strictEqual(page.data.selectedArtist.name, '小周')
|
||||
assert.strictEqual(page.data.artistSheetVisible, false)
|
||||
|
||||
page.data.id = '81'
|
||||
planningApi.appointment = async () => ({
|
||||
date: '2026-10-16',
|
||||
startTime: '2026-10-16 15:30:00',
|
||||
durationMinutes: 90,
|
||||
artistId: null,
|
||||
assignmentStatus: 'UNASSIGNED'
|
||||
})
|
||||
assert.strictEqual(await page.loadAppointment(), true)
|
||||
assert.strictEqual(page.data.date, '2026-10-16')
|
||||
assert.strictEqual(page.data.time, '15:30')
|
||||
assert.strictEqual(page.data.durationMinutes, 90)
|
||||
assert.strictEqual(page.data.isUnassigned, true)
|
||||
}
|
||||
|
||||
run().catch(error => {
|
||||
console.error(error)
|
||||
process.exitCode = 1
|
||||
})
|
||||
|
||||
@@ -13,15 +13,38 @@ Page({
|
||||
artistKeyword: '',
|
||||
date: dateUtil.formatDate(new Date()),
|
||||
time: '13:00',
|
||||
durationMinutes: '',
|
||||
isUnassigned: false,
|
||||
loadError: '',
|
||||
loading: false
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
async onLoad(options) {
|
||||
this.setData({
|
||||
id: options.id || ''
|
||||
})
|
||||
this.loadArtists()
|
||||
const loaded = await this.loadAppointment()
|
||||
if (!loaded) return
|
||||
await this.loadArtists()
|
||||
},
|
||||
|
||||
async loadAppointment() {
|
||||
if (!this.data.id) return false
|
||||
try {
|
||||
const appointment = await planningApi.appointment(this.data.id)
|
||||
const startTime = String(appointment.startTime || '')
|
||||
this.setData({
|
||||
date: appointment.date || startTime.slice(0, 10) || this.data.date,
|
||||
time: startTime.slice(11, 16) || this.data.time,
|
||||
durationMinutes: appointment.durationMinutes || '',
|
||||
isUnassigned: appointment.assignmentStatus === 'UNASSIGNED' || !appointment.artistId,
|
||||
loadError: ''
|
||||
})
|
||||
return true
|
||||
} catch (error) {
|
||||
this.setData({ loadError: error.message || '预约详情加载失败' })
|
||||
return false
|
||||
}
|
||||
},
|
||||
|
||||
async loadArtists(preferredArtistId, fallbackEmployee) {
|
||||
@@ -96,9 +119,11 @@ Page({
|
||||
addEmployeeFromSelector() {
|
||||
this.setData({ artistSheetVisible: false })
|
||||
wx.navigateTo({
|
||||
url: '/pages/employee-create/index?picker=1',
|
||||
url: `/pages/employee-create/index?picker=1&date=${encodeURIComponent(this.data.date || '')}&time=${encodeURIComponent(this.data.time || '')}&durationMinutes=${encodeURIComponent(this.data.durationMinutes || '')}`,
|
||||
success: result => {
|
||||
result.eventChannel.on('employeeCreated', employee => this.loadArtists(employee.id, employee))
|
||||
result.eventChannel.on('employeeCreated', employee => {
|
||||
this.loadArtists(employee.autoSelect === false ? '' : employee.id, employee)
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
@@ -122,10 +147,11 @@ Page({
|
||||
await planningApi.moveAppointment(this.data.id, {
|
||||
artistId: Number(this.data.selectedArtistId),
|
||||
appointmentDate: this.data.date,
|
||||
appointmentTime: this.data.time
|
||||
appointmentTime: this.data.time,
|
||||
durationMinutes: Number(this.data.durationMinutes) || undefined
|
||||
})
|
||||
markPlanningRefresh()
|
||||
wx.showToast({ title: '已改派' })
|
||||
wx.showToast({ title: this.data.isUnassigned ? '已分配' : '已改派' })
|
||||
setTimeout(() => wx.navigateBack(), 500)
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '改派失败', icon: 'none' })
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<view class="page no-tab">
|
||||
<view class="card form-card section">
|
||||
<view class="field">
|
||||
<text class="field-label required">改派员工</text>
|
||||
<text class="field-label required">{{isUnassigned ? '分配员工' : '改派员工'}}</text>
|
||||
<view class="field-value transfer-reference" bindtap="openArtistSheet">
|
||||
<view>
|
||||
<text>{{selectedArtist.name || '请选择员工'}}</text>
|
||||
@@ -11,13 +11,13 @@
|
||||
</view>
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label required">新日期</text>
|
||||
<text class="field-label required">预约日期</text>
|
||||
<picker mode="date" value="{{date}}" bindchange="onDateChange">
|
||||
<view class="field-value">{{date}}</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label required">新时间</text>
|
||||
<text class="field-label required">预约时间</text>
|
||||
<picker mode="time" value="{{time}}" start="10:00" end="22:00" bindchange="onTimeChange">
|
||||
<view class="field-value">{{time}}</view>
|
||||
</picker>
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
<entity-selector-sheet
|
||||
visible="{{artistSheetVisible}}"
|
||||
title="选择改派员工"
|
||||
title="{{isUnassigned ? '选择分配员工' : '选择改派员工'}}"
|
||||
keyword="{{artistKeyword}}"
|
||||
placeholder="搜索员工姓名"
|
||||
items="{{artistItems}}"
|
||||
@@ -43,6 +43,6 @@
|
||||
/>
|
||||
|
||||
<view class="fixed-bottom">
|
||||
<button class="primary-btn" loading="{{loading}}" bindtap="submit">确认改派</button>
|
||||
<button class="primary-btn" loading="{{loading}}" bindtap="submit">{{isUnassigned ? '确认分配' : '确认改派'}}</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -6,6 +6,9 @@ const DEFAULT_EMPLOYEE_PASSWORD = 'Fingertip@123'
|
||||
Page({
|
||||
data: {
|
||||
pickerMode: false,
|
||||
appointmentContext: { date: '', time: '', durationMinutes: '' },
|
||||
onboardingVisible: false,
|
||||
createdEmployee: null,
|
||||
form: {
|
||||
nickname: '',
|
||||
phone: '',
|
||||
@@ -20,7 +23,14 @@ Page({
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
this.setData({ pickerMode: options && options.picker === '1' })
|
||||
this.setData({
|
||||
pickerMode: options && options.picker === '1',
|
||||
appointmentContext: {
|
||||
date: options.date || '',
|
||||
time: options.time || '',
|
||||
durationMinutes: options.durationMinutes || ''
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
onInput(event) {
|
||||
@@ -54,6 +64,9 @@ Page({
|
||||
this.setData({ 'form.avatar': '', 'form.avatarUrl': '' })
|
||||
},
|
||||
|
||||
stopTouchMove() {
|
||||
},
|
||||
|
||||
async submit() {
|
||||
const form = this.data.form
|
||||
const nickname = String(form.nickname || '').trim()
|
||||
@@ -83,14 +96,48 @@ Page({
|
||||
})
|
||||
const id = result && typeof result === 'object' ? (result.id || result.userId) : result
|
||||
const employee = { id, name: nickname, title: nickname, avatar: form.avatar || '' }
|
||||
const eventChannel = this.getOpenerEventChannel && this.getOpenerEventChannel()
|
||||
if (eventChannel && eventChannel.emit) eventChannel.emit('employeeCreated', employee)
|
||||
wx.showToast({ title: '员工已新增', icon: 'success' })
|
||||
setTimeout(() => wx.navigateBack(), 450)
|
||||
this.setData({ createdEmployee: employee, onboardingVisible: true })
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '新增失败', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ creating: false })
|
||||
}
|
||||
},
|
||||
|
||||
setupFirstSchedule() {
|
||||
const employee = this.data.createdEmployee
|
||||
if (!employee || !employee.id) return
|
||||
const context = this.data.appointmentContext
|
||||
const query = [
|
||||
`id=${encodeURIComponent(employee.id)}`,
|
||||
'onboarding=1',
|
||||
`source=${this.data.pickerMode ? 'appointment' : 'employees'}`,
|
||||
`date=${encodeURIComponent(context.date || '')}`,
|
||||
`time=${encodeURIComponent(context.time || '')}`,
|
||||
`durationMinutes=${encodeURIComponent(context.durationMinutes || '')}`
|
||||
]
|
||||
wx.navigateTo({
|
||||
url: `/pages/schedule-setting/index?${query.join('&')}`,
|
||||
success: result => {
|
||||
result.eventChannel.on('scheduleSaved', () => {
|
||||
setTimeout(() => this.finishCreated(true, true), 250)
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
skipFirstSchedule() {
|
||||
this.finishCreated(!this.data.pickerMode, false)
|
||||
},
|
||||
|
||||
finishCreated(autoSelect, scheduleSaved) {
|
||||
const employee = this.data.createdEmployee
|
||||
const eventChannel = this.getOpenerEventChannel && this.getOpenerEventChannel()
|
||||
if (eventChannel && eventChannel.emit) {
|
||||
eventChannel.emit('employeeCreated', { ...employee, autoSelect, scheduleSaved })
|
||||
}
|
||||
this.setData({ onboardingVisible: false })
|
||||
wx.showToast({ title: scheduleSaved ? '排班已保存' : '员工已新增', icon: 'success' })
|
||||
setTimeout(() => wx.navigateBack(), 300)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -2,11 +2,13 @@ const assert = require('assert')
|
||||
const employeesApi = require('../../api/employees')
|
||||
|
||||
let navigatedBack = false
|
||||
let navigatedTo = ''
|
||||
global.wx = {
|
||||
getAccountInfoSync: () => ({ miniProgram: { envVersion: 'develop' } }),
|
||||
getDeviceInfo: () => ({ platform: 'devtools' }),
|
||||
showToast: () => {},
|
||||
navigateBack: () => { navigatedBack = true }
|
||||
navigateBack: () => { navigatedBack = true },
|
||||
navigateTo: options => { navigatedTo = options.url }
|
||||
}
|
||||
global.setTimeout = callback => { callback(); return 1 }
|
||||
|
||||
@@ -41,9 +43,19 @@ async function run() {
|
||||
})
|
||||
employeesApi.createUser = async () => 88
|
||||
await page.submit()
|
||||
assert.strictEqual(page.data.onboardingVisible, true)
|
||||
assert.strictEqual(emitted, undefined)
|
||||
page.data.pickerMode = true
|
||||
page.skipFirstSchedule()
|
||||
assert.strictEqual(emitted.name, 'employeeCreated')
|
||||
assert.deepStrictEqual(emitted.value, { id: 88, name: '小周', title: '小周', avatar: '' })
|
||||
assert.deepStrictEqual(emitted.value, { id: 88, name: '小周', title: '小周', avatar: '', autoSelect: false, scheduleSaved: false })
|
||||
assert.strictEqual(navigatedBack, true)
|
||||
|
||||
page.data.onboardingVisible = true
|
||||
page.data.createdEmployee = { id: 88, name: '小周' }
|
||||
page.data.appointmentContext = { date: '2026-10-12', time: '14:00', durationMinutes: '60' }
|
||||
page.setupFirstSchedule()
|
||||
assert.strictEqual(navigatedTo.includes('/pages/schedule-setting/index?id=88&onboarding=1&source=appointment'), true)
|
||||
}
|
||||
|
||||
run().catch(error => {
|
||||
|
||||
@@ -41,4 +41,14 @@
|
||||
<view class="fixed-bottom">
|
||||
<button class="primary-btn" loading="{{creating}}" disabled="{{avatarUploading || creating}}" bindtap="submit">保存员工</button>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{onboardingVisible}}" class="onboarding-mask" catchtouchmove="stopTouchMove">
|
||||
<view class="onboarding-card">
|
||||
<view class="onboarding-icon">✓</view>
|
||||
<text class="onboarding-title">员工已创建</text>
|
||||
<text class="onboarding-desc">{{pickerMode ? '设置常规排班后,可继续把当前预约分配给该员工。' : '为新员工设置首个常规排班,之后即可正常承接预约。'}}</text>
|
||||
<button class="primary-btn onboarding-primary" bindtap="setupFirstSchedule">{{pickerMode ? '设置排班并分配' : '立即设置排班'}}</button>
|
||||
<button class="onboarding-skip" bindtap="skipFirstSchedule">{{pickerMode ? '暂不设置' : '稍后设置'}}</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -79,3 +79,43 @@
|
||||
.create-form .field-label {
|
||||
width: 176rpx;
|
||||
}
|
||||
|
||||
.onboarding-mask {
|
||||
position: fixed;
|
||||
z-index: 50;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 44rpx;
|
||||
background: rgba(34, 39, 36, 0.58);
|
||||
}
|
||||
|
||||
.onboarding-card {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 42rpx 34rpx 28rpx;
|
||||
border-radius: 28rpx;
|
||||
background: #fffdf8;
|
||||
}
|
||||
|
||||
.onboarding-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 82rpx;
|
||||
height: 82rpx;
|
||||
border-radius: 50%;
|
||||
background: #e5eee9;
|
||||
color: #39705d;
|
||||
font-size: 38rpx;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.onboarding-title { margin-top: 22rpx; color: #29241f; font-size: 32rpx; font-weight: 900; }
|
||||
.onboarding-desc { margin-top: 12rpx; color: #837b72; font-size: 23rpx; line-height: 1.7; text-align: center; }
|
||||
.onboarding-primary { width: 100%; margin-top: 30rpx; }
|
||||
.onboarding-skip { margin-top: 12rpx; background: transparent; color: #7e776f; font-size: 23rpx; }
|
||||
|
||||
@@ -84,6 +84,9 @@ Page({
|
||||
dayTotal: 0,
|
||||
freeArtistCount: 0,
|
||||
pendingCount: 0,
|
||||
unassignedCount: 0,
|
||||
rangeUnassignedCount: 0,
|
||||
nearestUnassignedDate: '',
|
||||
canCreateAppointment: true,
|
||||
loading: false,
|
||||
calendarError: '',
|
||||
@@ -327,7 +330,10 @@ Page({
|
||||
hours: [],
|
||||
dayTotal: 0,
|
||||
freeArtistCount: 0,
|
||||
pendingCount: 0
|
||||
pendingCount: 0,
|
||||
unassignedCount: 0,
|
||||
rangeUnassignedCount: 0,
|
||||
nearestUnassignedDate: ''
|
||||
})
|
||||
},
|
||||
|
||||
@@ -362,6 +368,8 @@ Page({
|
||||
businessEndTime: snapshot.businessEndTime,
|
||||
artists: snapshot.artists,
|
||||
calendarError: '',
|
||||
rangeUnassignedCount: snapshot.appointments.filter(item => !item.artistId).length,
|
||||
nearestUnassignedDate: this.findNearestUnassignedDate(snapshot.appointments),
|
||||
...this.buildViewState(snapshot)
|
||||
})
|
||||
},
|
||||
@@ -411,11 +419,16 @@ Page({
|
||||
}))
|
||||
return dateUtil.monthGrid(this.data.currentDateText).map(day => {
|
||||
const summary = summaryMap[day.date] || {}
|
||||
const artistCounts = this.normalizeArtistCounts(summary.artistCounts || artistTemplate, calendar)
|
||||
const unassignedCount = Number(summary.unassignedCount || 0)
|
||||
const artistCounts = this.withUnassignedCount(
|
||||
this.normalizeArtistCounts(summary.artistCounts || artistTemplate, calendar),
|
||||
unassignedCount
|
||||
)
|
||||
return {
|
||||
...day,
|
||||
isPast: day.date < todayText,
|
||||
totalCount: summary.totalCount || 0,
|
||||
unassignedCount,
|
||||
dayStatus: summary.dayStatus || 'free',
|
||||
artistCounts,
|
||||
expandedBlocks: this.data.monthDisplayMode === 'blocks' ? this.buildExpandedBlocks(artistCounts) : [],
|
||||
@@ -431,12 +444,17 @@ Page({
|
||||
const target = dateUtil.addDays(start, index)
|
||||
const date = dateUtil.formatDate(target)
|
||||
const summary = summaryMap[date] || { artistCounts: [], totalCount: 0 }
|
||||
const artistCounts = this.normalizeArtistCounts(summary.artistCounts || [], calendar).filter(count => count.count > 0)
|
||||
const unassignedCount = Number(summary.unassignedCount || 0)
|
||||
const artistCounts = this.withUnassignedCount(
|
||||
this.normalizeArtistCounts(summary.artistCounts || [], calendar),
|
||||
unassignedCount
|
||||
).filter(count => count.count > 0)
|
||||
return {
|
||||
date,
|
||||
weekName: `周${label}`,
|
||||
day: target.getDate(),
|
||||
totalCount: summary.totalCount || 0,
|
||||
unassignedCount,
|
||||
artistCounts: artistCounts.map(count => ({
|
||||
...count,
|
||||
width: Math.max(12, Math.min(100, count.count * 22)),
|
||||
@@ -463,7 +481,7 @@ Page({
|
||||
? (calendar.artists || []).filter(item => String(item.id) === String(this.data.selectedArtistId))
|
||||
: (calendar.artists || [])
|
||||
const dayAppointments = (calendar.appointments || []).filter(item => resolveAppointmentDate(item) === this.data.currentDateText)
|
||||
const lanes = filteredArtists.map(artist => {
|
||||
const employeeLanes = filteredArtists.map(artist => {
|
||||
const blocks = dayAppointments
|
||||
.filter(item => String(item.artistId) === String(artist.id))
|
||||
.map(item => {
|
||||
@@ -475,8 +493,27 @@ Page({
|
||||
timeText: resolveAppointmentTimeText(item)
|
||||
}
|
||||
})
|
||||
return { ...artist, blocks }
|
||||
return { ...artist, artistId: artist.id, blocks }
|
||||
})
|
||||
const unassignedBlocks = dayAppointments
|
||||
.filter(item => !item.artistId)
|
||||
.map(item => {
|
||||
const itemStart = resolveAppointmentStartMinute(item)
|
||||
return {
|
||||
...item,
|
||||
top: Math.max(0, itemStart - startMinute) + laneHeaderHeight,
|
||||
height: Math.max(64, item.durationMinutes || 60),
|
||||
timeText: resolveAppointmentTimeText(item)
|
||||
}
|
||||
})
|
||||
const lanes = this.data.selectedArtistId ? employeeLanes : [{
|
||||
id: '__unassigned__',
|
||||
artistId: '__unassigned__',
|
||||
name: '待分配',
|
||||
color: '#D59A52',
|
||||
blocks: unassignedBlocks,
|
||||
emptyText: '暂无待分配'
|
||||
}, ...employeeLanes]
|
||||
const pendingCount = dayAppointments.filter(item => item.status === 0).length
|
||||
return {
|
||||
dayLanes: lanes,
|
||||
@@ -486,11 +523,48 @@ Page({
|
||||
laneItemWidth: 248,
|
||||
laneWidth: Math.max(720, lanes.length * 248),
|
||||
dayTotal: dayAppointments.length,
|
||||
freeArtistCount: lanes.filter(item => item.blocks.length === 0).length,
|
||||
pendingCount
|
||||
freeArtistCount: employeeLanes.filter(item => item.blocks.length === 0).length,
|
||||
pendingCount,
|
||||
unassignedCount: unassignedBlocks.length
|
||||
}
|
||||
},
|
||||
|
||||
withUnassignedCount(artistCounts, unassignedCount) {
|
||||
if (!unassignedCount) return artistCounts
|
||||
return [{
|
||||
artistId: '__unassigned__',
|
||||
artistName: '待分配',
|
||||
shortName: '待',
|
||||
color: '#D59A52',
|
||||
count: unassignedCount,
|
||||
status: 'pending'
|
||||
}, ...(artistCounts || [])]
|
||||
},
|
||||
|
||||
findNearestUnassignedDate(appointments) {
|
||||
const dates = (appointments || [])
|
||||
.filter(item => !item.artistId)
|
||||
.map(resolveAppointmentDate)
|
||||
.filter(Boolean)
|
||||
.sort()
|
||||
if (!dates.length) return ''
|
||||
const today = dateUtil.formatDate(new Date())
|
||||
return dates.find(date => date >= today) || dates[0]
|
||||
},
|
||||
|
||||
openNearestUnassigned() {
|
||||
if (!this.data.nearestUnassignedDate) return
|
||||
const target = this.data.nearestUnassignedDate
|
||||
this.setData({
|
||||
viewMode: 'day',
|
||||
currentDate: toLocalDate(target),
|
||||
currentDateText: target,
|
||||
selectedArtistId: '',
|
||||
selectedArtistName: '全部员工'
|
||||
})
|
||||
this.loadCalendar()
|
||||
},
|
||||
|
||||
summaryMap(calendar) {
|
||||
return (calendar.daySummaries || []).reduce((map, item) => {
|
||||
map[item.date] = item
|
||||
|
||||
@@ -60,10 +60,21 @@ async function run() {
|
||||
page.data.monthDisplayMode = 'count'
|
||||
const monthDays = definition.buildMonthDays.call(page, {
|
||||
artists: [{ id: 1, name: '员工', shortName: '员', color: '#000' }],
|
||||
daySummaries: []
|
||||
daySummaries: [{ date: dateUtil.formatDate(dateUtil.startOfMonth(page.data.currentDateText)), totalCount: 2, unassignedCount: 1, artistCounts: [] }]
|
||||
})
|
||||
assert.strictEqual(monthDays.length, 42)
|
||||
assert.strictEqual(monthDays.every(item => item.expandedBlocks.length === 0 && item.rowBlocks.length === 0), true)
|
||||
assert.strictEqual(monthDays.some(item => item.artistCounts.some(count => count.artistId === '__unassigned__' && count.count === 1)), true)
|
||||
|
||||
const dayPage = createPage({ currentDateText: '2026-10-12', selectedArtistId: '' })
|
||||
const dayState = dayPage.buildDayView({
|
||||
businessStartTime: '10:00',
|
||||
businessEndTime: '22:00',
|
||||
artists: [{ id: 1, name: '员工', color: '#000' }],
|
||||
appointments: [{ orderItemId: 8, date: '2026-10-12', startTime: '2026-10-12 14:00:00', durationMinutes: 60, artistId: null }]
|
||||
})
|
||||
assert.strictEqual(dayState.dayLanes[0].artistId, '__unassigned__')
|
||||
assert.strictEqual(dayState.dayLanes[0].blocks.length, 1)
|
||||
assert.strictEqual(dayState.unassignedCount, 1)
|
||||
|
||||
const requestPage = createPage({ viewMode: 'day', currentDateText: '2026-10-11' })
|
||||
let calendarRequests = 0
|
||||
|
||||
@@ -28,6 +28,11 @@
|
||||
<text class="chip-count">{{item.rangeCount || 0}}</text>
|
||||
</view>
|
||||
</scroll-view>
|
||||
<view wx:if="{{!selectedArtistId && rangeUnassignedCount > 0}}" class="unassigned-notice" bindtap="openNearestUnassigned">
|
||||
<view class="chip-dot unassigned-dot"></view>
|
||||
<text>有 {{rangeUnassignedCount}} 个预约待分配员工</text>
|
||||
<text class="unassigned-link">立即处理 ›</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{profilePromptVisible}}" class="profile-prompt-mask">
|
||||
@@ -65,6 +70,10 @@
|
||||
<text class="summary-value">{{pendingCount}}</text>
|
||||
<text class="summary-label">待确认</text>
|
||||
</view>
|
||||
<view class="summary-item card unassigned-summary">
|
||||
<text class="summary-value">{{unassignedCount}}</text>
|
||||
<text class="summary-label">待分配</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<scroll-view class="day-board card" scroll-y>
|
||||
@@ -84,12 +93,12 @@
|
||||
<text class="block-meta">{{block.timeText}} · {{block.productTitle}}</text>
|
||||
<text class="block-status">{{block.statusText}}</text>
|
||||
<view class="block-actions" catchtap="stopTap">
|
||||
<text wx:if="{{block.status === 0}}" data-id="{{block.orderItemId}}" data-status="1" catchtap="quickUpdateStatus">确认</text>
|
||||
<text data-id="{{block.orderItemId}}" catchtap="quickTransfer">改派</text>
|
||||
<text wx:if="{{block.status === 0 && block.assignmentStatus !== 'UNASSIGNED'}}" data-id="{{block.orderItemId}}" data-status="1" catchtap="quickUpdateStatus">确认</text>
|
||||
<text data-id="{{block.orderItemId}}" catchtap="quickTransfer">{{block.assignmentStatus === 'UNASSIGNED' ? '分配' : '改派'}}</text>
|
||||
<text data-id="{{block.orderItemId}}" catchtap="quickCancel">取消</text>
|
||||
</view>
|
||||
</view>
|
||||
<view wx:if="{{item.blocks.length === 0}}" class="lane-empty">全天可约</view>
|
||||
<view wx:if="{{item.blocks.length === 0}}" class="lane-empty">{{item.emptyText || '全天可约'}}</view>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
@@ -236,12 +236,38 @@
|
||||
color: #9a9288;
|
||||
}
|
||||
|
||||
.unassigned-notice {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-top: 14rpx;
|
||||
padding: 14rpx 16rpx;
|
||||
border-radius: 12rpx;
|
||||
background: #fff4e5;
|
||||
color: #8b5e24;
|
||||
font-size: 22rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.unassigned-dot {
|
||||
flex: none;
|
||||
background: #d59a52;
|
||||
}
|
||||
|
||||
.unassigned-link {
|
||||
margin-left: auto;
|
||||
color: #a56b24;
|
||||
}
|
||||
|
||||
.day-summary {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 12rpx;
|
||||
}
|
||||
|
||||
.unassigned-summary .summary-value {
|
||||
color: #c57d27;
|
||||
}
|
||||
|
||||
.summary-item {
|
||||
padding: 16rpx;
|
||||
}
|
||||
|
||||
@@ -68,6 +68,9 @@ function buildExceptionSummary(item) {
|
||||
Page({
|
||||
data: {
|
||||
artistId: '',
|
||||
onboarding: false,
|
||||
onboardingSource: '',
|
||||
appointmentContextText: '',
|
||||
presets: PRESETS,
|
||||
presetOptions: buildPresetOptions('DOUBLE_REST'),
|
||||
weekdays: WEEKDAYS,
|
||||
@@ -95,7 +98,13 @@ Page({
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
this.setData({ artistId: options.id || '' })
|
||||
const contextParts = [options.date, options.time, options.durationMinutes ? `${options.durationMinutes}分钟` : ''].filter(Boolean)
|
||||
this.setData({
|
||||
artistId: options.id || '',
|
||||
onboarding: options.onboarding === '1',
|
||||
onboardingSource: options.source || '',
|
||||
appointmentContextText: contextParts.join(' · ')
|
||||
})
|
||||
this.loadRule()
|
||||
},
|
||||
|
||||
@@ -235,7 +244,13 @@ Page({
|
||||
})
|
||||
markPlanningRefresh()
|
||||
wx.showToast({ title: '排班规则已保存', icon: 'success' })
|
||||
await this.loadRule()
|
||||
if (this.data.onboarding) {
|
||||
const eventChannel = this.getOpenerEventChannel && this.getOpenerEventChannel()
|
||||
if (eventChannel && eventChannel.emit) eventChannel.emit('scheduleSaved', { artistId: this.data.artistId })
|
||||
setTimeout(() => wx.navigateBack(), 250)
|
||||
} else {
|
||||
await this.loadRule()
|
||||
}
|
||||
} catch (error) {
|
||||
const message = error.message || '保存失败'
|
||||
wx.showModal({ title: '排班保存失败', content: message, showCancel: false, confirmText: '知道了' })
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
const assert = require('assert')
|
||||
const employeesApi = require('../../api/employees')
|
||||
|
||||
let navigatedBack = false
|
||||
global.wx = {
|
||||
getAccountInfoSync: () => ({ miniProgram: { envVersion: 'develop' } }),
|
||||
getDeviceInfo: () => ({ platform: 'devtools' }),
|
||||
setStorageSync: () => {},
|
||||
showToast: () => {},
|
||||
showModal: () => {},
|
||||
navigateBack: () => { navigatedBack = true }
|
||||
}
|
||||
global.getApp = () => ({ globalData: {} })
|
||||
global.getCurrentPages = () => []
|
||||
global.setTimeout = callback => { callback(); return 1 }
|
||||
|
||||
let definition
|
||||
global.Page = value => { definition = value }
|
||||
require('./index')
|
||||
|
||||
let emitted
|
||||
const page = {
|
||||
...definition,
|
||||
data: JSON.parse(JSON.stringify(definition.data)),
|
||||
getOpenerEventChannel: () => ({ emit: (name, value) => { emitted = { name, value } } }),
|
||||
setData(values) {
|
||||
Object.entries(values).forEach(([key, value]) => {
|
||||
const parts = key.split('.')
|
||||
let target = this.data
|
||||
for (let index = 0; index < parts.length - 1; index += 1) target = target[parts[index]]
|
||||
target[parts[parts.length - 1]] = value
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async function run() {
|
||||
page.data.artistId = '88'
|
||||
page.data.onboarding = true
|
||||
page.data.onboardingSource = 'appointment'
|
||||
employeesApi.saveScheduleRule = async payload => {
|
||||
assert.strictEqual(payload.artistId, '88')
|
||||
assert.deepStrictEqual(payload.workDays, [1, 2, 3, 4, 5])
|
||||
}
|
||||
|
||||
await page.save()
|
||||
|
||||
assert.deepStrictEqual(emitted, { name: 'scheduleSaved', value: { artistId: '88' } })
|
||||
assert.strictEqual(navigatedBack, true)
|
||||
}
|
||||
|
||||
run().catch(error => {
|
||||
console.error(error)
|
||||
process.exitCode = 1
|
||||
})
|
||||
@@ -1,4 +1,8 @@
|
||||
<view class="page no-tab">
|
||||
<view wx:if="{{onboarding}}" class="onboarding-context card">
|
||||
<text class="onboarding-context-title">首次排班设置</text>
|
||||
<text class="onboarding-context-desc">{{appointmentContextText ? '待承接预约:' + appointmentContextText : '保存常规排班后,员工即可开始承接预约。'}}</text>
|
||||
</view>
|
||||
<view class="section">
|
||||
<view class="section-title">常规排班</view>
|
||||
<view class="card rule-card">
|
||||
@@ -28,7 +32,7 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<view wx:if="{{!onboarding}}" class="section">
|
||||
<view class="section-title">特殊日期</view>
|
||||
<view class="card rule-card">
|
||||
<view class="field">
|
||||
@@ -63,6 +67,6 @@
|
||||
</view>
|
||||
|
||||
<view class="fixed-bottom">
|
||||
<button class="primary-btn" loading="{{saving}}" bindtap="save">保存排班规则</button>
|
||||
<button class="primary-btn" loading="{{saving}}" bindtap="save">{{onboarding && onboardingSource === 'appointment' ? '保存排班并继续分配' : '保存排班规则'}}</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -2,6 +2,19 @@
|
||||
padding: 20rpx 24rpx;
|
||||
}
|
||||
|
||||
.onboarding-context {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8rpx;
|
||||
margin-bottom: 20rpx;
|
||||
padding: 22rpx 24rpx;
|
||||
border-left: 8rpx solid #d59a52;
|
||||
background: #fff7ea;
|
||||
}
|
||||
|
||||
.onboarding-context-title { color: #70481c; font-size: 27rpx; font-weight: 900; }
|
||||
.onboarding-context-desc { color: #8d673b; font-size: 22rpx; line-height: 1.6; }
|
||||
|
||||
.preset-grid,
|
||||
.weekday-grid {
|
||||
display: flex;
|
||||
|
||||
Reference in New Issue
Block a user