完善店务员工工时与订单记录
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user