完善小程序排班与预约快捷操作

This commit is contained in:
2026-09-04 16:13:58 +08:00
parent 4209ee732c
commit 9ac56115d0
6 changed files with 88 additions and 6 deletions
+21 -2
View File
@@ -1,4 +1,6 @@
const employeesApi = require('../../api/employees')
const planningApi = require('../../api/planning')
const dateUtil = require('../../utils/date')
const { chooseImageFilePath, uploadObjectFile } = require('../../utils/upload')
const EMPLOYEE_COLORS = ['#7AA9C2', '#8EB99B', '#BDA7D8', '#D7B17D', '#D98D8D']
@@ -34,8 +36,14 @@ Page({
async loadEmployees() {
try {
const data = await employeesApi.list({ page: 1, size: 50 })
const today = dateUtil.formatDate(new Date())
const [data, calendar] = await Promise.all([
employeesApi.list({ page: 1, size: 50 }),
planningApi.calendar({ startDate: today, endDate: today })
])
const list = data.list || data || []
const appointments = calendar.appointments || []
const artists = calendar.artists || []
this.setData({
loadError: '',
employees: list.map((item, index) => ({
@@ -46,7 +54,18 @@ Page({
color: EMPLOYEE_COLORS[index % EMPLOYEE_COLORS.length],
monthOrders: item.monthOrders || item.orderCount || 0,
monthAmount: item.monthAmount || item.turnover || 0,
scheduleSummary: buildScheduleSummary(item)
scheduleSummary: buildScheduleSummary(item),
todaySchedule: (() => {
const artist = artists.find(entry => String(entry.id) === String(item.userId || item.id))
return artist && artist.workStartTime && artist.workEndTime
? `${artist.workStartTime.slice(0, 5)}-${artist.workEndTime.slice(0, 5)}`
: '今日未排班'
})(),
todayAvailable: (() => {
const artist = artists.find(entry => String(entry.id) === String(item.userId || item.id))
return !!artist && Number(artist.status) !== 0
})(),
todayOrders: appointments.filter(entry => String(entry.artistId) === String(item.userId || item.id)).length
}))
})
} catch (error) {
+2 -2
View File
@@ -18,8 +18,8 @@
<view wx:else class="avatar" style="background: {{item.color}};">{{item.shortName}}</view>
<view>
<text class="employee-name">{{item.name}}</text>
<text class="employee-schedule">{{item.scheduleSummary}}</text>
<text class="employee-meta">本月 {{item.monthOrders}} 单 · ¥{{item.monthAmount}}</text>
<text class="employee-schedule">{{item.todaySchedule}} · {{item.todayAvailable ? '可预约' : '休息中'}}</text>
<text class="employee-meta">今日 {{item.todayOrders}} 单 · 本月 {{item.monthOrders}} 单</text>
</view>
</view>
<view class="color-pill" style="background: {{item.color}};"></view>
+43
View File
@@ -418,5 +418,48 @@ Page({
wx.navigateTo({
url: `/pages/appointment-detail/index?id=${event.currentTarget.dataset.id}`
})
},
stopTap() {
},
async quickUpdateStatus(event) {
const appointment = this.data.appointments.find(item => String(item.orderItemId) === String(event.currentTarget.dataset.id))
if (!appointment) return
try {
await planningApi.updateStatus(appointment.orderId, Number(event.currentTarget.dataset.status))
wx.showToast({ title: '预约已确认', icon: 'success' })
this.loadCalendar()
} catch (error) {
wx.showToast({ title: error.message || '预约状态更新失败', icon: 'none' })
}
},
quickTransfer(event) {
wx.navigateTo({ url: `/pages/artist-transfer/index?id=${event.currentTarget.dataset.id}` })
},
quickCancel(event) {
const appointment = this.data.appointments.find(item => String(item.orderItemId) === String(event.currentTarget.dataset.id))
if (!appointment) return
wx.showModal({
title: '取消预约',
content: '确定取消这条预约吗?',
success: result => {
if (result.confirm) {
this.updateAppointmentStatus(appointment.orderId, 3)
}
}
})
},
async updateAppointmentStatus(orderId, status) {
try {
await planningApi.updateStatus(orderId, status)
wx.showToast({ title: '预约已取消', icon: 'success' })
this.loadCalendar()
} catch (error) {
wx.showToast({ title: error.message || '预约取消失败', icon: 'none' })
}
}
})
@@ -67,6 +67,11 @@
<text class="block-title">{{block.customerName}}</text>
<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 data-id="{{block.orderItemId}}" catchtap="quickCancel">取消</text>
</view>
</view>
<view wx:if="{{item.blocks.length === 0}}" class="lane-empty">全天可约</view>
</view>
+13
View File
@@ -320,6 +320,19 @@
line-height: 1.25;
}
.block-actions {
display: flex;
gap: 10rpx;
margin-top: 6rpx;
color: #2f6f62;
font-size: 20rpx;
font-weight: 800;
}
.block-actions text {
padding: 2rpx 6rpx;
}
.lane-empty {
position: absolute;
top: 76rpx;
@@ -237,7 +237,8 @@ Page({
wx.showToast({ title: '排班规则已保存', icon: 'success' })
await this.loadRule()
} catch (error) {
wx.showToast({ title: error.message || '保存失败', icon: 'none' })
const message = error.message || '保存失败'
wx.showModal({ title: '排班保存失败', content: message, showCancel: false, confirmText: '知道了' })
} finally {
this.setData({ saving: false })
}
@@ -267,7 +268,8 @@ Page({
wx.showToast({ title: '例外已保存', icon: 'success' })
await this.loadRule()
} catch (error) {
wx.showToast({ title: error.message || '例外保存失败', icon: 'none' })
const message = error.message || '例外保存失败'
wx.showModal({ title: '特殊日期保存失败', content: message, showCancel: false, confirmText: '知道了' })
} finally {
this.setData({ saving: false })
}