功能:支持待分配预约与首次排班引导
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user