260 预约管理-》医生排班管理:系统未正确限制同一天同一时段(上午/下午)的重复排班,导致同一医生在同一时间段可被多次排班,产生数据冲突和资源调度混乱

This commit is contained in:
HuangXinQuan
2026-03-24 11:51:17 +08:00
parent 4060be4de7
commit 4e58601b2c
2 changed files with 128 additions and 11 deletions

View File

@@ -166,7 +166,19 @@
<span class="weekday-text">{{ dateGroup.weekday }}</span>
</div>
<el-table :data="dateGroup.items" border style="width: 100%" class="schedule-table">
<el-table-column prop="timeSlot" label="时段" width="100"></el-table-column>
<el-table-column label="时段" width="100">
<template #default="scope">
<el-select
v-model="scope.row.timeSlot"
placeholder="请选择"
:disabled="!isEditMode"
@change="(val) => handleTimeSlotChange(val, scope.row)"
>
<el-option label="上午" value="上午"></el-option>
<el-option label="下午" value="下午"></el-option>
</el-select>
</template>
</el-table-column>
<el-table-column prop="doctorName" :label="filterParams.appointmentType === '专家' ? '专家' : '医生'" width="150">
<template #default="scope">
<el-select
@@ -207,14 +219,15 @@
</el-table-column>
<el-table-column prop="startTime" label="开始时间" width="120">
<template #default="scope">
<el-time-picker
v-model="scope.row.startTime"
type="time"
format="HH:mm"
value-format="HH:mm"
<el-time-picker
v-model="scope.row.startTime"
type="time"
format="HH:mm"
value-format="HH:mm"
placeholder="选择开始时间"
:disabled="!isEditMode"
class="time-picker"
@change="(val) => handleStartTimeChange(val, scope.row)"
/>
</template>
</el-table-column>
@@ -929,17 +942,24 @@ const handleAppointmentSettingCancel = () => {
// 路由和导航
const router = useRouter()
// 根据开始时间自动判断时段(上午/下午)
const getTimeSlot = (startTime) => {
if (!startTime) return '上午';
const hour = parseInt(startTime.split(':')[0]);
return hour < 12 ? '上午' : '下午';
};
// 生成一周排班数据
const generateWeekSchedule = (startDate, workTimeConfig) => {
const days = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
const timeSlots = [
{
label: '上午',
label: getTimeSlot(workTimeConfig?.morningStart || '08:00'),
startTime: workTimeConfig?.morningStart || '08:00',
endTime: workTimeConfig?.morningEnd || '12:00'
},
{
label: '下午',
label: getTimeSlot(workTimeConfig?.afternoonStart || '14:30'),
startTime: workTimeConfig?.afternoonStart || '14:30',
endTime: workTimeConfig?.afternoonEnd || '18:00'
}
@@ -1380,16 +1400,17 @@ const isLastDraftRowInSlot = (row) => {
const handleAddSchedule = (row) => {
// 创建新的排班记录,基于当前行的日期和时段
const startTime = row.startTime || '08:00';
const newSchedule = {
id: `new-${Date.now()}-${Math.random()}`,
date: row.date,
weekday: row.weekday,
timeSlot: row.timeSlot,
startTime: row.startTime || '08:00',
timeSlot: getTimeSlot(startTime),
startTime: startTime,
endTime: row.endTime || '12:00',
doctorName: '',
room: '',
maxNumber: '',
maxNumber: row.maxNumber ?? '',
appointmentItem: '',
registrationFee: 0,
clinicItem: '',
@@ -1412,6 +1433,29 @@ const handleAddSchedule = (row) => {
}
}
// 时段变化时,更新默认的开始结束时间
const handleTimeSlotChange = (val, row) => {
const config = workTimeConfig.value;
if (val === '上午') {
if (!row.startTime || row.startTime >= '12:00') {
row.startTime = config?.morningStart || '08:00';
row.endTime = config?.morningEnd || '12:00';
}
} else if (val === '下午') {
if (!row.startTime || row.startTime < '12:00') {
row.startTime = config?.afternoonStart || '14:30';
row.endTime = config?.afternoonEnd || '18:00';
}
}
};
// 开始时间变化时,自动更新时段
const handleStartTimeChange = (val, row) => {
if (val) {
row.timeSlot = getTimeSlot(val);
}
};
// 删除排班
const handleDeleteSchedule = (row) => {
if (isLastDraftRowInSlot(row)) {
@@ -1585,6 +1629,19 @@ const handleSave = async () => {
return !!resolveDoctorName(item) || !!item.doctorId;
});
// 验证结束时间必须大于开始时间
const invalidTimeSchedules = filledSchedules.filter(item => {
if (item.startTime && item.endTime) {
return item.startTime >= item.endTime;
}
return false;
});
if (invalidTimeSchedules.length > 0) {
ElMessage.warning('结束时间必须大于开始时间,请检查排班记录');
return;
}
const incompleteSchedules = filledSchedules.filter(item => {
const isDoctorValid = !!resolveDoctorName(item) || !!item.doctorId;
const isRoomValid = item.room && item.room.trim() !== '';