80 门诊医生站检查申请单开单界面,排班的回显问题

This commit is contained in:
HuangXinQuan
2026-02-27 14:25:17 +08:00
parent 87c7981ad9
commit fcd2d03424
6 changed files with 323 additions and 120 deletions

View File

@@ -378,7 +378,7 @@ import {ElDialog, ElForm, ElFormItem, ElInput, ElMessage, ElMessageBox, ElOption
import {DocumentRemove, EditPen, View, Delete} from '@element-plus/icons-vue'
import {listDept, searchDept} from '@/api/appoinmentmanage/dept'
import {getLocationTree, getPractitionerMetadata, getHealthcareMetadata} from '@/views/charge/outpatientregistration/components/outpatientregistration'
import {addDoctorSchedule, addDoctorScheduleWithDate, updateDoctorSchedule, deleteDoctorSchedule, getRegisterOrganizations, getDoctorScheduleListByDeptId} from './api'
import {addDoctorSchedule, addDoctorScheduleWithDate, updateDoctorSchedule, deleteDoctorSchedule, getRegisterOrganizations, getDoctorScheduleListByDeptId, getDoctorScheduleListByDeptIdAndDateRange} from './api'
import {getClinicRoomList} from '@/api/appoinmentmanage/clinicRoom'
import {getInitOption, getRegistrationItems, getClinicItems} from '@/views/basicservices/registrationfee/components/registrationfee'
import { deptTreeSelect } from '@/api/system/user'
@@ -1004,6 +1004,12 @@ const generateWeekSchedule = (startDate, workTimeConfig) => {
return schedule
}
// 格式化日期为 yyyy-MM-dd 字符串
const formatDateStr = (date) => {
const d = new Date(date)
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
}
// 重新加载排班数据
const reloadScheduleData = async () => {
const row = currentDept.value
@@ -1012,23 +1018,31 @@ const reloadScheduleData = async () => {
// 使用组件级别的 workTimeConfig
const weekSchedule = generateWeekSchedule(filterParams.value.startDate, workTimeConfig.value)
// 获取该科室的现有排班数据
// 计算当前周的起止日期,用于联表查询
const startDateStr = formatDateStr(filterParams.value.startDate)
const endDate = new Date(filterParams.value.startDate)
endDate.setDate(endDate.getDate() + 6)
const endDateStr = formatDateStr(endDate)
// 获取该科室在指定日期范围内的排班数据(联表查询 adm_schedule_pool 获取具体日期)
try {
const response = await getDoctorScheduleListByDeptId(row.id)
const response = await getDoctorScheduleListByDeptIdAndDateRange(row.id, startDateStr, endDateStr)
if (response.code === 200) {
const actualData = response.data
const deptSchedules = Array.isArray(actualData) ? actualData : (actualData && actualData.code === 200 ? actualData.data || [] : [])
// 创建一个映射表,提高查找效率
// 以 "具体日期-时段" 为 key 创建映射表,替代原来的 "星期-时段"
const scheduleMap = {}
deptSchedules.forEach(schedule => {
const key = `${schedule.weekday}-${schedule.timePeriod}`
// scheduleDate 来自 adm_schedule_pool.schedule_date是具体的出诊日期
const key = `${schedule.scheduleDate}-${schedule.timePeriod}`
scheduleMap[key] = schedule
})
// 将现有排班数据合并到周计划中
// 将现有排班数据合并到周计划中(以具体日期匹配)
weekSchedule.forEach(slot => {
const key = `${slot.weekday}-${slot.timeSlot}`
// slot.date 是前端生成的具体日期yyyy-MM-dd与后端的 scheduleDate 一致
const key = `${slot.date}-${slot.timeSlot}`
const existingSchedule = scheduleMap[key]
if (existingSchedule) {
@@ -1036,21 +1050,20 @@ const reloadScheduleData = async () => {
slot.doctorName = existingSchedule.doctor
slot.doctorId = String(existingSchedule.doctorId) // 确保为字符串
// --- 新增容错逻辑 ---
// --- 容错逻辑校验医生ID是否在当前医生列表中 ---
const allAvailableDoctors = [...doctorOptions.value['普通'], ...doctorOptions.value['专家']];
const matchedDoctorById = allAvailableDoctors.find(doc => doc.id === slot.doctorId);
if (!matchedDoctorById) { // 如果排班记录中的doctorId在当前医生列表中找不到
if (!matchedDoctorById) {
// 尝试根据医生姓名进行匹配
const matchedDoctorByName = allAvailableDoctors.find(doc => doc.label === slot.doctorName);
if (matchedDoctorByName) {
slot.doctorId = matchedDoctorByName.id; // 使用当前医生列表中的正确ID
slot.doctorId = matchedDoctorByName.id;
console.warn(`【调试警告】排班记录doctorId ${existingSchedule.doctorId} (姓名: ${existingSchedule.doctor}) 与当前医生列表不匹配。已根据姓名修正为ID: ${matchedDoctorByName.id}`);
} else {
// 如果医生ID和姓名都匹配不上则清空医生信息避免显示错误数据
slot.doctorId = null;
slot.doctorName = '';
console.error(`【调试错误】排班记录doctorId ${existingSchedule.doctorId} 和医生姓名 "${existingSchedule.doctor}" 都未在当前医生列表中找到。该医生信息可能已过时或错误。`);
console.error(`【调试错误】排班记录doctorId ${existingSchedule.doctorId} 和医生姓名 "${existingSchedule.doctor}" 都未在当前医生列表中找到。`);
}
}
// --- 结束容错逻辑 ---
@@ -1066,7 +1079,7 @@ const reloadScheduleData = async () => {
slot.online = existingSchedule.isOnline
slot.stopClinic = existingSchedule.isStopped
slot.stopReason = existingSchedule.stopReason
slot.backendId = existingSchedule.id // 关键修复:保存后端ID
slot.backendId = existingSchedule.id // 保存后端ID
}
})
}

View File

@@ -904,11 +904,12 @@ const getTaskIcon = (category) => {
// 获取日程数据实际应用中应该从API获取
const fetchScheduleList = async () => {
try {
console.log('Fetching schedule list...')
const response = await getTodayMySchedule()
console.log('今日日程原始响应:', response)
if (response.code === 200) {
// 将API返回的数据转换为前端所需的格式
const scheduleData = response.data.map((schedule, index) => {
const scheduleData = (response.data || []).map((schedule, index) => {
console.log(`排班记录[${index}]:`, schedule)
// 根据排班类型设置标签类型
let tagType = 'info'
if (schedule.shift) {
@@ -920,8 +921,15 @@ const fetchScheduleList = async () => {
// 确定标题
const title = schedule.doctorName ? `${schedule.doctorName}医生排班` : '医生排班'
// 确定位置
const location = schedule.clinicRoom || schedule.deptId || '未知科室'
// 按照用户最新要求:直接展示 adm_doctor_schedule 的 clinic 字段或诊室名clinicRoom优先于科室名称。
// 增加对下划线命名的兼容性检查,防止后端映射异常。
const clinic = schedule.clinic
const roomName = schedule.clinicRoom || schedule.clinic_room
const department = schedule.deptName || schedule.dept_name
// 优先显示排班里设置的 clinic其次是号源池的诊室名称如果没有则显示科室名称最后显示默认值
const location = clinic || roomName || (department ? `${department}` : '院内')
console.log(`排班记录[${index}] 位置信息:`, { clinic, roomName, department, location })
return {
id: schedule.id || index,