完善小程序排班与预约快捷操作
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
const employeesApi = require('../../api/employees')
|
const employeesApi = require('../../api/employees')
|
||||||
|
const planningApi = require('../../api/planning')
|
||||||
|
const dateUtil = require('../../utils/date')
|
||||||
const { chooseImageFilePath, uploadObjectFile } = require('../../utils/upload')
|
const { chooseImageFilePath, uploadObjectFile } = require('../../utils/upload')
|
||||||
|
|
||||||
const EMPLOYEE_COLORS = ['#7AA9C2', '#8EB99B', '#BDA7D8', '#D7B17D', '#D98D8D']
|
const EMPLOYEE_COLORS = ['#7AA9C2', '#8EB99B', '#BDA7D8', '#D7B17D', '#D98D8D']
|
||||||
@@ -34,8 +36,14 @@ Page({
|
|||||||
|
|
||||||
async loadEmployees() {
|
async loadEmployees() {
|
||||||
try {
|
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 list = data.list || data || []
|
||||||
|
const appointments = calendar.appointments || []
|
||||||
|
const artists = calendar.artists || []
|
||||||
this.setData({
|
this.setData({
|
||||||
loadError: '',
|
loadError: '',
|
||||||
employees: list.map((item, index) => ({
|
employees: list.map((item, index) => ({
|
||||||
@@ -46,7 +54,18 @@ Page({
|
|||||||
color: EMPLOYEE_COLORS[index % EMPLOYEE_COLORS.length],
|
color: EMPLOYEE_COLORS[index % EMPLOYEE_COLORS.length],
|
||||||
monthOrders: item.monthOrders || item.orderCount || 0,
|
monthOrders: item.monthOrders || item.orderCount || 0,
|
||||||
monthAmount: item.monthAmount || item.turnover || 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) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -18,8 +18,8 @@
|
|||||||
<view wx:else class="avatar" style="background: {{item.color}};">{{item.shortName}}</view>
|
<view wx:else class="avatar" style="background: {{item.color}};">{{item.shortName}}</view>
|
||||||
<view>
|
<view>
|
||||||
<text class="employee-name">{{item.name}}</text>
|
<text class="employee-name">{{item.name}}</text>
|
||||||
<text class="employee-schedule">{{item.scheduleSummary}}</text>
|
<text class="employee-schedule">{{item.todaySchedule}} · {{item.todayAvailable ? '可预约' : '休息中'}}</text>
|
||||||
<text class="employee-meta">本月 {{item.monthOrders}} 单 · ¥{{item.monthAmount}}</text>
|
<text class="employee-meta">今日 {{item.todayOrders}} 单 · 本月 {{item.monthOrders}} 单</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="color-pill" style="background: {{item.color}};"></view>
|
<view class="color-pill" style="background: {{item.color}};"></view>
|
||||||
|
|||||||
@@ -418,5 +418,48 @@ Page({
|
|||||||
wx.navigateTo({
|
wx.navigateTo({
|
||||||
url: `/pages/appointment-detail/index?id=${event.currentTarget.dataset.id}`
|
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-title">{{block.customerName}}</text>
|
||||||
<text class="block-meta">{{block.timeText}} · {{block.productTitle}}</text>
|
<text class="block-meta">{{block.timeText}} · {{block.productTitle}}</text>
|
||||||
<text class="block-status">{{block.statusText}}</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>
|
||||||
<view wx:if="{{item.blocks.length === 0}}" class="lane-empty">全天可约</view>
|
<view wx:if="{{item.blocks.length === 0}}" class="lane-empty">全天可约</view>
|
||||||
</view>
|
</view>
|
||||||
|
|||||||
@@ -320,6 +320,19 @@
|
|||||||
line-height: 1.25;
|
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 {
|
.lane-empty {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 76rpx;
|
top: 76rpx;
|
||||||
|
|||||||
@@ -237,7 +237,8 @@ Page({
|
|||||||
wx.showToast({ title: '排班规则已保存', icon: 'success' })
|
wx.showToast({ title: '排班规则已保存', icon: 'success' })
|
||||||
await this.loadRule()
|
await this.loadRule()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
wx.showToast({ title: error.message || '保存失败', icon: 'none' })
|
const message = error.message || '保存失败'
|
||||||
|
wx.showModal({ title: '排班保存失败', content: message, showCancel: false, confirmText: '知道了' })
|
||||||
} finally {
|
} finally {
|
||||||
this.setData({ saving: false })
|
this.setData({ saving: false })
|
||||||
}
|
}
|
||||||
@@ -267,7 +268,8 @@ Page({
|
|||||||
wx.showToast({ title: '例外已保存', icon: 'success' })
|
wx.showToast({ title: '例外已保存', icon: 'success' })
|
||||||
await this.loadRule()
|
await this.loadRule()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
wx.showToast({ title: error.message || '例外保存失败', icon: 'none' })
|
const message = error.message || '例外保存失败'
|
||||||
|
wx.showModal({ title: '特殊日期保存失败', content: message, showCancel: false, confirmText: '知道了' })
|
||||||
} finally {
|
} finally {
|
||||||
this.setData({ saving: false })
|
this.setData({ saving: false })
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user