完善店务员工工时与订单记录

This commit is contained in:
2026-07-24 14:23:13 +08:00
parent 3a543f1d69
commit eff4e73427
20 changed files with 440 additions and 225 deletions
@@ -1,5 +1,4 @@
const employeesApi = require('../../api/employees')
const dateUtil = require('../../utils/date')
const { markPlanningRefresh } = require('../../utils/planning-refresh')
const PRESETS = [
@@ -20,12 +19,6 @@ const WEEKDAYS = [
{ value: 7, label: '周日' }
]
const EXCEPTION_TYPES = [
{ value: 'REST', label: '休假' },
{ value: 'EXTRA_WORK', label: '临时上班' },
{ value: 'CHANGE_SHIFT', label: '临时改班' }
]
function copyWorkDays(days) {
return (days || []).map(day => Number(day)).filter(day => day >= 1 && day <= 7)
}
@@ -49,22 +42,6 @@ function buildWeekdayOptions(workDays) {
}))
}
function buildExceptionTypeLabel(exceptionType) {
const option = EXCEPTION_TYPES.find(item => item.value === exceptionType) || EXCEPTION_TYPES[0]
return option.label
}
function buildExceptionSummary(item) {
const type = EXCEPTION_TYPES.find(option => option.value === item.exceptionType)
if (!item) {
return ''
}
if (item.exceptionType === 'REST') {
return `${item.workDate} ${type ? type.label : '休假'}`
}
return `${item.workDate} ${type ? type.label : '例外'} ${String(item.startTime || '').slice(0, 5)}-${String(item.endTime || '').slice(0, 5)}`
}
Page({
data: {
artistId: '',
@@ -72,10 +49,6 @@ Page({
presetOptions: buildPresetOptions('DOUBLE_REST'),
weekdays: WEEKDAYS,
weekdayOptions: buildWeekdayOptions([1, 2, 3, 4, 5]),
exceptionTypes: EXCEPTION_TYPES,
exceptionTypeIndex: 0,
exceptionTypeLabel: '休假',
exceptions: [],
loading: false,
saving: false,
form: {
@@ -84,13 +57,6 @@ Page({
startTime: '09:00',
endTime: '17:00',
remark: ''
},
exceptionForm: {
workDate: dateUtil.formatDate(new Date()),
exceptionType: 'REST',
startTime: '10:00',
endTime: '18:00',
remark: ''
}
},
@@ -119,13 +85,7 @@ Page({
this.setData({
form,
presetOptions: buildPresetOptions(form.presetType),
weekdayOptions: buildWeekdayOptions(form.workDays),
exceptions: (setting.exceptions || []).map(item => ({
...item,
startTime: item.startTime ? String(item.startTime).slice(0, 5) : '',
endTime: item.endTime ? String(item.endTime).slice(0, 5) : '',
summary: buildExceptionSummary(item)
}))
weekdayOptions: buildWeekdayOptions(form.workDays)
})
} catch (error) {
wx.showToast({ title: error.message || '排班规则加载失败', icon: 'none' })
@@ -184,33 +144,6 @@ Page({
this.setData({ [`form.${field}`]: event.detail.value })
},
onExceptionInput(event) {
const field = event.currentTarget.dataset.field
this.setData({ [`exceptionForm.${field}`]: event.detail.value })
},
onExceptionDateChange(event) {
this.setData({ 'exceptionForm.workDate': event.detail.value })
},
onExceptionStartChange(event) {
this.setData({ 'exceptionForm.startTime': event.detail.value })
},
onExceptionEndChange(event) {
this.setData({ 'exceptionForm.endTime': event.detail.value })
},
onExceptionTypeChange(event) {
const index = Number(event.detail.value)
const option = this.data.exceptionTypes[index] || this.data.exceptionTypes[0]
this.setData({
exceptionTypeIndex: index,
exceptionTypeLabel: buildExceptionTypeLabel(option.value),
'exceptionForm.exceptionType': option.value
})
},
async save() {
const form = this.data.form
const workDays = copyWorkDays(form.workDays)
@@ -243,36 +176,6 @@ Page({
}
},
async saveException() {
const form = this.data.exceptionForm
if (!form.workDate || !form.exceptionType) {
wx.showToast({ title: '请补全例外日期', icon: 'none' })
return
}
if (form.exceptionType !== 'REST' && (!form.startTime || !form.endTime || form.startTime >= form.endTime)) {
wx.showToast({ title: '请填写正确的例外时间', icon: 'none' })
return
}
this.setData({ saving: true })
try {
await employeesApi.saveScheduleException({
artistId: this.data.artistId,
workDate: form.workDate,
exceptionType: form.exceptionType,
startTime: form.exceptionType === 'REST' ? null : form.startTime,
endTime: form.exceptionType === 'REST' ? null : form.endTime,
remark: String(form.remark || '').trim()
})
markPlanningRefresh()
wx.showToast({ title: '例外已保存', icon: 'success' })
await this.loadRule()
} catch (error) {
wx.showToast({ title: error.message || '例外保存失败', icon: 'none' })
} finally {
this.setData({ saving: false })
}
},
back() {
wx.navigateBack()
}
@@ -28,40 +28,6 @@
</view>
</view>
<view class="section">
<view class="section-title">特殊日期</view>
<view class="card rule-card">
<view class="field">
<text class="field-label">日期</text>
<picker mode="date" value="{{exceptionForm.workDate}}" bindchange="onExceptionDateChange"><view class="field-value">{{exceptionForm.workDate}}</view></picker>
</view>
<view class="field">
<text class="field-label">类型</text>
<picker range="{{exceptionTypes}}" range-key="label" value="{{exceptionTypeIndex}}" bindchange="onExceptionTypeChange"><view class="field-value">{{exceptionTypeLabel}}</view></picker>
</view>
<view wx:if="{{exceptionForm.exceptionType !== 'REST'}}" class="field">
<text class="field-label">开始时间</text>
<picker mode="time" value="{{exceptionForm.startTime}}" bindchange="onExceptionStartChange"><view class="field-value">{{exceptionForm.startTime}}</view></picker>
</view>
<view wx:if="{{exceptionForm.exceptionType !== 'REST'}}" class="field">
<text class="field-label">结束时间</text>
<picker mode="time" value="{{exceptionForm.endTime}}" bindchange="onExceptionEndChange"><view class="field-value">{{exceptionForm.endTime}}</view></picker>
</view>
<view class="field">
<text class="field-label">备注</text>
<input value="{{exceptionForm.remark}}" data-field="remark" bindinput="onExceptionInput" placeholder="可选" />
</view>
<button class="secondary-btn exception-btn" loading="{{saving}}" bindtap="saveException">保存特殊日期</button>
</view>
<view wx:if="{{exceptions.length}}" class="exception-list">
<view wx:for="{{exceptions}}" wx:key="id" class="card exception-card">
<text>{{item.summary}}</text>
<text wx:if="{{item.remark}}" class="exception-remark">{{item.remark}}</text>
</view>
</view>
</view>
<view class="fixed-bottom">
<button class="primary-btn" loading="{{saving}}" bindtap="save">保存排班规则</button>
</view>
@@ -1,4 +1,4 @@
.rule-card {
.rule-card {
padding: 20rpx 24rpx;
}
@@ -60,35 +60,3 @@
font-size: 26rpx;
font-weight: 700;
}
.exception-btn {
margin-top: 22rpx;
}
.exception-list {
display: flex;
flex-direction: column;
gap: 14rpx;
margin-top: 18rpx;
}
.exception-card {
display: flex;
flex-direction: column;
gap: 8rpx;
padding: 20rpx 24rpx;
color: #4c4740;
font-size: 24rpx;
font-weight: 700;
transition: transform 180ms ease, box-shadow 180ms ease;
}
.exception-card:active {
transform: scale(0.99);
}
.exception-remark {
color: #8d857b;
font-size: 22rpx;
font-weight: 500;
}