实现员工规则排班设置
This commit is contained in:
@@ -43,5 +43,28 @@ module.exports = {
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
},
|
||||
|
||||
scheduleRule(params) {
|
||||
return request({
|
||||
url: '/manager/employees/schedule-rule',
|
||||
params
|
||||
})
|
||||
},
|
||||
|
||||
saveScheduleRule(data) {
|
||||
return request({
|
||||
url: '/manager/employees/schedule-rule',
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
},
|
||||
|
||||
saveScheduleException(data) {
|
||||
return request({
|
||||
url: '/manager/employees/schedule-exceptions',
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,286 @@
|
||||
const employeesApi = require('../../api/employees')
|
||||
const dateUtil = require('../../utils/date')
|
||||
|
||||
const PRESETS = [
|
||||
{ value: 'DOUBLE_REST', label: '双休', workDays: [1, 2, 3, 4, 5], startTime: '09:00', endTime: '17:00' },
|
||||
{ value: 'SINGLE_REST', label: '单休', workDays: [1, 2, 3, 4, 5, 6], startTime: '10:00', endTime: '22:00' },
|
||||
{ value: 'NINE_TO_FIVE', label: '朝九晚五', workDays: [1, 2, 3, 4, 5], startTime: '09:00', endTime: '17:00' },
|
||||
{ value: 'LATE_SHIFT', label: '晚班', workDays: [1, 2, 3, 4, 5, 6], startTime: '10:00', endTime: '22:00' },
|
||||
{ value: 'CUSTOM', label: '自定义', workDays: [1, 2, 3, 4, 5], startTime: '10:00', endTime: '22:00' }
|
||||
]
|
||||
|
||||
const WEEKDAYS = [
|
||||
{ value: 1, label: '周一' },
|
||||
{ value: 2, label: '周二' },
|
||||
{ value: 3, label: '周三' },
|
||||
{ value: 4, label: '周四' },
|
||||
{ value: 5, label: '周五' },
|
||||
{ value: 6, label: '周六' },
|
||||
{ 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)
|
||||
}
|
||||
|
||||
function buildPreset(value) {
|
||||
return PRESETS.find(item => item.value === value) || PRESETS[0]
|
||||
}
|
||||
|
||||
function buildPresetOptions(presetType) {
|
||||
return PRESETS.map(item => ({
|
||||
...item,
|
||||
active: item.value === presetType
|
||||
}))
|
||||
}
|
||||
|
||||
function buildWeekdayOptions(workDays) {
|
||||
const selected = copyWorkDays(workDays)
|
||||
return WEEKDAYS.map(item => ({
|
||||
...item,
|
||||
active: selected.includes(item.value)
|
||||
}))
|
||||
}
|
||||
|
||||
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: {
|
||||
form: { workDate: dateUtil.formatDate(new Date()), startTime: '10:00', endTime: '22:00', capacity: 1 }
|
||||
artistId: '',
|
||||
presets: PRESETS,
|
||||
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: {
|
||||
presetType: 'DOUBLE_REST',
|
||||
workDays: [1, 2, 3, 4, 5],
|
||||
startTime: '09:00',
|
||||
endTime: '17:00',
|
||||
slotMinutes: 60,
|
||||
capacity: 1,
|
||||
remark: ''
|
||||
},
|
||||
exceptionForm: {
|
||||
workDate: dateUtil.formatDate(new Date()),
|
||||
exceptionType: 'REST',
|
||||
startTime: '10:00',
|
||||
endTime: '18:00',
|
||||
slotMinutes: 60,
|
||||
capacity: 1,
|
||||
remark: ''
|
||||
}
|
||||
},
|
||||
onInput(event) { this.setData({ [`form.${event.currentTarget.dataset.field}`]: event.detail.value }) },
|
||||
onDateChange(event) { this.setData({ 'form.workDate': event.detail.value }) },
|
||||
onStartChange(event) { this.setData({ 'form.startTime': event.detail.value }) },
|
||||
onEndChange(event) { this.setData({ 'form.endTime': event.detail.value }) },
|
||||
save() { wx.showToast({ title: '已保存' }) },
|
||||
back() { wx.navigateBack() }
|
||||
|
||||
onLoad(options) {
|
||||
this.setData({ artistId: options.id || '' })
|
||||
this.loadRule()
|
||||
},
|
||||
|
||||
async loadRule() {
|
||||
if (!this.data.artistId) {
|
||||
wx.showToast({ title: '缺少美甲师ID', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.setData({ loading: true })
|
||||
try {
|
||||
const setting = await employeesApi.scheduleRule({ artistId: this.data.artistId })
|
||||
const rule = setting.rule || {}
|
||||
const preset = buildPreset(rule.presetType)
|
||||
const form = {
|
||||
presetType: rule.presetType || preset.value,
|
||||
workDays: copyWorkDays(rule.workDays || preset.workDays),
|
||||
startTime: String(rule.startTime || preset.startTime).slice(0, 5),
|
||||
endTime: String(rule.endTime || preset.endTime).slice(0, 5),
|
||||
slotMinutes: rule.slotMinutes || 60,
|
||||
capacity: rule.capacity || 1,
|
||||
remark: rule.remark || ''
|
||||
}
|
||||
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)
|
||||
}))
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '排班规则加载失败', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ loading: false })
|
||||
}
|
||||
},
|
||||
|
||||
selectPreset(event) {
|
||||
const preset = buildPreset(event.currentTarget.dataset.value)
|
||||
const form = {
|
||||
...this.data.form,
|
||||
presetType: preset.value,
|
||||
workDays: copyWorkDays(preset.workDays),
|
||||
startTime: preset.startTime,
|
||||
endTime: preset.endTime
|
||||
}
|
||||
this.setData({
|
||||
form,
|
||||
presetOptions: buildPresetOptions(form.presetType),
|
||||
weekdayOptions: buildWeekdayOptions(form.workDays)
|
||||
})
|
||||
},
|
||||
|
||||
toggleWeekday(event) {
|
||||
const day = Number(event.currentTarget.dataset.value)
|
||||
const workDays = copyWorkDays(this.data.form.workDays)
|
||||
const exists = workDays.includes(day)
|
||||
const nextDays = exists ? workDays.filter(item => item !== day) : [...workDays, day].sort()
|
||||
this.setData({
|
||||
'form.presetType': 'CUSTOM',
|
||||
'form.workDays': nextDays,
|
||||
presetOptions: buildPresetOptions('CUSTOM'),
|
||||
weekdayOptions: buildWeekdayOptions(nextDays)
|
||||
})
|
||||
},
|
||||
|
||||
onStartChange(event) {
|
||||
this.setData({
|
||||
'form.startTime': event.detail.value,
|
||||
'form.presetType': 'CUSTOM',
|
||||
presetOptions: buildPresetOptions('CUSTOM')
|
||||
})
|
||||
},
|
||||
|
||||
onEndChange(event) {
|
||||
this.setData({
|
||||
'form.endTime': event.detail.value,
|
||||
'form.presetType': 'CUSTOM',
|
||||
presetOptions: buildPresetOptions('CUSTOM')
|
||||
})
|
||||
},
|
||||
|
||||
onInput(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
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)
|
||||
if (!workDays.length) {
|
||||
wx.showToast({ title: '请选择工作日', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!form.startTime || !form.endTime || form.startTime >= form.endTime) {
|
||||
wx.showToast({ title: '请填写正确的排班时间', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.setData({ saving: true })
|
||||
try {
|
||||
await employeesApi.saveScheduleRule({
|
||||
artistId: this.data.artistId,
|
||||
presetType: form.presetType,
|
||||
workDays,
|
||||
startTime: form.startTime,
|
||||
endTime: form.endTime,
|
||||
slotMinutes: Number(form.slotMinutes) || 60,
|
||||
capacity: Number(form.capacity) || 1,
|
||||
status: 1,
|
||||
remark: String(form.remark || '').trim()
|
||||
})
|
||||
wx.showToast({ title: '排班规则已保存', icon: 'success' })
|
||||
await this.loadRule()
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '保存失败', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ saving: false })
|
||||
}
|
||||
},
|
||||
|
||||
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,
|
||||
slotMinutes: Number(form.slotMinutes) || 60,
|
||||
capacity: Number(form.capacity) || 1,
|
||||
remark: String(form.remark || '').trim()
|
||||
})
|
||||
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()
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,34 +1,84 @@
|
||||
<view class="page no-tab">
|
||||
<view class="card form-card">
|
||||
<view class="field">
|
||||
<view class="field-label-wrap">
|
||||
<text class="field-label">日期</text>
|
||||
<text class="field-hint">点击可编辑</text>
|
||||
<view class="section">
|
||||
<view class="section-title">常规排班</view>
|
||||
<view class="card rule-card">
|
||||
<view class="preset-grid">
|
||||
<view wx:for="{{presetOptions}}" wx:key="value" class="preset-chip {{item.active ? 'active' : ''}}" data-value="{{item.value}}" bindtap="selectPreset">{{item.label}}</view>
|
||||
</view>
|
||||
<picker mode="date" value="{{form.workDate}}" bindchange="onDateChange"><view class="field-value">{{form.workDate}}</view></picker>
|
||||
</view>
|
||||
<view class="field">
|
||||
<view class="field-label-wrap">
|
||||
|
||||
<view class="field-block">
|
||||
<view class="field-title">工作日</view>
|
||||
<view class="weekday-grid">
|
||||
<view wx:for="{{weekdayOptions}}" wx:key="value" class="weekday-chip {{item.active ? 'active' : ''}}" data-value="{{item.value}}" bindtap="toggleWeekday">{{item.label}}</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="field">
|
||||
<text class="field-label">开始时间</text>
|
||||
<text class="field-hint">点击可编辑</text>
|
||||
<picker mode="time" value="{{form.startTime}}" bindchange="onStartChange"><view class="field-value">{{form.startTime}}</view></picker>
|
||||
</view>
|
||||
<picker mode="time" value="{{form.startTime}}" bindchange="onStartChange"><view class="field-value">{{form.startTime}}</view></picker>
|
||||
</view>
|
||||
<view class="field">
|
||||
<view class="field-label-wrap">
|
||||
<view class="field">
|
||||
<text class="field-label">结束时间</text>
|
||||
<text class="field-hint">点击可编辑</text>
|
||||
<picker mode="time" value="{{form.endTime}}" bindchange="onEndChange"><view class="field-value">{{form.endTime}}</view></picker>
|
||||
</view>
|
||||
<picker mode="time" value="{{form.endTime}}" bindchange="onEndChange"><view class="field-value">{{form.endTime}}</view></picker>
|
||||
</view>
|
||||
<view class="field capacity-field">
|
||||
<view class="field-label-wrap">
|
||||
<view class="field">
|
||||
<text class="field-label">预约间隔</text>
|
||||
<input type="number" value="{{form.slotMinutes}}" data-field="slotMinutes" bindinput="onInput" />
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label">容量</text>
|
||||
<text class="field-desc">同一时间段最多可同时接待的预约数</text>
|
||||
<text class="field-hint">点击可编辑</text>
|
||||
<input type="number" value="{{form.capacity}}" data-field="capacity" bindinput="onInput" />
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label">备注</text>
|
||||
<input value="{{form.remark}}" data-field="remark" bindinput="onInput" placeholder="可选" />
|
||||
</view>
|
||||
<input type="number" value="{{form.capacity}}" data-field="capacity" bindinput="onInput" />
|
||||
</view>
|
||||
</view>
|
||||
<view class="fixed-bottom"><button class="primary-btn" bindtap="save">保存排班</button></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 wx:if="{{exceptionForm.exceptionType !== 'REST'}}" class="field">
|
||||
<text class="field-label">预约间隔</text>
|
||||
<input type="number" value="{{exceptionForm.slotMinutes}}" data-field="slotMinutes" bindinput="onExceptionInput" />
|
||||
</view>
|
||||
<view wx:if="{{exceptionForm.exceptionType !== 'REST'}}" class="field">
|
||||
<text class="field-label">容量</text>
|
||||
<input type="number" value="{{exceptionForm.capacity}}" data-field="capacity" bindinput="onExceptionInput" />
|
||||
</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>
|
||||
</view>
|
||||
|
||||
@@ -1,34 +1,77 @@
|
||||
.field-label-wrap {
|
||||
.rule-card {
|
||||
padding: 20rpx 24rpx;
|
||||
}
|
||||
|
||||
.preset-grid,
|
||||
.weekday-grid {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-wrap: wrap;
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
.preset-chip,
|
||||
.weekday-chip {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 260rpx;
|
||||
flex-shrink: 0;
|
||||
gap: 6rpx;
|
||||
min-width: 128rpx;
|
||||
height: 60rpx;
|
||||
padding: 0 22rpx;
|
||||
border: 1rpx solid #e3ddd4;
|
||||
border-radius: 999rpx;
|
||||
background: #fbf7f0;
|
||||
color: #5f5951;
|
||||
font-size: 24rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.field-label-wrap .field-label {
|
||||
width: auto;
|
||||
.preset-chip.active,
|
||||
.weekday-chip.active {
|
||||
border-color: #6f8f83;
|
||||
background: #e5eee9;
|
||||
color: #55786d;
|
||||
}
|
||||
|
||||
.field-hint {
|
||||
color: #a39b91;
|
||||
font-size: 20rpx;
|
||||
font-weight: 500;
|
||||
.field-block {
|
||||
padding: 26rpx 0 12rpx;
|
||||
border-bottom: 1rpx solid #eee8df;
|
||||
}
|
||||
|
||||
.field-desc {
|
||||
max-width: 240rpx;
|
||||
color: #7f786f;
|
||||
font-size: 20rpx;
|
||||
line-height: 1.25;
|
||||
}
|
||||
|
||||
.capacity-field {
|
||||
min-height: 136rpx;
|
||||
.field-title {
|
||||
margin-bottom: 16rpx;
|
||||
color: #625c55;
|
||||
font-size: 26rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.field input,
|
||||
.field-value {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
.exception-remark {
|
||||
color: #8d857b;
|
||||
font-size: 22rpx;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user