75 门诊出诊医生诊室设置的完善
This commit is contained in:
@@ -47,7 +47,7 @@
|
|||||||
<el-table-column label="卫生机构" width="200" align="center" show-overflow-tooltip>
|
<el-table-column label="卫生机构" width="200" align="center" show-overflow-tooltip>
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<!-- 用==忽略类型匹配,string的"3"和number的3就能匹配上 -->
|
<!-- 用==忽略类型匹配,string的"3"和number的3就能匹配上 -->
|
||||||
{{ tenantOptions.find(item => item.id == scope.row.orgName)?.tenantName || '未知机构' }}
|
{{ tenantOptions.find(item => item.id == scope.row.orgName)?.tenantName || scope.row.orgName || '未知机构' }}
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column prop="roomName" label="诊室名称" width="160" align="center" show-overflow-tooltip />
|
<el-table-column prop="roomName" label="诊室名称" width="160" align="center" show-overflow-tooltip />
|
||||||
@@ -118,6 +118,7 @@
|
|||||||
width="500px"
|
width="500px"
|
||||||
append-to-body
|
append-to-body
|
||||||
:close-on-click-modal="false"
|
:close-on-click-modal="false"
|
||||||
|
destroy-on-close
|
||||||
>
|
>
|
||||||
<el-form
|
<el-form
|
||||||
ref="formRef"
|
ref="formRef"
|
||||||
@@ -150,7 +151,7 @@
|
|||||||
:disabled="dialogType === 'view'"
|
:disabled="dialogType === 'view'"
|
||||||
>
|
>
|
||||||
<el-option
|
<el-option
|
||||||
v-for="item in tenantOptions"
|
v-for="item in addEditTenantOptions"
|
||||||
:key="item.id"
|
:key="item.id"
|
||||||
:label="item.tenantName"
|
:label="item.tenantName"
|
||||||
:value="item.id"
|
:value="item.id"
|
||||||
@@ -250,7 +251,9 @@ const queryParams = reactive({
|
|||||||
// 科室选项
|
// 科室选项
|
||||||
const departmentOptions = ref([])
|
const departmentOptions = ref([])
|
||||||
// 租户选项
|
// 租户选项
|
||||||
const tenantOptions = ref([])
|
const tenantOptions = ref([]) // 用于查询表单
|
||||||
|
const rawTenantOptions = ref([]) // 存储从API获取的所有租户选项
|
||||||
|
const addEditTenantOptions = ref([]) // 用于新增/编辑弹窗的租户选项
|
||||||
// 弹窗相关
|
// 弹窗相关
|
||||||
const dialogVisible = ref(false)
|
const dialogVisible = ref(false)
|
||||||
const dialogType = ref('') // add/edit/view
|
const dialogType = ref('') // add/edit/view
|
||||||
@@ -271,37 +274,105 @@ const form = reactive({
|
|||||||
})
|
})
|
||||||
// 表单验证规则
|
// 表单验证规则
|
||||||
const rules = {
|
const rules = {
|
||||||
roomName: [
|
roomName: [
|
||||||
{ required: true, message: '诊室名称不能为空', trigger: 'blur' },
|
{ required: true, message: '诊室名称不能为空', trigger: 'blur' },
|
||||||
{ max: 20, message: '诊室名称长度不能超过20个字符', trigger: 'blur' },
|
{ max: 20, message: '诊室名称长度不能超过20个字符', trigger: 'blur' },
|
||||||
|
{
|
||||||
|
validator: (rule, value, callback) => {
|
||||||
|
// console.log('Validating roomName:', { value, formId: form.id });
|
||||||
|
if (!value) {
|
||||||
|
return callback()
|
||||||
|
}
|
||||||
|
// 检查诊室名称是否已存在(全局唯一性)
|
||||||
|
const isExist = clinicRoomList.value.some(item => {
|
||||||
|
const checkRoomName = String(item.roomName) === String(value); // Ensure type consistency
|
||||||
|
const checkId = item.id !== form.id;
|
||||||
|
|
||||||
|
// console.log('Comparing item for roomName:', {
|
||||||
|
// itemId: item.id,
|
||||||
|
// itemRoomName: item.roomName,
|
||||||
|
// checkRoomName,
|
||||||
|
// checkId,
|
||||||
|
// allConditions: checkRoomName && checkId
|
||||||
|
// });
|
||||||
|
|
||||||
|
return checkRoomName && checkId
|
||||||
|
})
|
||||||
|
if (isExist) {
|
||||||
|
callback(new Error('诊室名称已存在'))
|
||||||
|
} else {
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
trigger: 'blur'
|
||||||
|
} ], department: [
|
||||||
|
{ required: true, message: '', trigger: 'change' },
|
||||||
{
|
{
|
||||||
validator: (rule, value, callback) => {
|
validator: (rule, value, callback) => {
|
||||||
|
// console.log('Validating department:', { value, formOrgName: form.orgName, formId: form.id });
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return callback()
|
return callback()
|
||||||
}
|
}
|
||||||
if (!form.orgName) {
|
if (!form.orgName) {
|
||||||
|
// console.log('Department validation: form.orgName is missing, skipping uniqueness check.');
|
||||||
return callback()
|
return callback()
|
||||||
}
|
}
|
||||||
// 检查当前租户下是否已存在相同的诊室名称
|
// 检查当前卫生机构下科室名称是否已存在
|
||||||
const isExist = clinicRoomList.value.some(item => {
|
const isExist = clinicRoomList.value.some(item => {
|
||||||
return item.roomName === value &&
|
const checkDepartment = String(item.department) === String(value);
|
||||||
item.orgName === form.orgName &&
|
const checkOrgName = String(item.orgName) === String(form.orgName); // Ensure type consistency
|
||||||
item.id !== form.id
|
const checkId = item.id !== form.id; // Check against other items
|
||||||
|
|
||||||
|
// console.log('Comparing item:', {
|
||||||
|
// itemId: item.id,
|
||||||
|
// itemDepartment: item.department,
|
||||||
|
// itemOrgName: item.orgName,
|
||||||
|
// checkDepartment,
|
||||||
|
// checkOrgName,
|
||||||
|
// checkId,
|
||||||
|
// allConditions: checkDepartment && checkOrgName && checkId
|
||||||
|
// });
|
||||||
|
|
||||||
|
return checkDepartment && checkOrgName && checkId
|
||||||
})
|
})
|
||||||
if (isExist) {
|
if (isExist) {
|
||||||
callback(new Error('诊室名称已存在'))
|
// 不在此处直接报错,而是依赖orgName的校验来显示错误
|
||||||
|
callback()
|
||||||
} else {
|
} else {
|
||||||
callback()
|
callback()
|
||||||
}
|
}
|
||||||
|
// 触发对orgName字段的重新验证,以实现联动校验
|
||||||
|
proxy.formRef.validateField('orgName')
|
||||||
},
|
},
|
||||||
trigger: 'blur'
|
trigger: 'change'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
department: [
|
|
||||||
{ required: true, message: '科室名称不能为空', trigger: 'change' }
|
|
||||||
],
|
|
||||||
orgName: [
|
orgName: [
|
||||||
{ required: true, message: '卫生机构不能为空', trigger: 'change' }
|
{ required: true, message: '卫生机构不能为空', trigger: 'change' },
|
||||||
|
{
|
||||||
|
validator: (rule, value, callback) => {
|
||||||
|
// 如果卫生机构为空或科室名称为空,则不进行组合唯一性校验
|
||||||
|
if (!value || !form.department) {
|
||||||
|
return callback()
|
||||||
|
}
|
||||||
|
// 检查当前卫生机构下科室名称是否已存在
|
||||||
|
const isExist = clinicRoomList.value.some(item => {
|
||||||
|
const checkDepartment = String(item.department) === String(form.department);
|
||||||
|
const checkOrgName = String(item.orgName) === String(value); // 这里使用当前的value (orgName)
|
||||||
|
const checkId = item.id !== form.id;
|
||||||
|
|
||||||
|
return checkDepartment && checkOrgName && checkId
|
||||||
|
})
|
||||||
|
if (isExist) {
|
||||||
|
callback(new Error('当前卫生机构下已存在该科室名称的诊室'))
|
||||||
|
} else {
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
// 触发对department字段的重新验证,以实现联动校验
|
||||||
|
proxy.formRef.validateField('department')
|
||||||
|
},
|
||||||
|
trigger: 'change'
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,15 +382,22 @@ function getList() {
|
|||||||
getClinicRoomList(queryParams)
|
getClinicRoomList(queryParams)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.code === 200) {
|
if (response.code === 200) {
|
||||||
clinicRoomList.value = response.data?.records || response.data || []
|
// 确保数据格式正确
|
||||||
total.value = response.data?.total || clinicRoomList.value.length || 0
|
const records = response.data?.records || response.data || []
|
||||||
|
clinicRoomList.value = records
|
||||||
|
total.value = response.data?.total || records.length || 0
|
||||||
|
// console.log('获取诊室列表成功,记录数:', records.length)
|
||||||
} else {
|
} else {
|
||||||
ElMessage.error(response.msg || '获取诊室列表失败')
|
ElMessage.error(response.msg || '获取诊室列表失败')
|
||||||
|
clinicRoomList.value = []
|
||||||
|
total.value = 0
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('获取诊室列表失败:', error)
|
console.error('获取诊室列表失败:', error)
|
||||||
ElMessage.error('获取诊室列表失败')
|
ElMessage.error('获取诊室列表失败')
|
||||||
|
clinicRoomList.value = []
|
||||||
|
total.value = 0
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
@@ -341,44 +419,113 @@ function resetQuery() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 新增按钮操作
|
// 新增按钮操作
|
||||||
function handleAdd() {
|
async function handleAdd() {
|
||||||
|
// 首先清空表单
|
||||||
resetForm()
|
resetForm()
|
||||||
|
|
||||||
|
// 过滤租户选项,只保留 status 为 '0' 的卫生机构用于新增
|
||||||
|
addEditTenantOptions.value = rawTenantOptions.value.filter(item => item.status === '0');
|
||||||
|
|
||||||
|
// 设置对话框状态
|
||||||
dialogType.value = 'add'
|
dialogType.value = 'add'
|
||||||
dialogTitle.value = '新增诊室'
|
dialogTitle.value = '新增诊室'
|
||||||
dialogVisible.value = true
|
dialogVisible.value = true
|
||||||
|
|
||||||
// 为新增模式修改诊室名称验证规则:检查全局唯一性
|
// 然后获取当前用户信息并设置默认卫生机构
|
||||||
rules.roomName = [
|
try {
|
||||||
{ required: true, message: '诊室名称不能为空', trigger: 'blur' },
|
const userModule = await import('@/store/modules/user')
|
||||||
{ max: 20, message: '诊室名称长度不能超过20个字符', trigger: 'blur' },
|
const useUserStore = userModule.default
|
||||||
{
|
const userStore = useUserStore()
|
||||||
validator: (rule, value, callback) => {
|
|
||||||
if (!value) {
|
// 从用户store获取租户ID和租户名称
|
||||||
return callback()
|
const tenantId = userStore?.tenantId
|
||||||
}
|
const tenantName = userStore?.tenantName
|
||||||
// 新增时检查所有诊室名称是否已存在
|
|
||||||
const isExist = clinicRoomList.value.some(item => {
|
console.log('当前用户信息:', userStore)
|
||||||
return item.roomName === value
|
console.log('当前用户租户ID:', tenantId)
|
||||||
})
|
console.log('当前用户租户名称:', tenantName)
|
||||||
if (isExist) {
|
console.log('租户选项列表:', tenantOptions.value)
|
||||||
callback(new Error('诊室名称已存在'))
|
|
||||||
} else {
|
// 检查租户ID是否存在,如果不存在则尝试从租户名称匹配
|
||||||
callback()
|
let matchedTenantId = null
|
||||||
}
|
if (tenantId) {
|
||||||
},
|
// 优先使用租户ID进行匹配
|
||||||
trigger: 'blur'
|
matchedTenantId = tenantId
|
||||||
|
} else if (tenantName && tenantOptions.value && tenantOptions.value.length > 0) {
|
||||||
|
// 如果没有租户ID但有租户名称,则尝试通过名称匹配
|
||||||
|
const matchedTenant = tenantOptions.value.find(tenant =>
|
||||||
|
tenant.tenantName === tenantName
|
||||||
|
)
|
||||||
|
if (matchedTenant) {
|
||||||
|
matchedTenantId = matchedTenant.id
|
||||||
|
console.log('通过租户名称匹配到租户ID:', matchedTenantId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
|
||||||
|
// 检查匹配到的租户是否在租户选项列表中
|
||||||
|
if (matchedTenantId && tenantOptions.value && tenantOptions.value.length > 0) {
|
||||||
|
const userTenantExists = tenantOptions.value.some(tenant =>
|
||||||
|
tenant.id === matchedTenantId ||
|
||||||
|
Number(tenant.id) === Number(matchedTenantId)
|
||||||
|
)
|
||||||
|
|
||||||
|
console.log('用户租户是否存在:', userTenantExists)
|
||||||
|
|
||||||
|
if (userTenantExists) {
|
||||||
|
// 确保数据类型一致,将租户ID转换为数字类型
|
||||||
|
form.orgName = Number(matchedTenantId)
|
||||||
|
console.log('已设置默认卫生机构ID:', form.orgName)
|
||||||
|
|
||||||
|
// 查找并显示卫生机构名称
|
||||||
|
const tenantInfo = tenantOptions.value.find(tenant =>
|
||||||
|
tenant.id === matchedTenantId ||
|
||||||
|
Number(tenant.id) === Number(matchedTenantId)
|
||||||
|
)
|
||||||
|
if (tenantInfo) {
|
||||||
|
console.log('已设置默认卫生机构名称:', tenantInfo.tenantName)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log('当前用户租户不在租户选项列表中')
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log('用户租户ID和租户名称都为空,或租户选项列表为空')
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('无法获取当前用户信息:', error.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 确保 form.orgName 是数字类型以便与下拉框选项匹配
|
||||||
|
if (form.orgName && typeof form.orgName === 'string') {
|
||||||
|
const orgNameAsNumber = Number(form.orgName)
|
||||||
|
if (!isNaN(orgNameAsNumber)) {
|
||||||
|
form.orgName = orgNameAsNumber
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 编辑按钮操作
|
// 编辑按钮操作
|
||||||
function handleEdit(row) {
|
function handleEdit(row) {
|
||||||
resetForm()
|
resetForm()
|
||||||
const id = row.id
|
const id = row.id
|
||||||
|
// 编辑时不需要过滤租户状态,显示所有租户
|
||||||
|
addEditTenantOptions.value = rawTenantOptions.value;
|
||||||
getClinicRoomDetail(id)
|
getClinicRoomDetail(id)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.code === 200) {
|
if (response.code === 200) {
|
||||||
Object.assign(form, response.data || row)
|
const clinicRoomData = response.data || row
|
||||||
|
|
||||||
|
// 处理 orgName 数据类型,确保与下拉框选项值类型一致
|
||||||
|
if (clinicRoomData.orgName) {
|
||||||
|
const orgNameAsNumber = Number(clinicRoomData.orgName) // 转换为数字类型
|
||||||
|
// 确保转换成功且不是一个 NaN 值
|
||||||
|
if (!isNaN(orgNameAsNumber)) {
|
||||||
|
clinicRoomData.orgName = orgNameAsNumber
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.assign(form, clinicRoomData)
|
||||||
dialogType.value = 'edit'
|
dialogType.value = 'edit'
|
||||||
dialogTitle.value = '编辑诊室'
|
dialogTitle.value = '编辑诊室'
|
||||||
dialogVisible.value = true
|
dialogVisible.value = true
|
||||||
@@ -424,10 +571,23 @@ function handleEdit(row) {
|
|||||||
function handleView(row) {
|
function handleView(row) {
|
||||||
resetForm()
|
resetForm()
|
||||||
const id = row.id
|
const id = row.id
|
||||||
|
// 查看时不需要过滤租户状态,显示所有租户
|
||||||
|
addEditTenantOptions.value = rawTenantOptions.value;
|
||||||
getClinicRoomDetail(id)
|
getClinicRoomDetail(id)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.code === 200) {
|
if (response.code === 200) {
|
||||||
Object.assign(form, response.data || row)
|
const clinicRoomData = response.data || row
|
||||||
|
|
||||||
|
// 处理 orgName 数据类型,确保与下拉框选项值类型一致
|
||||||
|
if (clinicRoomData.orgName) {
|
||||||
|
const orgNameAsNumber = Number(clinicRoomData.orgName) // 转换为数字类型
|
||||||
|
// 确保转换成功且不是一个 NaN 值
|
||||||
|
if (!isNaN(orgNameAsNumber)) {
|
||||||
|
clinicRoomData.orgName = orgNameAsNumber
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.assign(form, clinicRoomData)
|
||||||
dialogType.value = 'view'
|
dialogType.value = 'view'
|
||||||
dialogTitle.value = '查看诊室详情'
|
dialogTitle.value = '查看诊室详情'
|
||||||
dialogVisible.value = true
|
dialogVisible.value = true
|
||||||
@@ -547,23 +707,33 @@ function getDepartmentOptions() {
|
|||||||
|
|
||||||
// 获取租户列表
|
// 获取租户列表
|
||||||
function getTenantOptions() {
|
function getTenantOptions() {
|
||||||
getTenantList()
|
return getTenantList()
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.code === 200) {
|
if (response.code === 200) {
|
||||||
// 处理不同的响应格式
|
// 处理不同的响应格式
|
||||||
|
let tenantList = [];
|
||||||
if (response.data?.records && Array.isArray(response.data.records)) {
|
if (response.data?.records && Array.isArray(response.data.records)) {
|
||||||
tenantOptions.value = response.data.records
|
tenantList = response.data.records;
|
||||||
} else if (Array.isArray(response.data)) {
|
} else if (Array.isArray(response.data)) {
|
||||||
tenantOptions.value = response.data
|
tenantList = response.data;
|
||||||
} else {
|
} else {
|
||||||
tenantOptions.value = []
|
tenantList = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rawTenantOptions.value = tenantList; // 存储所有租户
|
||||||
|
tenantOptions.value = tenantList; // 查询表单使用所有租户
|
||||||
} else {
|
} else {
|
||||||
console.warn('获取租户列表失败:', response.msg)
|
console.warn('获取租户列表失败:', response.msg)
|
||||||
|
rawTenantOptions.value = []
|
||||||
|
tenantOptions.value = []
|
||||||
}
|
}
|
||||||
|
return response; // 返回响应以支持链式调用
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('获取租户列表失败:', error)
|
console.error('获取租户列表失败:', error)
|
||||||
|
rawTenantOptions.value = []
|
||||||
|
tenantOptions.value = []
|
||||||
|
return Promise.reject(error); // 返回拒绝的Promise
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user