206
检验项目设置-》套餐设置:卫生机构字段取值当前登录账户的科室名称了 210 检验项目设置-》套餐管理:卫生机构筛选字段下拉选项取值错误
This commit is contained in:
@@ -25,9 +25,20 @@
|
||||
</div>
|
||||
<div class="filter-item">
|
||||
<label>卫生机构:</label>
|
||||
<select>
|
||||
<option>演示医院</option>
|
||||
</select>
|
||||
<el-select
|
||||
v-model="selectedTenantId"
|
||||
placeholder="请选择机构"
|
||||
style="width: 150px;"
|
||||
clearable
|
||||
@change="handleSearch"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in tenantOptions"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="filter-item">
|
||||
<label>套餐名称:</label>
|
||||
@@ -182,9 +193,8 @@ import {useRouter} from 'vue-router';
|
||||
import {ElMessage} from 'element-plus';
|
||||
import {getLocationTree} from '@/views/charge/outpatientregistration/components/outpatientregistration';
|
||||
import {listInspectionPackage} from '@/api/system/inspectionPackage';
|
||||
import { getTenantPage } from '@/api/system/tenant';
|
||||
|
||||
console.log('PackageManagement 组件脚本开始执行')
|
||||
console.log('listInspectionPackage 函数:', listInspectionPackage)
|
||||
|
||||
// 创建路由实例
|
||||
const router = useRouter();
|
||||
@@ -199,9 +209,8 @@ const departments = ref([]);
|
||||
function getDepartmentList() {
|
||||
console.log('调用getLocationTree API...');
|
||||
getLocationTree().then((response) => {
|
||||
console.log('getLocationTree API完整返回:', response);
|
||||
console.log('getLocationTree API数据结构:', JSON.stringify(response.data, null, 2));
|
||||
|
||||
|
||||
|
||||
// 检查数据结构并转换为适合el-tree-select的格式
|
||||
if (Array.isArray(response.data)) {
|
||||
// 直接使用数组数据
|
||||
@@ -213,13 +222,12 @@ function getDepartmentList() {
|
||||
// 处理另一种分页格式数据
|
||||
departments.value = response.data.rows;
|
||||
} else {
|
||||
console.error('API返回数据格式不符合预期:', response.data);
|
||||
|
||||
departments.value = [];
|
||||
}
|
||||
|
||||
console.log('最终科室数据:', JSON.stringify(departments.value, null, 2));
|
||||
|
||||
|
||||
}).catch((error) => {
|
||||
console.error('获取科室数据失败:', error);
|
||||
departments.value = [];
|
||||
});
|
||||
}
|
||||
@@ -257,7 +265,7 @@ const searchParams = ref({
|
||||
// 从API加载数据
|
||||
async function loadData() {
|
||||
try {
|
||||
console.log('loadData 函数被调用')
|
||||
|
||||
loading.value = true
|
||||
|
||||
// 构建查询参数(匹配后端 InspectionPackage 实体字段)
|
||||
@@ -266,7 +274,7 @@ async function loadData() {
|
||||
pageSize: pageSize.value,
|
||||
packageCategory: '检验套餐' // InspectionPackage 使用 packageCategory 而不是 packageType
|
||||
}
|
||||
|
||||
|
||||
// 处理日期范围(后端可能不支持日期范围查询,先保留)
|
||||
// if (searchParams.value.startDate) {
|
||||
// params.startDate = searchParams.value.startDate
|
||||
@@ -274,7 +282,10 @@ async function loadData() {
|
||||
// if (searchParams.value.endDate) {
|
||||
// params.endDate = searchParams.value.endDate
|
||||
// }
|
||||
|
||||
if (selectedTenantId.value) {
|
||||
params.tenantId = selectedTenantId.value;
|
||||
}
|
||||
|
||||
if (searchParams.value.packageName) {
|
||||
params.packageName = searchParams.value.packageName
|
||||
}
|
||||
@@ -284,62 +295,53 @@ async function loadData() {
|
||||
if (searchParams.value.department) {
|
||||
params.department = searchParams.value.department
|
||||
}
|
||||
|
||||
console.log('准备调用 listInspectionPackage API,参数:', params)
|
||||
|
||||
|
||||
const response = await listInspectionPackage(params)
|
||||
console.log('listInspectionPackage API 完整返回:', response)
|
||||
console.log('response 类型:', typeof response)
|
||||
console.log('response.data 是否存在:', !!response.data)
|
||||
console.log('response.rows 是否存在:', !!response.rows)
|
||||
console.log('response.total 是否存在:', !!response.total)
|
||||
|
||||
|
||||
|
||||
if (response) {
|
||||
// 处理不同的响应格式(优先按若依风格:response.rows / response.total)
|
||||
let dataList = []
|
||||
let totalCount = 0
|
||||
|
||||
|
||||
// 优先检查 response.data(axios 包装的响应)
|
||||
if (response.data) {
|
||||
const data = response.data
|
||||
console.log('response.data 内容:', data)
|
||||
console.log('response.data.rows:', data.rows)
|
||||
console.log('response.data.total:', data.total)
|
||||
|
||||
|
||||
if (Array.isArray(data.rows)) {
|
||||
// TableDataInfo 格式:{ rows: [], total: 0 }
|
||||
dataList = data.rows
|
||||
totalCount = data.total || 0
|
||||
console.log('使用 response.data.rows 和 response.data.total, totalCount:', totalCount)
|
||||
|
||||
} else if (Array.isArray(data.records)) {
|
||||
// MyBatis Plus 分页格式
|
||||
dataList = data.records
|
||||
totalCount = data.total || 0
|
||||
console.log('使用 response.data.records 和 response.data.total, totalCount:', totalCount)
|
||||
|
||||
} else if (Array.isArray(data)) {
|
||||
// 直接是数组
|
||||
dataList = data
|
||||
totalCount = data.length
|
||||
console.log('使用 response.data 数组, totalCount:', totalCount)
|
||||
|
||||
}
|
||||
} else if (Array.isArray(response.rows)) {
|
||||
// 直接是 TableDataInfo 格式
|
||||
dataList = response.rows
|
||||
totalCount = response.total || 0
|
||||
console.log('使用 response.rows 和 response.total, totalCount:', totalCount)
|
||||
|
||||
} else if (Array.isArray(response)) {
|
||||
// 直接返回数组
|
||||
dataList = response
|
||||
totalCount = response.length
|
||||
console.log('使用 response 数组, totalCount:', totalCount)
|
||||
|
||||
}
|
||||
|
||||
|
||||
total.value = totalCount
|
||||
console.log('设置 total.value =', total.value)
|
||||
|
||||
|
||||
|
||||
// 转换数据格式以匹配前端显示(InspectionPackage 字段映射)
|
||||
console.log('原始数据列表:', dataList)
|
||||
console.log('数据列表长度:', dataList.length)
|
||||
|
||||
|
||||
tableData.value = (dataList || []).map(item => {
|
||||
const mappedItem = {
|
||||
id: item.basicInformationId || item.id, // 优先使用 basicInformationId
|
||||
@@ -362,22 +364,18 @@ async function loadData() {
|
||||
enabled: item.isDisabled === true ? '否' : '是',
|
||||
operator: item.createBy || ''
|
||||
}
|
||||
console.log('原始数据项:', item)
|
||||
console.log('映射后的数据项:', mappedItem)
|
||||
|
||||
return mappedItem
|
||||
})
|
||||
|
||||
console.log('最终 tableData.value:', tableData.value)
|
||||
console.log('tableData.value 长度:', tableData.value.length)
|
||||
console.log('最终 total.value:', total.value)
|
||||
console.log('计算的总页数 totalPages:', Math.ceil(total.value / pageSize.value))
|
||||
|
||||
|
||||
} else {
|
||||
tableData.value = []
|
||||
total.value = 0
|
||||
console.log('response 为空,重置数据')
|
||||
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载数据失败:', error)
|
||||
|
||||
ElMessage.error('加载数据失败: ' + (error.message || '未知错误'))
|
||||
tableData.value = []
|
||||
total.value = 0
|
||||
@@ -386,11 +384,70 @@ async function loadData() {
|
||||
}
|
||||
}
|
||||
|
||||
const selectedTenantId = ref(null); // 绑定下拉框的值
|
||||
const tenantOptions = ref([]); // 存储机构选项
|
||||
const loadingTenant = ref(false);
|
||||
|
||||
// 获取机构列表函数
|
||||
const fetchTenantList = async () => {
|
||||
if (loadingTenant.value) return;
|
||||
loadingTenant.value = true;
|
||||
|
||||
try {
|
||||
const response = await getTenantPage({ pageNum: 1, pageSize: 100 });
|
||||
|
||||
if (response.code !== 200) throw new Error(response.msg || '获取机构列表失败');
|
||||
|
||||
let tenantData = [];
|
||||
const data = response.data;
|
||||
if (Array.isArray(data)) {
|
||||
tenantData = data;
|
||||
} else if (data && typeof data === 'object') {
|
||||
tenantData = data.records || data.rows || data.list || [];
|
||||
}
|
||||
|
||||
// 过滤启用的机构
|
||||
const activeTenants = (Array.isArray(tenantData) ? tenantData : []).filter(item => item && item.status === "0");
|
||||
|
||||
// 生成下拉选项
|
||||
tenantOptions.value = activeTenants.map(item => ({
|
||||
value: item.id,
|
||||
label: item.tenantName || item.name || item.orgName || String(item.id)
|
||||
}));
|
||||
|
||||
// 默认选中 ID=1 或第一个
|
||||
if (activeTenants.length > 0) {
|
||||
const zhonglianHospital = activeTenants.find(item => item.id === 1);
|
||||
selectedTenantId.value = zhonglianHospital ? 1 : activeTenants[0].id;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取机构列表失败:', error);
|
||||
tenantOptions.value = [];
|
||||
} finally {
|
||||
loadingTenant.value = false;
|
||||
}
|
||||
};
|
||||
// 初始化数据
|
||||
onMounted(() => {
|
||||
console.log('onMounted 被调用,准备加载数据')
|
||||
loadData()
|
||||
})
|
||||
// 整合后的 onMounted 钩子
|
||||
onMounted(async () => {
|
||||
// 1. 加载科室数据
|
||||
getDepartmentList();
|
||||
|
||||
// 2. 加载机构列表 (包含默认选中逻辑)
|
||||
await fetchTenantList();
|
||||
|
||||
// 3. 等待 DOM 更新
|
||||
await nextTick();
|
||||
|
||||
// 4. 防御性检查
|
||||
if (tenantOptions.value.length > 0 && !selectedTenantId.value) {
|
||||
selectedTenantId.value = tenantOptions.value[0].value;
|
||||
}
|
||||
|
||||
// 5. 加载表格数据
|
||||
loadData();
|
||||
|
||||
});
|
||||
|
||||
// 过滤后的数据 - 现在直接从API获取,这里保留前端过滤作为补充
|
||||
const filteredData = computed(() => {
|
||||
@@ -434,7 +491,7 @@ function handleReset() {
|
||||
// 计算总页数
|
||||
const totalPages = computed(() => {
|
||||
const pages = Math.ceil(total.value / pageSize.value)
|
||||
console.log('[分页] 计算总页数: total=', total.value, 'pageSize=', pageSize.value, 'totalPages=', pages)
|
||||
|
||||
return pages > 0 ? pages : 1 // 至少返回1页
|
||||
})
|
||||
|
||||
@@ -448,28 +505,28 @@ function handlePrevPage() {
|
||||
|
||||
// 处理分页 - 下一页
|
||||
function handleNextPage() {
|
||||
console.log('[分页] 点击下一页, currentPage:', currentPage.value, 'totalPages:', totalPages.value)
|
||||
|
||||
if (currentPage.value < totalPages.value) {
|
||||
currentPage.value++
|
||||
console.log('[分页] 跳转到第', currentPage.value, '页')
|
||||
|
||||
loadData()
|
||||
} else {
|
||||
console.log('[分页] 已经是最后一页,无法继续')
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 处理分页 - 跳转到指定页
|
||||
function handlePageChange(page) {
|
||||
console.log('[分页] 点击页码, page:', page, 'currentPage:', currentPage.value, 'totalPages:', totalPages.value)
|
||||
|
||||
if (page === '...') {
|
||||
return // 省略号不可点击
|
||||
}
|
||||
if (page >= 1 && page <= totalPages.value && page !== currentPage.value) {
|
||||
currentPage.value = page
|
||||
console.log('[分页] 跳转到第', currentPage.value, '页')
|
||||
|
||||
loadData()
|
||||
} else {
|
||||
console.log('[分页] 无效的页码或已经是当前页')
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -478,15 +535,15 @@ const pageButtons = computed(() => {
|
||||
const buttons = []
|
||||
const total = totalPages.value
|
||||
const current = currentPage.value
|
||||
|
||||
console.log('[分页] 计算分页按钮, totalPages:', total, 'currentPage:', current)
|
||||
|
||||
|
||||
|
||||
|
||||
if (total <= 0) {
|
||||
// 如果没有数据,至少显示第1页
|
||||
buttons.push(1)
|
||||
return buttons
|
||||
}
|
||||
|
||||
|
||||
if (total <= 7) {
|
||||
// 如果总页数小于等于7,显示所有页码
|
||||
for (let i = 1; i <= total; i++) {
|
||||
@@ -519,8 +576,8 @@ const pageButtons = computed(() => {
|
||||
buttons.push(total)
|
||||
}
|
||||
}
|
||||
|
||||
console.log('[分页] 生成的按钮:', buttons)
|
||||
|
||||
|
||||
return buttons
|
||||
})
|
||||
|
||||
@@ -582,10 +639,10 @@ function handleDelete(item) {
|
||||
function handleExport() {
|
||||
// 获取当前筛选后的数据
|
||||
const dataToExport = filteredData.value;
|
||||
|
||||
|
||||
// 转换为CSV格式
|
||||
const csvContent = convertToCSV(dataToExport);
|
||||
|
||||
|
||||
// 创建下载链接
|
||||
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
@@ -601,13 +658,13 @@ function handleExport() {
|
||||
// 将数据转换为CSV格式的函数
|
||||
function convertToCSV(data) {
|
||||
if (data.length === 0) return '';
|
||||
|
||||
|
||||
// 获取表头
|
||||
const headers = Object.keys(data[0]);
|
||||
|
||||
|
||||
// 构建CSV内容
|
||||
let csv = headers.join(',') + '\n';
|
||||
|
||||
|
||||
// 添加数据行
|
||||
data.forEach(row => {
|
||||
const values = headers.map(header => {
|
||||
@@ -617,7 +674,7 @@ function convertToCSV(data) {
|
||||
});
|
||||
csv += values.join(',') + '\n';
|
||||
});
|
||||
|
||||
|
||||
return csv;
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user