恢复员工排班预设
This commit is contained in:
@@ -81,9 +81,12 @@ export interface ArtistScheduleRule {
|
||||
id?: IdType
|
||||
artistId: IdType
|
||||
shopId?: IdType
|
||||
workDays: string
|
||||
presetType?: string
|
||||
workDays: number[]
|
||||
startTime: string
|
||||
endTime: string
|
||||
status?: number
|
||||
remark?: string
|
||||
enabled?: number
|
||||
}
|
||||
|
||||
|
||||
@@ -4,19 +4,53 @@
|
||||
<template v-else>
|
||||
<section class="card form-card">
|
||||
<div class="field"><label>员工</label><div class="field-value">{{ employee?.name || employee?.nickname || route.params.id }}</div></div>
|
||||
<div class="field"><label class="required">工作日</label><input v-model.trim="ruleForm.workDays" placeholder="例如:1,2,3,4,5" /></div>
|
||||
<div class="field"><label class="required">开始时间</label><input v-model="ruleForm.startTime" type="time" /></div>
|
||||
<div class="field"><label class="required">结束时间</label><input v-model="ruleForm.endTime" type="time" /></div>
|
||||
<div class="field-block">
|
||||
<div class="field-title">排班预设</div>
|
||||
<div class="preset-grid">
|
||||
<button
|
||||
v-for="item in presets"
|
||||
:key="item.value"
|
||||
class="preset-chip"
|
||||
:class="{ active: ruleForm.presetType === item.value }"
|
||||
type="button"
|
||||
@click="selectPreset(item.value)"
|
||||
>
|
||||
{{ item.label }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field-block">
|
||||
<div class="field-title">工作日</div>
|
||||
<div class="weekday-grid">
|
||||
<button
|
||||
v-for="item in weekdays"
|
||||
:key="item.value"
|
||||
class="weekday-chip"
|
||||
:class="{ active: workDays.includes(item.value) }"
|
||||
type="button"
|
||||
@click="toggleWeekday(item.value)"
|
||||
>
|
||||
{{ item.label }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field"><label class="required">开始时间</label><input v-model="ruleForm.startTime" type="time" @change="markCustom" /></div>
|
||||
<div class="field"><label class="required">结束时间</label><input v-model="ruleForm.endTime" type="time" @change="markCustom" /></div>
|
||||
</section>
|
||||
<button class="primary-btn section" type="button" :disabled="saving" @click="saveRule">{{ saving ? '保存中...' : '保存排班规则' }}</button>
|
||||
|
||||
<PageSection title="新增例外">
|
||||
<section class="card form-card">
|
||||
<div class="field"><label class="required">日期</label><input v-model="exceptionForm.workDate" type="date" /></div>
|
||||
<div class="field"><label>开始时间</label><input v-model="exceptionForm.startTime" type="time" /></div>
|
||||
<div class="field"><label>结束时间</label><input v-model="exceptionForm.endTime" type="time" /></div>
|
||||
<div class="field"><label>状态</label><select v-model.number="exceptionForm.status"><option :value="1">可预约</option><option :value="0">休息</option></select></div>
|
||||
<div class="field"><label>原因</label><input v-model.trim="exceptionForm.reason" placeholder="选填" /></div>
|
||||
<div class="field">
|
||||
<label>类型</label>
|
||||
<select v-model="exceptionForm.exceptionType">
|
||||
<option v-for="item in exceptionTypes" :key="item.value" :value="item.value">{{ item.label }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div v-if="exceptionForm.exceptionType !== 'REST'" class="field"><label>开始时间</label><input v-model="exceptionForm.startTime" type="time" /></div>
|
||||
<div v-if="exceptionForm.exceptionType !== 'REST'" class="field"><label>结束时间</label><input v-model="exceptionForm.endTime" type="time" /></div>
|
||||
<div class="field"><label>原因</label><input v-model.trim="exceptionForm.remark" placeholder="选填" /></div>
|
||||
</section>
|
||||
<button class="secondary-btn section" type="button" :disabled="saving" @click="saveException">保存例外</button>
|
||||
</PageSection>
|
||||
@@ -28,9 +62,9 @@
|
||||
<div class="row-between">
|
||||
<div>
|
||||
<h2 class="list-card__title">{{ item.workDate }}</h2>
|
||||
<div class="list-card__subtitle">{{ item.status === 1 ? `${item.startTime || '-'} - ${item.endTime || '-'}` : '休息' }}</div>
|
||||
<div class="list-card__subtitle">{{ exceptionSummary(item) }}</div>
|
||||
</div>
|
||||
<span class="tag">{{ item.status === 1 ? '可预约' : '休息' }}</span>
|
||||
<span class="tag">{{ exceptionTypeLabel(item.exceptionType) }}</span>
|
||||
</div>
|
||||
</article>
|
||||
</section>
|
||||
@@ -40,7 +74,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import EmptyState from '@/components/EmptyState.vue'
|
||||
import LoadingState from '@/components/LoadingState.vue'
|
||||
@@ -51,41 +85,141 @@ import type { Artist, ArtistScheduleException } from '@/types/manager'
|
||||
import { formatDate } from '@/utils/date'
|
||||
import { useToastStore } from '@/stores/toast'
|
||||
|
||||
interface SchedulePreset {
|
||||
value: string
|
||||
label: string
|
||||
workDays: number[]
|
||||
startTime: string
|
||||
endTime: string
|
||||
}
|
||||
|
||||
const presets: SchedulePreset[] = [
|
||||
{ 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 exceptionTypes = [
|
||||
{ value: 'REST', label: '休息' },
|
||||
{ value: 'EXTRA_WORK', label: '临时上班' },
|
||||
{ value: 'CHANGE_SHIFT', label: '临时改班' }
|
||||
]
|
||||
|
||||
const route = useRoute()
|
||||
const toast = useToastStore()
|
||||
const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
const employee = ref<Artist | null>(null)
|
||||
const exceptions = ref<ArtistScheduleException[]>([])
|
||||
const ruleForm = reactive({ workDays: '1,2,3,4,5', startTime: '10:00', endTime: '22:00' })
|
||||
const exceptionForm = reactive({ workDate: formatDate(new Date()), startTime: '10:00', endTime: '18:00', status: 0, reason: '' })
|
||||
const ruleForm = reactive({ presetType: 'DOUBLE_REST', workDays: '1,2,3,4,5', startTime: '09:00', endTime: '17:00' })
|
||||
const exceptionForm = reactive({ workDate: formatDate(new Date()), exceptionType: 'REST', startTime: '10:00', endTime: '18:00', remark: '' })
|
||||
const workDays = computed(() => parseWorkDays(ruleForm.workDays))
|
||||
|
||||
const artistId = (): string => String(route.params.id)
|
||||
|
||||
const parseWorkDays = (value: string | number[] | null | undefined): number[] => {
|
||||
const rawDays = Array.isArray(value) ? value : String(value || '').split(',').map(item => Number(item.trim()))
|
||||
return [...new Set(rawDays.filter(item => item >= 1 && item <= 7))].sort((a, b) => a - b)
|
||||
}
|
||||
|
||||
const encodeWorkDays = (days: number[]): string => {
|
||||
return [...new Set(days)].sort((a, b) => a - b).join(',')
|
||||
}
|
||||
|
||||
const selectedPreset = (value: string): SchedulePreset => {
|
||||
return presets.find(item => item.value === value) ?? presets[0]!
|
||||
}
|
||||
|
||||
const normalizePresetType = (value: string | null | undefined): string => {
|
||||
return presets.some(item => item.value === value) ? String(value) : 'CUSTOM'
|
||||
}
|
||||
|
||||
const loadData = async (): Promise<void> => {
|
||||
loading.value = true
|
||||
try {
|
||||
employee.value = await managerEmployeesApi.detail(artistId())
|
||||
const setting = await managerEmployeesApi.scheduleRule({ artistId: artistId() })
|
||||
if (setting.rule) {
|
||||
ruleForm.workDays = setting.rule.workDays || ruleForm.workDays
|
||||
ruleForm.presetType = normalizePresetType(setting.rule.presetType)
|
||||
const loadedDays = parseWorkDays(setting.rule.workDays)
|
||||
ruleForm.workDays = encodeWorkDays(loadedDays.length > 0 ? loadedDays : selectedPreset(ruleForm.presetType).workDays)
|
||||
ruleForm.startTime = String(setting.rule.startTime || ruleForm.startTime).slice(0, 5)
|
||||
ruleForm.endTime = String(setting.rule.endTime || ruleForm.endTime).slice(0, 5)
|
||||
}
|
||||
exceptions.value = setting.exceptions || []
|
||||
exceptions.value = (setting.exceptions || []).map(normalizeException)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const normalizeException = (item: ArtistScheduleException): ArtistScheduleException => ({
|
||||
...item,
|
||||
exceptionType: item.exceptionType || (item.status === 0 ? 'REST' : 'CHANGE_SHIFT'),
|
||||
startTime: item.startTime ? String(item.startTime).slice(0, 5) : '',
|
||||
endTime: item.endTime ? String(item.endTime).slice(0, 5) : '',
|
||||
remark: item.remark || item.reason || ''
|
||||
})
|
||||
|
||||
const selectPreset = (value: string): void => {
|
||||
const preset = selectedPreset(value)
|
||||
ruleForm.presetType = preset.value
|
||||
ruleForm.workDays = encodeWorkDays(preset.workDays)
|
||||
ruleForm.startTime = preset.startTime
|
||||
ruleForm.endTime = preset.endTime
|
||||
}
|
||||
|
||||
const toggleWeekday = (day: number): void => {
|
||||
const days = workDays.value.includes(day)
|
||||
? workDays.value.filter(item => item !== day)
|
||||
: [...workDays.value, day]
|
||||
ruleForm.presetType = 'CUSTOM'
|
||||
ruleForm.workDays = encodeWorkDays(days)
|
||||
}
|
||||
|
||||
const markCustom = (): void => {
|
||||
ruleForm.presetType = 'CUSTOM'
|
||||
}
|
||||
|
||||
const exceptionTypeLabel = (value: string | null | undefined): string => {
|
||||
return exceptionTypes.find(item => item.value === value)?.label || '特殊日期'
|
||||
}
|
||||
|
||||
const exceptionSummary = (item: ArtistScheduleException): string => {
|
||||
if (item.exceptionType === 'REST') {
|
||||
return '休息'
|
||||
}
|
||||
const timeText = `${item.startTime || '-'} - ${item.endTime || '-'}`
|
||||
return item.remark ? `${timeText}|${item.remark}` : timeText
|
||||
}
|
||||
|
||||
const saveRule = async (): Promise<void> => {
|
||||
if (!ruleForm.workDays || !ruleForm.startTime || !ruleForm.endTime) {
|
||||
const days = workDays.value
|
||||
if (days.length === 0 || !ruleForm.startTime || !ruleForm.endTime) {
|
||||
toast.error('请填写排班规则')
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
await managerEmployeesApi.saveScheduleRule({ artistId: artistId(), workDays: ruleForm.workDays, startTime: ruleForm.startTime, endTime: ruleForm.endTime, enabled: 1 })
|
||||
await managerEmployeesApi.saveScheduleRule({
|
||||
artistId: artistId(),
|
||||
presetType: ruleForm.presetType,
|
||||
workDays: days,
|
||||
startTime: ruleForm.startTime,
|
||||
endTime: ruleForm.endTime,
|
||||
status: 1
|
||||
})
|
||||
toast.success('排班规则已保存')
|
||||
await loadData()
|
||||
} finally {
|
||||
@@ -98,9 +232,21 @@ const saveException = async (): Promise<void> => {
|
||||
toast.error('请补全例外日期')
|
||||
return
|
||||
}
|
||||
if (exceptionForm.exceptionType !== 'REST' && (!exceptionForm.startTime || !exceptionForm.endTime)) {
|
||||
toast.error('请填写开始和结束时间')
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
await managerEmployeesApi.saveScheduleException({ artistId: artistId(), ...exceptionForm })
|
||||
await managerEmployeesApi.saveScheduleException({
|
||||
artistId: artistId(),
|
||||
workDate: exceptionForm.workDate,
|
||||
exceptionType: exceptionForm.exceptionType,
|
||||
startTime: exceptionForm.exceptionType === 'REST' ? undefined : exceptionForm.startTime,
|
||||
endTime: exceptionForm.exceptionType === 'REST' ? undefined : exceptionForm.endTime,
|
||||
status: exceptionForm.exceptionType === 'REST' ? 0 : 1,
|
||||
remark: exceptionForm.remark.trim()
|
||||
})
|
||||
toast.success('例外已保存')
|
||||
await loadData()
|
||||
} finally {
|
||||
@@ -112,3 +258,52 @@ onMounted(() => {
|
||||
void loadData()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.field-block {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
padding: 12px 14px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.field-title {
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.preset-grid,
|
||||
.weekday-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.weekday-grid {
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.preset-chip,
|
||||
.weekday-chip {
|
||||
min-height: 38px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
background: var(--card-bg);
|
||||
color: var(--ink);
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.preset-chip.active,
|
||||
.weekday-chip.active {
|
||||
border-color: var(--accent);
|
||||
background: #e5f2eb;
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.preset-grid {
|
||||
grid-template-columns: repeat(5, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user